Skip to content

Commit db0479d

Browse files
committed
Cleanup hsluv tests
Fix crash due to a missing file. Simplify tests by only dealing with coords and not creating PlainColorObjects. Delete util.mjs and move the readTestData function to the hsluv.js test module.
1 parent 168b96b commit db0479d

File tree

3 files changed

+27
-36
lines changed

3 files changed

+27
-36
lines changed

Diff for: test/hsluv/hpluv.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { to, sRGB, HPLuv } from "../../src/index-fn.js";
2-
import { check } from "../util.mjs";
3-
import { readTestData, normalizeCoords } from "./util.mjs";
2+
import * as check from "../../node_modules/htest.dev/src/check.js";
3+
import { readTestData } from "./hsluv.js";
44

55
let json = readTestData();
66
let srgbToHpluv = [];
77
let hpluvToSrgb = [];
88

99
Object.entries(json).forEach(([rgbHex, value]) => {
10-
let coords = normalizeCoords(value.hpluv);
10+
let coords = value.hpluv;
1111
let rgb = value.rgb;
12-
srgbToHpluv.push({ args: {space: sRGB, coords: rgb, alpha: 1}, expect: coords });
13-
hpluvToSrgb.push({ args: {space: HPLuv, coords: coords, alpha: 1}, expect: rgb });
12+
srgbToHpluv.push({ args: {space: sRGB, coords: rgb}, expect: coords });
13+
hpluvToSrgb.push({ args: {space: HPLuv, coords: coords}, expect: rgb });
1414
});
1515

1616
const tests = {
1717
name: "HPLuv Conversion Tests",
1818
description: "These tests compare sRGB values against the HSLuv reference implementation snapshot data.",
19-
run (color, spaceId = this.data.toSpace) {
20-
return to(color, spaceId).coords;
19+
run (color, space = this.data.toSpace) {
20+
return space.from(color.space, color.coords);
2121
},
2222
check: check.deep(function (actual, expect) {
2323
if (expect === null || Number.isNaN(expect)) {

Diff for: test/hsluv/hsluv.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
1-
import { to, sRGB, HSLuv } from "../../src/index-fn.js";
2-
import { check } from "../util.mjs";
3-
import { readTestData, normalizeCoords } from "./util.mjs";
1+
import { sRGB, HSLuv } from "../../src/index-fn.js";
2+
import * as check from "../../node_modules/htest.dev/src/check.js";
3+
import fs from "node:fs";
4+
import path from "node:path";
5+
import { fileURLToPath } from "node:url";
6+
7+
export function readTestData () {
8+
try {
9+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
10+
const filePath = path.resolve(__dirname, "snapshot-rev4.json");
11+
return JSON.parse(fs.readFileSync(filePath, "utf8"));
12+
}
13+
catch (err) {
14+
console.error(err);
15+
}
16+
}
417

518
let json = readTestData();
619
let srgbToHsluv = [];
720
let hsluvToSrgb = [];
821

922
Object.entries(json).forEach(([rgbHex, value]) => {
10-
let coords = normalizeCoords(value.hsluv);
23+
let coords = value.hsluv;
1124
let rgb = value.rgb;
12-
srgbToHsluv.push({ args: {space: sRGB, coords: rgb, alpha: 1}, expect: coords });
13-
hsluvToSrgb.push({ args: {space: HSLuv, coords: coords, alpha: 1}, expect: rgb });
25+
srgbToHsluv.push({ args: {space: sRGB, coords: rgb}, expect: coords });
26+
hsluvToSrgb.push({ args: {space: HSLuv, coords: coords}, expect: rgb });
1427
});
1528

1629
const tests = {
1730
name: "HSLuv Conversion Tests",
1831
description: "These tests compare sRGB values against the HSLuv reference implementation snapshot data.",
1932
run (color, space = this.data.toSpace) {
20-
return space.from(color);
33+
return space.from(color.space, color.coords);
2134
},
2235
check: check.deep(function (actual, expect) {
2336
if (expect === null || Number.isNaN(expect)) {

Diff for: test/hsluv/util.mjs

-22
This file was deleted.

0 commit comments

Comments
 (0)