Skip to content

Commit

Permalink
test(tsc): add test for TS-next (#4724)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk authored Aug 25, 2024
1 parent a243f94 commit e4d3683
Show file tree
Hide file tree
Showing 3 changed files with 860 additions and 881 deletions.
70 changes: 47 additions & 23 deletions packages/tsc/tests/typecheck.spec.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,59 @@
import * as path from 'path';
import { describe, expect, it } from 'vitest';
import { describe, expect, test } from 'vitest';
import { run } from '..';

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

it(`typecheck`, () => {
const consoleOutput: string[] = [];
const originalConsoleLog = process.stdout.write;
const originalArgv = process.argv;
process.stdout.write = output => {
consoleOutput.push(String(output).trim());
return true;
};
process.argv = [
...originalArgv,
'--build',
path.resolve(__dirname, '../../../test-workspace/tsc'),
'--pretty',
'false',
];
try {
run();
} catch (err) { }
process.stdout.write = originalConsoleLog;
process.argv = originalArgv;
expect(consoleOutput).toMatchInlineSnapshot(`
test(`TypeScript - Stable`, () => {
expect(
getTscOutput('stable')
).toMatchInlineSnapshot(`
[
"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 ..., {}>'.",
"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 ..., {}>'.",
"test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.",
]
`);;
`);
});

test(`TypeScript - next`, () => {
expect(
getTscOutput('next')
).toMatchInlineSnapshot(`
[
"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 ..., {}>'.",
"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 ..., {}>'.",
"test-workspace/tsc/failureFixtures/directives/main.vue(12,2): error TS2578: Unused '@ts-expect-error' directive.",
"test-workspace/tsc/passedFixtures/#3373/tsconfig.json(4,3): error TS5102: Option 'importsNotUsedAsValues' has been removed. Please remove it from your configuration.
Use 'verbatimModuleSyntax' instead.",
]
`);
});
});

function getTscOutput(tsVersion: 'stable' | 'next') {
const consoleOutput: string[] = [];
const originalConsoleLog = process.stdout.write;
const originalArgv = process.argv;
process.stdout.write = output => {
consoleOutput.push(String(output).trim());
return true;
};
process.argv = [
...originalArgv,
'--build',
path.resolve(__dirname, '../../../test-workspace/tsc'),
'--pretty',
'false',
];
try {
const tscPath = require.resolve(
`typescript-${tsVersion}/lib/tsc`,
{ paths: [path.resolve(__dirname, '../../../test-workspace')] }
);
run(tscPath);
} catch (err) { }
process.stdout.write = originalConsoleLog;
process.argv = originalArgv;
return consoleOutput;
}
Loading

0 comments on commit e4d3683

Please sign in to comment.