|
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 | +} |
4 | 17 |
|
5 | 18 | let json = readTestData();
|
6 | 19 | let srgbToHsluv = [];
|
7 | 20 | let hsluvToSrgb = [];
|
8 | 21 |
|
9 | 22 | Object.entries(json).forEach(([rgbHex, value]) => {
|
10 |
| - let coords = normalizeCoords(value.hsluv); |
| 23 | + let coords = value.hsluv; |
11 | 24 | 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 }); |
14 | 27 | });
|
15 | 28 |
|
16 | 29 | const tests = {
|
17 | 30 | name: "HSLuv Conversion Tests",
|
18 | 31 | description: "These tests compare sRGB values against the HSLuv reference implementation snapshot data.",
|
19 | 32 | run (color, space = this.data.toSpace) {
|
20 |
| - return space.from(color); |
| 33 | + return space.from(color.space, color.coords); |
21 | 34 | },
|
22 | 35 | check: check.deep(function (actual, expect) {
|
23 | 36 | if (expect === null || Number.isNaN(expect)) {
|
|
0 commit comments