From 33be4afeb7e90c29efb44845d5056e944080e980 Mon Sep 17 00:00:00 2001 From: Chris Scott <> Date: Mon, 5 Oct 2026 17:15:21 +0000 Subject: [PATCH] test(frontend): read theme source files with ?raw imports instead of node builtins --- frontend/src/lib/theme/colorTheme.test.ts | 9 +-------- frontend/src/lib/theme/syntaxHighlight.test.ts | 13 ++----------- frontend/vitest.config.ts | 3 +++ 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/frontend/src/lib/theme/colorTheme.test.ts b/frontend/src/lib/theme/colorTheme.test.ts index 8ce71892..b60db705 100644 --- a/frontend/src/lib/theme/colorTheme.test.ts +++ b/frontend/src/lib/theme/colorTheme.test.ts @@ -1,6 +1,4 @@ -import { readFileSync } from 'node:fs' -import path from 'node:path' -import { fileURLToPath } from 'node:url' +import indexHtml from '../../../index.html?raw' import { beforeEach, describe, expect, it } from 'vitest' import { APPEARANCE_STORAGE_KEY, @@ -9,11 +7,6 @@ import { resolveColorThemeTokens, } from './colorTheme' -const indexHtml = readFileSync( - path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../index.html'), - 'utf8', -) - function themeColorMeta(): string | null { return document.querySelector('meta[name="theme-color"]')?.getAttribute('content') ?? null } diff --git a/frontend/src/lib/theme/syntaxHighlight.test.ts b/frontend/src/lib/theme/syntaxHighlight.test.ts index 3d4212a1..42ea06ea 100644 --- a/frontend/src/lib/theme/syntaxHighlight.test.ts +++ b/frontend/src/lib/theme/syntaxHighlight.test.ts @@ -1,17 +1,8 @@ -import { readFileSync } from 'node:fs' -import path from 'node:path' -import { fileURLToPath } from 'node:url' +import indexCss from '../../index.css?raw' +import textPart from '../../components/message/TextPart.tsx?raw' import { describe, expect, it } from 'vitest' import { resolveColorThemeTokens } from './colorTheme' -const themeDir = path.dirname(fileURLToPath(import.meta.url)) - -const indexCss = readFileSync(path.resolve(themeDir, '../../index.css'), 'utf8') -const textPart = readFileSync( - path.resolve(themeDir, '../../components/message/TextPart.tsx'), - 'utf8', -) - function countOccurrences(source: string, needle: string): number { return source.split(needle).length - 1 } diff --git a/frontend/vitest.config.ts b/frontend/vitest.config.ts index eaadbc54..8954af6f 100644 --- a/frontend/vitest.config.ts +++ b/frontend/vitest.config.ts @@ -16,6 +16,9 @@ export default defineConfig({ NODE_ENV: "test", }, setupFiles: ["./src/test/setup.ts"], + css: { + include: [/[?&]raw(?:&|$)/], + }, include: ["src/**/*.test.{ts,tsx}"], }, resolve: {