|
| 1 | +import assert from "node:assert/strict" |
| 2 | +import test from "node:test" |
| 3 | + |
| 4 | +import type { WebviewThemeFixture } from "@roo-code/types" |
| 5 | + |
| 6 | +import { themeFixtureDefinitions } from "./definitions" |
| 7 | +import { createSerializedFixtures, findDriftedFixtures, serializeThemeFixture } from "./fixtures" |
| 8 | + |
| 9 | +const validVariables = Object.fromEntries( |
| 10 | + Array.from({ length: 100 }, (_, index) => [`--vscode-test-${index}`, "#000000"]), |
| 11 | +) |
| 12 | +const validFixture: WebviewThemeFixture = { |
| 13 | + themeId: "Default Dark Modern", |
| 14 | + bodyClass: "vscode-dark", |
| 15 | + variables: { |
| 16 | + ...validVariables, |
| 17 | + "--vscode-foreground": "#cccccc", |
| 18 | + "--vscode-editor-background": "#1f1f1f", |
| 19 | + "--vscode-button-foreground": "#ffffff", |
| 20 | + }, |
| 21 | +} |
| 22 | + |
| 23 | +test("serializeThemeFixture sorts variables and emits stable metadata", () => { |
| 24 | + const fixture: WebviewThemeFixture = { |
| 25 | + themeId: "Default Dark Modern", |
| 26 | + bodyClass: "vscode-dark", |
| 27 | + variables: { |
| 28 | + "--vscode-z-last": "rgb(2, 2, 2)", |
| 29 | + "--vscode-a-first": "#010101", |
| 30 | + "--vscode-font-family": "platform-dependent", |
| 31 | + }, |
| 32 | + } |
| 33 | + |
| 34 | + assert.equal( |
| 35 | + serializeThemeFixture(themeFixtureDefinitions[0], fixture, "1.100.0"), |
| 36 | + [ |
| 37 | + "/* Generated from Default Dark Modern by VS Code 1.100.0. Do not edit manually. */", |
| 38 | + ".vscode-dark {", |
| 39 | + "\tcolor-scheme: dark;", |
| 40 | + "\t--vscode-a-first: #010101;", |
| 41 | + "\t--vscode-z-last: rgb(2, 2, 2);", |
| 42 | + "}", |
| 43 | + "", |
| 44 | + ].join("\n"), |
| 45 | + ) |
| 46 | +}) |
| 47 | + |
| 48 | +test("findDriftedFixtures reports missing and changed files in sorted order", () => { |
| 49 | + const expected = new Map([ |
| 50 | + ["vscode-theme-light.css", "light"], |
| 51 | + ["vscode-theme-dark.css", "dark"], |
| 52 | + ]) |
| 53 | + const actual = new Map<string, string | undefined>([["vscode-theme-light.css", "stale"]]) |
| 54 | + |
| 55 | + assert.deepEqual(findDriftedFixtures(expected, actual), ["vscode-theme-dark.css", "vscode-theme-light.css"]) |
| 56 | +}) |
| 57 | + |
| 58 | +test("createSerializedFixtures rejects incomplete captures", () => { |
| 59 | + const fixture: WebviewThemeFixture = { |
| 60 | + ...validFixture, |
| 61 | + variables: { |
| 62 | + ...validVariables, |
| 63 | + "--vscode-foreground": "#cccccc", |
| 64 | + "--vscode-editor-background": "#1f1f1f", |
| 65 | + }, |
| 66 | + } |
| 67 | + |
| 68 | + assert.throws( |
| 69 | + () => createSerializedFixtures(new Map([["dark", fixture]]), "1.100.0", [themeFixtureDefinitions[0]]), |
| 70 | + /--vscode-button-foreground/, |
| 71 | + ) |
| 72 | +}) |
| 73 | + |
| 74 | +test("createSerializedFixtures rejects an empty capture", () => { |
| 75 | + assert.throws( |
| 76 | + () => |
| 77 | + createSerializedFixtures(new Map([["dark", { ...validFixture, variables: {} }]]), "1.100.0", [ |
| 78 | + themeFixtureDefinitions[0], |
| 79 | + ]), |
| 80 | + /fewer than 100/, |
| 81 | + ) |
| 82 | +}) |
| 83 | + |
| 84 | +test("createSerializedFixtures rejects the wrong theme identity", () => { |
| 85 | + assert.throws( |
| 86 | + () => |
| 87 | + createSerializedFixtures( |
| 88 | + new Map([["dark", { ...validFixture, themeId: "Default Light Modern" }]]), |
| 89 | + "1.100.0", |
| 90 | + [themeFixtureDefinitions[0]], |
| 91 | + ), |
| 92 | + /Expected Default Dark Modern/, |
| 93 | + ) |
| 94 | +}) |
0 commit comments