Files
HMDesign/packages/org-chart/test.mjs
T

18 lines
1.2 KiB
JavaScript

import { build } from 'vite';
import { globSync } from 'node:fs';
import { execFileSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
const root = fileURLToPath(new URL('./', import.meta.url));
// Optional exact paths let a change run only its affected tests; default keeps
// the existing full data test command and discovery unchanged.
const selected = process.argv.slice(2).map(file => file.replaceAll('\\', '/'));
const tests = [...globSync('src/**/*.test.ts', { cwd: root })].filter(file => !selected.length || selected.includes(file.replaceAll('\\', '/')));
if (!tests.length) throw new Error('No OrgChart data tests found');
await build({ configFile: false, root, publicDir: false, build: {
outDir: '../../test-results/org-chart-unit', emptyOutDir: true, target: 'node22', minify: false,
lib: { entry: Object.fromEntries(tests.map((file, i) => [`test-${i}`, path.join(root, file)])), formats: ['es'], fileName: (_, entry) => `${entry}.mjs` },
rolldownOptions: { external: [/^node:/] },
} });
execFileSync(process.execPath, ['--test', ...tests.map((_, i) => path.join(root, '../../test-results/org-chart-unit', `test-${i}.mjs`))], { stdio: 'inherit' });