Skip to content

Commit 73bab01

Browse files
authored
test: auto collect vue-tsc tests (#3634)
1 parent 2d72fa4 commit 73bab01

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

packages/vue-tsc/tests/index.spec.ts

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,43 @@
11
import * as path from 'path';
2+
import * as fs from 'fs';
23
import { describe, it } from 'vitest';
34
import { fork } from 'child_process';
45

56
const binPath = require.resolve('../bin/vue-tsc.js');
6-
const workspace = path.resolve(__dirname, '../../vue-test-workspace/vue-tsc')
7+
const workspace = path.resolve(__dirname, '../../vue-test-workspace/vue-tsc');
8+
9+
function prettyPath(path: string, isRoot: boolean) {
10+
const segments = path.split('/');
11+
return !isRoot ? segments.slice(segments.length - 2, segments.length).join('/') : segments[segments.length - 1];
12+
}
13+
14+
function collectTests(dir: string, depth = 2, isRoot: boolean = true): [string, boolean][] {
15+
const tests: [string, boolean][] = [];
16+
17+
if (depth <= 0) {
18+
return tests;
19+
}
20+
21+
const files = fs.readdirSync(dir);
22+
for (const file of files) {
23+
const filePath = path.join(dir, file);
24+
const stat = fs.statSync(filePath);
25+
if (stat.isDirectory()) {
26+
const tsconfigPath = path.join(filePath, 'tsconfig.json');
27+
if (fs.existsSync(tsconfigPath)) {
28+
tests.push([
29+
filePath.replace(/\\/g, '/'),
30+
isRoot,
31+
]);
32+
}
33+
tests.push(...collectTests(filePath, depth - 1, false));
34+
}
35+
}
36+
37+
return tests;
38+
}
39+
40+
const tests = collectTests(workspace);
741

842
function runVueTsc(cwd: string) {
943
return new Promise((resolve, reject) => {
@@ -32,11 +66,11 @@ function runVueTsc(cwd: string) {
3266
reject(new Error(`Exited with code ${code}`));
3367
}
3468
});
35-
})
69+
});
3670
}
3771

3872
describe(`vue-tsc`, () => {
39-
it(`vue-tsc no errors (non-strict-template)`, () => runVueTsc(path.resolve(workspace, './non-strict-template')), 40_000);
40-
it(`vue-tsc no errors (strict-template)`, () => runVueTsc(path.resolve(workspace, './strict-template')), 40_000);
41-
it(`vue-tsc no errors (#3373)`, () => runVueTsc(path.resolve(workspace, './#3373')), 40_000);
73+
for (const [path, isRoot] of tests) {
74+
it(`vue-tsc no errors (${prettyPath(path, isRoot)})`, () => runVueTsc(path), 40_000);
75+
}
4276
});

0 commit comments

Comments
 (0)