Files
h-school/src/HSchool.Client/scripts/run-test.mjs
T
Leonid Pershin 45059b927f Run client typecheck before vitest in npm test.
Duplicate keys in strings.ts were green under vitest and red only on build. Drop the self file: dependency loop so npm test is enough.
2026-08-20 12:57:16 +03:00

39 lines
1.0 KiB
JavaScript

// `tsc -b && vitest run` on Windows npm (tsc.cmd) can drop the typecheck exit code.
import { spawnSync } from 'node:child_process';
import { createRequire } from 'node:module';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const clientRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const require = createRequire(import.meta.url);
const win = process.platform === 'win32';
function statusOf(result) {
if (result.error) {
console.error(result.error);
return 1;
}
return result.status ?? 1;
}
const typecheck = statusOf(
spawnSync(process.execPath, [require.resolve('typescript/bin/tsc'), '-b'], {
cwd: clientRoot,
stdio: 'inherit',
}),
);
if (typecheck !== 0) {
process.exit(typecheck);
}
const vitest = path.join(clientRoot, 'node_modules', '.bin', win ? 'vitest.cmd' : 'vitest');
process.exit(
statusOf(
spawnSync(vitest, ['run', ...process.argv.slice(2)], {
cwd: clientRoot,
stdio: 'inherit',
shell: win,
}),
),
);