-
-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(tsc): add test for TS-next (#4724)
- Loading branch information
1 parent
a243f94
commit e4d3683
Showing
3 changed files
with
860 additions
and
881 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.