Use vitest
Some checks failed
CI / deploy (push) Failing after 16m45s

This commit is contained in:
Kirill Zhumarin 2026-10-11 20:22:59 +00:00
parent 7106e0e2ea
commit 76c99c8dec
7 changed files with 13 additions and 78 deletions

View file

@ -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",

View file

@ -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 });

View file

@ -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);

View file

@ -1,4 +1,4 @@
import { test } from 'node:test';
import { test } from 'vitest';
import assert from 'node:assert/strict';
import {
PatchHistoryEntry, addPatchHistoryEntry, clearPatchHistory, deletePatchHistoryEntry,

View file

@ -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';

View file

@ -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';

View file

@ -5,10 +5,16 @@ import { defineConfig } from 'vitest/config';
// SIE_FFS_TEST_FULLFLASHES=<directories of fullflashes> CHROME_PATH=<chrome> 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',