Skip to content

Commit 4fbd087

Browse files
committed
chore: update testing infrastructure (#5848)
1 parent 0f16db8 commit 4fbd087

File tree

589 files changed

+1826
-422
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

589 files changed

+1826
-422
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"runtimeExecutable": "${execPath}",
1111
"args": [
1212
"--extensionDevelopmentPath=${workspaceRoot}/extensions/vscode",
13-
"--folder-uri=${workspaceRoot}/test-workspace"
13+
"--folder-uri=${workspaceRoot}/test-workspace/tsc"
1414
],
1515
"outFiles": [
1616
"${workspaceRoot}/**/*.js"

.vscode/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
"vue.server.path": "packages/language-server",
3+
"typescript.tsdk": "node_modules/typescript/lib",
24
"dprint.path": "node_modules/dprint/dprint",
35
"[javascript]": {
46
"editor.defaultFormatter": "dprint.dprint"
@@ -20,6 +22,5 @@
2022
"packages/*/lib/**/*.d.ts": true,
2123
"packages/*/lib/**/*.js": true,
2224
"packages/*/lib/**/*.map": true
23-
},
24-
"typescript.tsdk": "node_modules/typescript/lib"
25+
}
2526
}

packages/tsc/tests/__snapshots__/dts.spec.ts.snap

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`vue-tsc-dts > Input: component-name-description/component.vue, Output: component-name-description/component.vue.d.ts 1`] = `
3+
exports[`Input: component-name-description/component.vue, Output: component-name-description/component.vue.d.ts 1`] = `
44
"/**
55
* My awesome component description
66
*/
@@ -38,7 +38,7 @@ declare const __VLS_export: import("vue").DefineComponent2<{
3838
"
3939
`;
4040

41-
exports[`vue-tsc-dts > Input: component-name-description/component-no-name.vue, Output: component-name-description/component-no-name.vue.d.ts 1`] = `
41+
exports[`Input: component-name-description/component-no-name.vue, Output: component-name-description/component-no-name.vue.d.ts 1`] = `
4242
"/**
4343
* Component without explicit name
4444
*/
@@ -74,7 +74,7 @@ export default _default;
7474
"
7575
`;
7676

77-
exports[`vue-tsc-dts > Input: component-name-description/component-ts.ts, Output: component-name-description/component-ts.d.ts 1`] = `
77+
exports[`Input: component-name-description/component-ts.ts, Output: component-name-description/component-ts.d.ts 1`] = `
7878
"/**
7979
* TypeScript component with description
8080
*/
@@ -111,7 +111,7 @@ export default _default;
111111
"
112112
`;
113113

114-
exports[`vue-tsc-dts > Input: empty-component/component.vue, Output: empty-component/component.vue.d.ts 1`] = `
114+
exports[`Input: empty-component/component.vue, Output: empty-component/component.vue.d.ts 1`] = `
115115
"declare const __VLS_export: import("vue").DefineComponent2<{
116116
setup(): {};
117117
data(): {};
@@ -138,7 +138,7 @@ export default _default;
138138
"
139139
`;
140140

141-
exports[`vue-tsc-dts > Input: empty-component/custom-extension-component.cext, Output: empty-component/custom-extension-component.cext.d.ts 1`] = `
141+
exports[`Input: empty-component/custom-extension-component.cext, Output: empty-component/custom-extension-component.cext.d.ts 1`] = `
142142
"declare const __VLS_export: import("vue").DefineComponent2<{
143143
setup(): {};
144144
data(): {};
@@ -165,7 +165,7 @@ export default _default;
165165
"
166166
`;
167167

168-
exports[`vue-tsc-dts > Input: generic/component.vue, Output: generic/component.vue.d.ts 1`] = `
168+
exports[`Input: generic/component.vue, Output: generic/component.vue.d.ts 1`] = `
169169
"declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
170170
props: __VLS_PrettifyLocal<({
171171
foo: number;
@@ -200,7 +200,7 @@ type __VLS_PrettifyLocal<T> = (T extends any ? {
200200
"
201201
`;
202202
203-
exports[`vue-tsc-dts > Input: generic/custom-extension-component.cext, Output: generic/custom-extension-component.cext.d.ts 1`] = `
203+
exports[`Input: generic/custom-extension-component.cext, Output: generic/custom-extension-component.cext.d.ts 1`] = `
204204
"declare const __VLS_export: <T>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
205205
props: __VLS_PrettifyLocal<({
206206
foo: number;
@@ -235,7 +235,7 @@ type __VLS_PrettifyLocal<T> = (T extends any ? {
235235
"
236236
`;
237237
238-
exports[`vue-tsc-dts > Input: generic/main.vue, Output: generic/main.vue.d.ts 1`] = `
238+
exports[`Input: generic/main.vue, Output: generic/main.vue.d.ts 1`] = `
239239
"declare const __VLS_export: import("vue").DefineComponent2<{
240240
setup(): {};
241241
data(): {};
@@ -262,13 +262,13 @@ export default _default;
262262
"
263263
`;
264264
265-
exports[`vue-tsc-dts > Input: non-component/component.ts, Output: non-component/component.d.ts 1`] = `
265+
exports[`Input: non-component/component.ts, Output: non-component/component.d.ts 1`] = `
266266
"declare const _default: {};
267267
export default _default;
268268
"
269269
`;
270270
271-
exports[`vue-tsc-dts > Input: options-api/component.ts, Output: options-api/component.d.ts 1`] = `
271+
exports[`Input: options-api/component.ts, Output: options-api/component.d.ts 1`] = `
272272
"interface SubmitPayload {
273273
/**
274274
* email of user
@@ -337,7 +337,7 @@ export default _default;
337337
"
338338
`;
339339
340-
exports[`vue-tsc-dts > Input: reference-type-events/component.vue, Output: reference-type-events/component.vue.d.ts 1`] = `
340+
exports[`Input: reference-type-events/component.vue, Output: reference-type-events/component.vue.d.ts 1`] = `
341341
"import type { MyEvents } from './my-events';
342342
declare const __VLS_export: import("vue").DefineComponent2<{
343343
setup(): {};
@@ -365,7 +365,7 @@ export default _default;
365365
"
366366
`;
367367
368-
exports[`vue-tsc-dts > Input: reference-type-events/my-events.ts, Output: reference-type-events/my-events.d.ts 1`] = `
368+
exports[`Input: reference-type-events/my-events.ts, Output: reference-type-events/my-events.d.ts 1`] = `
369369
"/**
370370
* Emitted when the foo property is changed.
371371
*/
@@ -384,7 +384,7 @@ export {};
384384
"
385385
`;
386386
387-
exports[`vue-tsc-dts > Input: reference-type-exposed/component.vue, Output: reference-type-exposed/component.vue.d.ts 1`] = `
387+
exports[`Input: reference-type-exposed/component.vue, Output: reference-type-exposed/component.vue.d.ts 1`] = `
388388
"declare const __VLS_export: import("vue").DefineComponent2<{
389389
setup(): {
390390
/**
@@ -416,7 +416,7 @@ export default _default;
416416
"
417417
`;
418418
419-
exports[`vue-tsc-dts > Input: reference-type-model/component.vue, Output: reference-type-model/component.vue.d.ts 1`] = `
419+
exports[`Input: reference-type-model/component.vue, Output: reference-type-model/component.vue.d.ts 1`] = `
420420
"type __VLS_ModelProps = {
421421
/**
422422
* required number modelValue
@@ -463,7 +463,7 @@ export default _default;
463463
"
464464
`;
465465
466-
exports[`vue-tsc-dts > Input: reference-type-props/component.vue, Output: reference-type-props/component.vue.d.ts 1`] = `
466+
exports[`Input: reference-type-props/component.vue, Output: reference-type-props/component.vue.d.ts 1`] = `
467467
"import { MyProps } from './my-props';
468468
declare const __VLS_export: import("vue").DefineComponent2<{
469469
setup(): {};
@@ -494,7 +494,7 @@ export default _default;
494494
"
495495
`;
496496
497-
exports[`vue-tsc-dts > Input: reference-type-props/component-destructure.vue, Output: reference-type-props/component-destructure.vue.d.ts 1`] = `
497+
exports[`Input: reference-type-props/component-destructure.vue, Output: reference-type-props/component-destructure.vue.d.ts 1`] = `
498498
"type __VLS_Props = {
499499
text: string;
500500
};
@@ -524,7 +524,7 @@ export default _default;
524524
"
525525
`;
526526
527-
exports[`vue-tsc-dts > Input: reference-type-props/component-js.vue, Output: reference-type-props/component-js.vue.d.ts 1`] = `
527+
exports[`Input: reference-type-props/component-js.vue, Output: reference-type-props/component-js.vue.d.ts 1`] = `
528528
"declare const _default: typeof __VLS_export;
529529
export default _default;
530530
declare const __VLS_export: import("vue").DefineComponent2<{
@@ -574,7 +574,7 @@ declare const __VLS_export: import("vue").DefineComponent2<{
574574
"
575575
`;
576576
577-
exports[`vue-tsc-dts > Input: reference-type-props/component-js-setup.vue, Output: reference-type-props/component-js-setup.vue.d.ts 1`] = `
577+
exports[`Input: reference-type-props/component-js-setup.vue, Output: reference-type-props/component-js-setup.vue.d.ts 1`] = `
578578
"declare const __VLS_export: import("vue").DefineComponent2<{
579579
setup(): {};
580580
data(): {};
@@ -641,7 +641,7 @@ export default _default;
641641
"
642642
`;
643643
644-
exports[`vue-tsc-dts > Input: reference-type-props/my-props.ts, Output: reference-type-props/my-props.d.ts 1`] = `
644+
exports[`Input: reference-type-props/my-props.ts, Output: reference-type-props/my-props.d.ts 1`] = `
645645
"export interface MyNestedProps {
646646
/**
647647
* nested prop documentation
@@ -752,7 +752,7 @@ export {};
752752
"
753753
`;
754754
755-
exports[`vue-tsc-dts > Input: reference-type-slots/component.vue, Output: reference-type-slots/component.vue.d.ts 1`] = `
755+
exports[`Input: reference-type-slots/component.vue, Output: reference-type-slots/component.vue.d.ts 1`] = `
756756
"declare var __VLS_1: {}, __VLS_3: {
757757
num: number;
758758
}, __VLS_5: {
@@ -802,7 +802,7 @@ type __VLS_WithSlots<T, S> = T & {
802802
"
803803
`;
804804
805-
exports[`vue-tsc-dts > Input: reference-type-slots/component-define-slots.vue, Output: reference-type-slots/component-define-slots.vue.d.ts 1`] = `
805+
exports[`Input: reference-type-slots/component-define-slots.vue, Output: reference-type-slots/component-define-slots.vue.d.ts 1`] = `
806806
"import type { VNode } from 'vue';
807807
type __VLS_Slots = {
808808
default: (props: {
@@ -849,7 +849,7 @@ type __VLS_WithSlots<T, S> = T & {
849849
"
850850
`;
851851
852-
exports[`vue-tsc-dts > Input: reference-type-slots/component-no-script.vue, Output: reference-type-slots/component-no-script.vue.d.ts 1`] = `
852+
exports[`Input: reference-type-slots/component-no-script.vue, Output: reference-type-slots/component-no-script.vue.d.ts 1`] = `
853853
"declare var __VLS_1: {}, __VLS_3: {
854854
num: number;
855855
}, __VLS_5: {
@@ -899,7 +899,7 @@ type __VLS_WithSlots<T, S> = T & {
899899
"
900900
`;
901901
902-
exports[`vue-tsc-dts > Input: ts-component/PropDefinitions.ts, Output: ts-component/PropDefinitions.d.ts 1`] = `
902+
exports[`Input: ts-component/PropDefinitions.ts, Output: ts-component/PropDefinitions.d.ts 1`] = `
903903
"export interface MyProps {
904904
/**
905905
* string foo
@@ -913,11 +913,11 @@ exports[`vue-tsc-dts > Input: ts-component/PropDefinitions.ts, Output: ts-compon
913913
"
914914
`;
915915
916-
exports[`vue-tsc-dts > Input: ts-component/component.ts, Output: ts-component/component.d.ts 1`] = `undefined`;
916+
exports[`Input: ts-component/component.ts, Output: ts-component/component.d.ts 1`] = `undefined`;
917917
918-
exports[`vue-tsc-dts > Input: ts-component/component.tsx, Output: ts-component/component.d.ts 1`] = `undefined`;
918+
exports[`Input: ts-component/component.tsx, Output: ts-component/component.d.ts 1`] = `undefined`;
919919
920-
exports[`vue-tsc-dts > Input: ts-named-export/component.ts, Output: ts-named-export/component.d.ts 1`] = `
920+
exports[`Input: ts-named-export/component.ts, Output: ts-named-export/component.d.ts 1`] = `
921921
"export declare const Foo: import("vue").DefineSetupFnComponent<{
922922
foo: string;
923923
}, string[], {}, {

packages/tsc/tests/dts.spec.ts

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,73 +3,70 @@ import * as core from '@vue/language-core';
33
import * as fs from 'node:fs';
44
import * as path from 'node:path';
55
import * as ts from 'typescript';
6-
import { describe, expect, it } from 'vitest';
6+
import { expect, test } from 'vitest';
77

88
const workspace = path.resolve(__dirname, '../../../test-workspace/component-meta');
99
const normalizePath = (filename: string) => filename.replace(/\\/g, '/');
1010
const normalizeNewline = (text: string) => text.replace(/\r\n/g, '\n');
1111
const windowsPathReg = /\\/g;
1212

13-
describe('vue-tsc-dts', () => {
14-
const compilerOptions: ts.CompilerOptions = {
15-
rootDir: workspace,
16-
declaration: true,
17-
emitDeclarationOnly: true,
18-
allowNonTsExtensions: true,
19-
};
20-
const host = ts.createCompilerHost(compilerOptions);
21-
const options: ts.CreateProgramOptions = {
22-
host,
23-
rootNames: readFilesRecursive(workspace),
24-
options: compilerOptions,
25-
};
13+
const compilerOptions: ts.CompilerOptions = {
14+
rootDir: workspace,
15+
declaration: true,
16+
emitDeclarationOnly: true,
17+
allowNonTsExtensions: true,
18+
};
19+
const host = ts.createCompilerHost(compilerOptions);
20+
const options: ts.CreateProgramOptions = {
21+
host,
22+
rootNames: readFilesRecursive(workspace),
23+
options: compilerOptions,
24+
};
2625

27-
let vueOptions: core.VueCompilerOptions;
26+
let vueOptions: core.VueCompilerOptions;
2827

29-
const createProgram = proxyCreateProgram(ts, ts.createProgram, (ts, options) => {
30-
const { configFilePath } = options.options;
31-
if (typeof configFilePath === 'string') {
32-
vueOptions = core.createParsedCommandLine(ts, ts.sys, configFilePath.replace(windowsPathReg, '/')).vueOptions;
33-
}
34-
else {
35-
vueOptions =
36-
core.createParsedCommandLineByJson(ts, ts.sys, workspace.replace(windowsPathReg, '/'), {}).vueOptions;
37-
vueOptions.target = 99;
38-
vueOptions.extensions = ['vue', 'cext'];
39-
}
40-
vueOptions.globalTypesPath = core.createGlobalTypesWriter(vueOptions, ts.sys.writeFile);
41-
const vueLanguagePlugin = core.createVueLanguagePlugin<string>(
42-
ts,
43-
options.options,
44-
vueOptions,
45-
id => id,
46-
);
47-
return [vueLanguagePlugin];
48-
});
49-
const program = createProgram(options);
50-
51-
for (const intputFile of options.rootNames) {
52-
const expectedOutputFile = intputFile.endsWith('.ts')
53-
? intputFile.slice(0, -'.ts'.length) + '.d.ts'
54-
: intputFile.endsWith('.tsx')
55-
? intputFile.slice(0, -'.tsx'.length) + '.d.ts'
56-
: intputFile + '.d.ts';
57-
it(`Input: ${shortenPath(intputFile)}, Output: ${shortenPath(expectedOutputFile)}`, () => {
58-
let outputText: string | undefined;
59-
const sourceFile = program.getSourceFile(intputFile);
60-
program.emit(
61-
sourceFile,
62-
(outputFile, text) => {
63-
expect(outputFile.replace(windowsPathReg, '/')).toBe(expectedOutputFile.replace(windowsPathReg, '/'));
64-
outputText = text;
65-
},
66-
undefined,
67-
true,
68-
);
69-
expect(outputText ? normalizeNewline(outputText) : undefined).toMatchSnapshot();
70-
});
28+
const createProgram = proxyCreateProgram(ts, ts.createProgram, (ts, options) => {
29+
const { configFilePath } = options.options;
30+
if (typeof configFilePath === 'string') {
31+
vueOptions = core.createParsedCommandLine(ts, ts.sys, configFilePath.replace(windowsPathReg, '/')).vueOptions;
7132
}
33+
else {
34+
vueOptions = core.createParsedCommandLineByJson(ts, ts.sys, workspace.replace(windowsPathReg, '/'), {}).vueOptions;
35+
vueOptions.target = 99;
36+
vueOptions.extensions = ['vue', 'cext'];
37+
}
38+
vueOptions.globalTypesPath = core.createGlobalTypesWriter(vueOptions, ts.sys.writeFile);
39+
const vueLanguagePlugin = core.createVueLanguagePlugin<string>(
40+
ts,
41+
options.options,
42+
vueOptions,
43+
id => id,
44+
);
45+
return [vueLanguagePlugin];
7246
});
47+
const program = createProgram(options);
48+
49+
for (const intputFile of options.rootNames) {
50+
const expectedOutputFile = intputFile.endsWith('.ts')
51+
? intputFile.slice(0, -'.ts'.length) + '.d.ts'
52+
: intputFile.endsWith('.tsx')
53+
? intputFile.slice(0, -'.tsx'.length) + '.d.ts'
54+
: intputFile + '.d.ts';
55+
test(`Input: ${shortenPath(intputFile)}, Output: ${shortenPath(expectedOutputFile)}`, () => {
56+
let outputText: string | undefined;
57+
const sourceFile = program.getSourceFile(intputFile);
58+
program.emit(
59+
sourceFile,
60+
(outputFile, text) => {
61+
expect(outputFile.replace(windowsPathReg, '/')).toBe(expectedOutputFile.replace(windowsPathReg, '/'));
62+
outputText = text;
63+
},
64+
undefined,
65+
true,
66+
);
67+
expect(outputText ? normalizeNewline(outputText) : undefined).toMatchSnapshot();
68+
});
69+
}
7370

7471
function readFilesRecursive(dir: string) {
7572
if (path.relative(workspace, dir).startsWith('#')) {

0 commit comments

Comments
 (0)