From 76c99c8deca8f0344d870a4ecb2ca03c8174bd90 Mon Sep 17 00:00:00 2001 From: Kirill Zhumarin Date: Sun, 11 Oct 2026 20:22:59 +0000 Subject: [PATCH] Use vitest --- package.json | 2 +- scripts/run-tests.mjs | 71 ------------------------------- src/tests/mfl.test.ts | 4 +- src/tests/patch-history.test.ts | 2 +- src/tests/persisted-store.test.ts | 2 +- src/tests/vkp-highlight.test.ts | 2 +- vitest.config.ts | 8 +++- 7 files changed, 13 insertions(+), 78 deletions(-) delete mode 100644 scripts/run-tests.mjs diff --git a/package.json b/package.json index 87ffd10..bfa814a 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "build": "tsc && vite build", "gh-pages-build": "tsc && vite build", "serve": "vite preview", - "test": "node scripts/run-tests.mjs", + "test": "vitest run --project unit", "test:e2e": "vitest run --project e2e --no-file-parallelism" }, "license": "MIT", diff --git a/scripts/run-tests.mjs b/scripts/run-tests.mjs deleted file mode 100644 index 32727dc..0000000 --- a/scripts/run-tests.mjs +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env node -// Runs the TypeScript tests with Node's built-in test runner. -// Compiles the needed sources into .test-build/ first, since the project -// has no test bundler installed. -import { execSync } from "node:child_process"; -import { rmSync, cpSync, mkdirSync, existsSync, symlinkSync } from "node:fs"; -import path from "node:path"; - -const root = path.resolve(import.meta.dirname, ".."); -const buildDir = path.join(root, ".test-build"); - -const testSuites = [ - { - sources: [ - "src/utils/store/makePersistedSignal.ts", - "src/utils/store/makePersistedStore.ts", - "src/tests/persisted-store.test.ts", - ], - run: [".test-build/tests/persisted-store.test.js"], - }, - { - sources: [ - "src/pages/Flasher/history.ts", - "src/tests/patch-history.test.ts", - ], - run: [".test-build/tests/patch-history.test.js"], - }, - { - sources: [ - "src/pages/Flasher/vkpHighlight.ts", - "src/tests/vkp-highlight.test.ts", - ], - run: [".test-build/tests/vkp-highlight.test.js"], - }, - { - sources: [ - "src/utils/mfl.ts", - "src/tests/mfl.test.ts", - ], - run: [".test-build/tests/mfl.test.js"], - }, -]; - -rmSync(buildDir, { recursive: true, force: true }); -mkdirSync(buildDir); - -for (const suite of testSuites) { - execSync(`pnpm exec tsc --ignoreConfig ${suite.sources.join(" ")} --outDir ${buildDir} ` + - "--module esnext --target esnext --moduleResolution bundler --skipLibCheck --esModuleInterop --strict --types node", - { stdio: "inherit", cwd: root }); -} - -// node_modules for the compiled tests (symlink: fast). -const nodeModulesLink = path.join(buildDir, "node_modules"); -if (!existsSync(nodeModulesLink)) - symlinkSync(path.join(root, "node_modules"), nodeModulesLink, "dir"); - -let failed = false; -for (const testPath of testSuites.flatMap((s) => s.run)) { - try { - execSync(`node --test --test-reporter spec ${testPath}`, { stdio: "inherit", cwd: root }); - } catch (e) { - failed = true; - } -} - -if (failed) - process.exit(1); - -if (!existsSync(path.join(buildDir, "keep"))) - rmSync(buildDir, { recursive: true, force: true }); diff --git a/src/tests/mfl.test.ts b/src/tests/mfl.test.ts index cc795dc..8728dc4 100644 --- a/src/tests/mfl.test.ts +++ b/src/tests/mfl.test.ts @@ -1,4 +1,4 @@ -import { test } from 'node:test'; +import { test } from 'vitest'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; @@ -103,7 +103,7 @@ test('mfl: phone model detection', () => { assert.deepEqual(detectMflModels(flash).map((model) => model.code), ['C11F', 'X65G', 'L71F']); }); -test('mfl: Martech files', { skip: !files.length && 'MFL_TEST_FILES has no .mfl files' }, () => { +test.skipIf(!files.length)('mfl: Martech files', () => { for (const file of files) { const data = fs.readFileSync(file); const { code, flash } = decodeMfl(data); diff --git a/src/tests/patch-history.test.ts b/src/tests/patch-history.test.ts index 40e19d1..7ba84df 100644 --- a/src/tests/patch-history.test.ts +++ b/src/tests/patch-history.test.ts @@ -1,4 +1,4 @@ -import { test } from 'node:test'; +import { test } from 'vitest'; import assert from 'node:assert/strict'; import { PatchHistoryEntry, addPatchHistoryEntry, clearPatchHistory, deletePatchHistoryEntry, diff --git a/src/tests/persisted-store.test.ts b/src/tests/persisted-store.test.ts index fbbfa0f..9dd4cda 100644 --- a/src/tests/persisted-store.test.ts +++ b/src/tests/persisted-store.test.ts @@ -1,5 +1,5 @@ import assert from 'node:assert/strict'; -import { test } from 'node:test'; +import { test } from 'vitest'; import { createSignal } from 'solid-js'; import { createStore } from 'solid-js/store'; import { makePersistedSignal } from '../utils/store/makePersistedSignal.js'; diff --git a/src/tests/vkp-highlight.test.ts b/src/tests/vkp-highlight.test.ts index 895d676..73b1608 100644 --- a/src/tests/vkp-highlight.test.ts +++ b/src/tests/vkp-highlight.test.ts @@ -1,4 +1,4 @@ -import { test } from 'node:test'; +import { test } from 'vitest'; import assert from 'node:assert/strict'; import { tokenizeVkp } from '../pages/Flasher/vkpHighlight.js'; diff --git a/vitest.config.ts b/vitest.config.ts index 23709bb..43eb12a 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -5,10 +5,16 @@ import { defineConfig } from 'vitest/config'; // SIE_FFS_TEST_FULLFLASHES= CHROME_PATH= pnpm test:e2e // Without CHROME_PATH, they take the Chromium of `pnpm exec playwright install chromium`. The tests // of a fullflash that isn't found are skipped, and the run fails when none is. -// The unit tests run with Node's test runner: pnpm test. export default defineConfig({ test: { projects: [ + { + test: { + name: 'unit', + include: ['src/tests/**/*.test.ts'], + environment: 'node', + }, + }, { test: { name: 'e2e',