|
1 | 1 | import * as path from 'path';
|
| 2 | +import * as fs from 'fs'; |
2 | 3 | import { describe, it } from 'vitest';
|
3 | 4 | import { fork } from 'child_process';
|
4 | 5 |
|
5 | 6 | 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); |
7 | 41 |
|
8 | 42 | function runVueTsc(cwd: string) {
|
9 | 43 | return new Promise((resolve, reject) => {
|
@@ -32,11 +66,11 @@ function runVueTsc(cwd: string) {
|
32 | 66 | reject(new Error(`Exited with code ${code}`));
|
33 | 67 | }
|
34 | 68 | });
|
35 |
| - }) |
| 69 | + }); |
36 | 70 | }
|
37 | 71 |
|
38 | 72 | 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 | + } |
42 | 76 | });
|
0 commit comments