Skip to content

Commit e4d3683

Browse files
test(tsc): add test for TS-next (#4724)
1 parent a243f94 commit e4d3683

File tree

3 files changed

+860
-881
lines changed

3 files changed

+860
-881
lines changed

packages/tsc/tests/typecheck.spec.ts

+47-23
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,59 @@
11
import * as path from 'path';
2-
import { describe, expect, it } from 'vitest';
2+
import { describe, expect, test } from 'vitest';
33
import { run } from '..';
44

55
describe(`vue-tsc`, () => {
66

7-
it(`typecheck`, () => {
8-
const consoleOutput: string[] = [];
9-
const originalConsoleLog = process.stdout.write;
10-
const originalArgv = process.argv;
11-
process.stdout.write = output => {
12-
consoleOutput.push(String(output).trim());
13-
return true;
14-
};
15-
process.argv = [
16-
...originalArgv,
17-
'--build',
18-
path.resolve(__dirname, '../../../test-workspace/tsc'),
19-
'--pretty',
20-
'false',
21-
];
22-
try {
23-
run();
24-
} catch (err) { }
25-
process.stdout.write = originalConsoleLog;
26-
process.argv = originalArgv;
27-
expect(consoleOutput).toMatchInlineSnapshot(`
7+
test(`TypeScript - Stable`, () => {
8+
expect(
9+
getTscOutput('stable')
10+
).toMatchInlineSnapshot(`
2811
[
2912
"test-workspace/tsc/failureFixtures/directives/main.vue(4,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstance<Readonly<ExtractPropTypes<{}>>, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 12 more ..., {}>'.",
3013
"test-workspace/tsc/failureFixtures/directives/main.vue(9,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstance<Readonly<ExtractPropTypes<{}>>, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 12 more ..., {}>'.",
3114
"test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.",
3215
]
33-
`);;
16+
`);
17+
});
18+
19+
test(`TypeScript - next`, () => {
20+
expect(
21+
getTscOutput('next')
22+
).toMatchInlineSnapshot(`
23+
[
24+
"test-workspace/tsc/failureFixtures/directives/main.vue(4,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstance<Readonly<ExtractPropTypes<{}>>, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 12 more ..., {}>'.",
25+
"test-workspace/tsc/failureFixtures/directives/main.vue(9,6): error TS2339: Property 'notExist' does not exist on type 'CreateComponentPublicInstance<Readonly<ExtractPropTypes<{}>>, { exist: typeof exist; }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, ... 12 more ..., {}>'.",
26+
"test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.",
27+
"test-workspace/tsc/passedFixtures/#3373/tsconfig.json(4,3): error TS5102: Option 'importsNotUsedAsValues' has been removed. Please remove it from your configuration.
28+
Use 'verbatimModuleSyntax' instead.",
29+
]
30+
`);
3431
});
3532
});
33+
34+
function getTscOutput(tsVersion: 'stable' | 'next') {
35+
const consoleOutput: string[] = [];
36+
const originalConsoleLog = process.stdout.write;
37+
const originalArgv = process.argv;
38+
process.stdout.write = output => {
39+
consoleOutput.push(String(output).trim());
40+
return true;
41+
};
42+
process.argv = [
43+
...originalArgv,
44+
'--build',
45+
path.resolve(__dirname, '../../../test-workspace/tsc'),
46+
'--pretty',
47+
'false',
48+
];
49+
try {
50+
const tscPath = require.resolve(
51+
`typescript-${tsVersion}/lib/tsc`,
52+
{ paths: [path.resolve(__dirname, '../../../test-workspace')] }
53+
);
54+
run(tscPath);
55+
} catch (err) { }
56+
process.stdout.write = originalConsoleLog;
57+
process.argv = originalArgv;
58+
return consoleOutput;
59+
}

0 commit comments

Comments
 (0)