Skip to content

Commit 9bedf4b

Browse files
rchljohnsoncodehk
andauthored
test: add tests for Vue 2 (#3351)
Co-authored-by: Johnson Chu <[email protected]>
1 parent b1ecfb8 commit 9bedf4b

File tree

10 files changed

+154
-7
lines changed

10 files changed

+154
-7
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"private": true,
3+
"name": "@volar/vue-test-workspace-vue-2",
4+
"version": "1.0.0",
5+
"license": "MIT",
6+
"devDependencies": {
7+
"vue": "^2.7.14",
8+
"vue-component-type-helpers": "1.8.3"
9+
}
10+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"lib": [
4+
"esnext",
5+
"dom"
6+
],
7+
"strict": true,
8+
"noUncheckedIndexedAccess": true,
9+
"noUnusedLocals": true,
10+
"noUnusedParameters": true,
11+
"skipLibCheck": true,
12+
"allowJs": true,
13+
"jsx": "preserve",
14+
},
15+
"include": [
16+
"**/*"
17+
]
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// https://stackoverflow.com/a/53808212
2+
type IfEquals<T, U, Y = unknown, N = never> =
3+
(<G>() => G extends T ? 1 : 2) extends
4+
(<G>() => G extends U ? 1 : 2) ? Y : N;
5+
export declare function exactType<T, U>(draft: T & IfEquals<T, U>, expected: U & IfEquals<T, U>): IfEquals<T, U>;
6+
7+
// https://stackoverflow.com/a/49928360
8+
type IfNotAny<T> = 0 extends 1 & T ? never : T;
9+
type IfNotUndefined<T> = Exclude<T, undefined> extends never ? never : T;
10+
export declare function isNotAnyOrUndefined<T>(value: IfNotAny<IfNotUndefined<T>>): void;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<template>
2+
<div>
3+
<!-- FIXME: bug here -->
4+
<!-- @vue-expect-error -->
5+
<Foo class="123"></Foo>
6+
<div class="123"></div>
7+
</div>
8+
</template>
9+
<script lang="ts">
10+
import { defineComponent } from 'vue';
11+
12+
const Foo = defineComponent({
13+
props: {
14+
foo: String
15+
}
16+
});
17+
</script>
18+
<script setup lang="ts">
19+
</script>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../tsconfig.base.json",
3+
"vueCompilerOptions": {
4+
"strictTemplates": true
5+
},
6+
"include": ["**/*"]
7+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<template>
2+
<div>
3+
<!-- @vue-expect-error -->
4+
<Foo bar="123"></Foo>
5+
6+
<!-- @vue-expect-error -->
7+
<div foo="123"></div>
8+
</div>
9+
</template>
10+
11+
<script lang="ts">
12+
import { defineComponent } from 'vue';
13+
14+
const Foo = defineComponent({
15+
props: {
16+
foo: String
17+
}
18+
});
19+
</script>
20+
<script setup lang="ts">
21+
</script>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"noPropertyAccessFromIndexSignature": true,
5+
},
6+
"vueCompilerOptions": {
7+
"target": 2.7,
8+
"jsxSlots": true,
9+
"plugins": ["../../vue-language-plugin-pug"]
10+
},
11+
"include": []
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<Foo class="123"></Foo>
3+
4+
<div class="123"></div>
5+
</template>
6+
7+
<script setup lang="ts">
8+
import { defineComponent } from 'vue';
9+
10+
const Foo = defineComponent({
11+
props: {
12+
foo: String
13+
}
14+
});
15+
</script>

packages/vue-tsc/tests/index.spec.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ import { describe, it } from 'vitest';
44
import { fork } from 'child_process';
55

66
const binPath = require.resolve('../bin/vue-tsc.js');
7-
const workspace = path.resolve(__dirname, '../../vue-test-workspace/vue-tsc');
7+
8+
const workspaceVue3 = path.resolve(__dirname, '../../vue-test-workspace/vue-tsc');
9+
const workspaceVue2 = path.resolve(__dirname, '../../vue-test-workspace-vue-2/vue-tsc');
810

911
function prettyPath(path: string, isRoot: boolean) {
1012
const segments = path.split('/');
1113
return !isRoot ? segments.slice(segments.length - 2, segments.length).join('/') : segments[segments.length - 1];
1214
}
1315

14-
function collectTests(dir: string, depth = 2, isRoot: boolean = true): [string, boolean][] {
15-
const tests: [string, boolean][] = [];
16+
function collectTests(dir: string, depth = 2, isRoot: boolean = true): [filePath: string, isRoot: boolean][] {
17+
const tests: [filePath: string, isRoot: boolean][] = [];
1618

1719
if (depth <= 0) {
1820
return tests;
@@ -37,7 +39,8 @@ function collectTests(dir: string, depth = 2, isRoot: boolean = true): [string,
3739
return tests;
3840
}
3941

40-
const tests = collectTests(workspace);
42+
const testsVue3 = collectTests(workspaceVue3);
43+
const testsVue2 = collectTests(workspaceVue2);
4144

4245
function runVueTsc(cwd: string) {
4346
return new Promise((resolve, reject) => {
@@ -70,7 +73,13 @@ function runVueTsc(cwd: string) {
7073
}
7174

7275
describe(`vue-tsc`, () => {
73-
for (const [path, isRoot] of tests) {
76+
for (const [path, isRoot] of testsVue3) {
77+
it(`vue-tsc no errors (${prettyPath(path, isRoot)})`, () => runVueTsc(path), 40_000);
78+
}
79+
});
80+
81+
describe(`vue-tsc (vue 2)`, () => {
82+
for (const [path, isRoot] of testsVue2) {
7483
it(`vue-tsc no errors (${prettyPath(path, isRoot)})`, () => runVueTsc(path), 40_000);
7584
}
7685
});

pnpm-lock.yaml

Lines changed: 28 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)