Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tests for Vue 2 #3351

Merged
merged 3 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/vue-test-workspace-vue-2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"private": true,
"name": "@volar/vue-test-workspace-vue-2",
"version": "1.0.0",
"license": "MIT",
"devDependencies": {
"vue": "^2.7.14",
"vue-component-type-helpers": "1.8.3"
}
}
18 changes: 18 additions & 0 deletions packages/vue-test-workspace-vue-2/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"lib": [
"esnext",
"dom"
],
"strict": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"skipLibCheck": true,
"allowJs": true,
"jsx": "preserve",
},
"include": [
"**/*"
]
}
10 changes: 10 additions & 0 deletions packages/vue-test-workspace-vue-2/vue-tsc/shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// https://stackoverflow.com/a/53808212
type IfEquals<T, U, Y = unknown, N = never> =
(<G>() => G extends T ? 1 : 2) extends
(<G>() => G extends U ? 1 : 2) ? Y : N;
export declare function exactType<T, U>(draft: T & IfEquals<T, U>, expected: U & IfEquals<T, U>): IfEquals<T, U>;

// https://stackoverflow.com/a/49928360
type IfNotAny<T> = 0 extends 1 & T ? never : T;
type IfNotUndefined<T> = Exclude<T, undefined> extends never ? never : T;
export declare function isNotAnyOrUndefined<T>(value: IfNotAny<IfNotUndefined<T>>): void;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<template>
<div>
<!-- FIXME: bug here -->
<!-- @vue-expect-error -->
haoqunjiang marked this conversation as resolved.
Show resolved Hide resolved
<Foo class="123"></Foo>
<div class="123"></div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';

const Foo = defineComponent({
props: {
foo: String
}
});
</script>
<script setup lang="ts">
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.base.json",
"vueCompilerOptions": {
"strictTemplates": true
},
"include": ["**/*"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<div>
<!-- @vue-expect-error -->
<Foo bar="123"></Foo>

<!-- @vue-expect-error -->
<div foo="123"></div>
</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';

const Foo = defineComponent({
props: {
foo: String
}
});
</script>
<script setup lang="ts">
</script>
Comment on lines +11 to +21
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is a bit different from how I wrote this in my changes. My version only had one script setup block.

12 changes: 12 additions & 0 deletions packages/vue-test-workspace-vue-2/vue-tsc/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noPropertyAccessFromIndexSignature": true,
},
"vueCompilerOptions": {
"target": 2.7,
"jsxSlots": true,
"plugins": ["../../vue-language-plugin-pug"]
},
"include": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<Foo class="123"></Foo>

<div class="123"></div>
</template>

<script setup lang="ts">
import { defineComponent } from 'vue';

const Foo = defineComponent({
props: {
foo: String
}
});
</script>
19 changes: 14 additions & 5 deletions packages/vue-tsc/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import { describe, it } from 'vitest';
import { fork } from 'child_process';

const binPath = require.resolve('../bin/vue-tsc.js');
const workspace = path.resolve(__dirname, '../../vue-test-workspace/vue-tsc');

const workspaceVue3 = path.resolve(__dirname, '../../vue-test-workspace/vue-tsc');
const workspaceVue2 = path.resolve(__dirname, '../../vue-test-workspace-vue-2/vue-tsc');

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

function collectTests(dir: string, depth = 2, isRoot: boolean = true): [string, boolean][] {
const tests: [string, boolean][] = [];
function collectTests(dir: string, depth = 2, isRoot: boolean = true): [filePath: string, isRoot: boolean][] {
const tests: [filePath: string, isRoot: boolean][] = [];

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

const tests = collectTests(workspace);
const testsVue3 = collectTests(workspaceVue3);
const testsVue2 = collectTests(workspaceVue2);

function runVueTsc(cwd: string) {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -70,7 +73,13 @@ function runVueTsc(cwd: string) {
}

describe(`vue-tsc`, () => {
for (const [path, isRoot] of tests) {
for (const [path, isRoot] of testsVue3) {
it(`vue-tsc no errors (${prettyPath(path, isRoot)})`, () => runVueTsc(path), 40_000);
}
});

describe(`vue-tsc (vue 2)`, () => {
for (const [path, isRoot] of testsVue2) {
it(`vue-tsc no errors (${prettyPath(path, isRoot)})`, () => runVueTsc(path), 40_000);
}
});
30 changes: 28 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading