Skip to content

Commit e6ab227

Browse files
committed
fix: add test for typeScript.
1 parent b870965 commit e6ab227

File tree

7 files changed

+96
-2
lines changed

7 files changed

+96
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"access": "public"
4949
},
5050
"dependencies": {
51+
"@typescript-eslint/parser": "5.45.0",
5152
"commander": "9.4.1",
5253
"ejs": "3.1.8",
5354
"express": "4.18.2",
@@ -72,7 +73,6 @@
7273
"@types/opener": "1.4.0",
7374
"@types/ws": "8.5.3",
7475
"@typescript-eslint/eslint-plugin": "5.45.0",
75-
"@typescript-eslint/parser": "5.45.0",
7676
"eslint": "8.29.0",
7777
"husky": "8.0.2",
7878
"jest": "29.3.1",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<template>
2+
<div></div>
3+
</template>
4+
<script setup>
5+
defineProps({
6+
data: {
7+
type: String,
8+
required: true,
9+
default: '1',
10+
},
11+
data2: {
12+
type: Number,
13+
required: false,
14+
default: 1,
15+
},
16+
});
17+
</script>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<template>
2+
<div></div>
3+
</template>
4+
<script setup lang="ts">
5+
export default {
6+
created() {
7+
const num: number = 0;
8+
const str: string = '';
9+
const bool: boolean = false;
10+
},
11+
}
12+
</script>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<template>
2+
<div></div>
3+
</template>
4+
<script lang="ts">
5+
const num: number = 0;
6+
const str: string = '';
7+
const bool: boolean = false;
8+
</script>

test/specs/importDeclaration.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@ describe('import declaration test', () => {
7777
props: '',
7878
size: 88,
7979
lastModifiedTime: 0,
80-
children: [],
80+
children: [{
81+
name: '/test/components/child.vue',
82+
props: '',
83+
size: 42,
84+
lastModifiedTime: 0,
85+
children: [],
86+
}],
8187
});
8288
});
8389

test/specs/props.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,29 @@ describe('props test', () => {
1919

2020
expect(json).toMatchSnapshot();
2121
});
22+
23+
24+
it('defineTwoProps.vue', async () => {
25+
const filename = 'propsTest/defineTwoProps';
26+
const declaration = await getImportDeclarationTree(join(fixturesDir, `${filename}.vue`), [], true);
27+
28+
expect(declaration).toStrictEqual({
29+
name: '/test/fixture/propsTest/defineTwoProps.vue',
30+
props: {
31+
data: {
32+
type: 'String',
33+
required: 'true',
34+
default: '1',
35+
},
36+
data2: {
37+
type: 'Number',
38+
required: 'false',
39+
default: 1,
40+
},
41+
},
42+
size: 222,
43+
lastModifiedTime: 0,
44+
children: [],
45+
});
46+
});
2247
});

test/specs/syntax.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,30 @@ describe('syntax test', () => {
3434

3535
expect(json).toMatchSnapshot();
3636
});
37+
38+
it('langIsTypeScript.vue', async () => {
39+
const filename = 'syntaxTest/langIsTypeScript';
40+
const declaration = await getImportDeclarationTree(join(fixturesDir, `${filename}.vue`), [], true);
41+
42+
expect(declaration).toStrictEqual({
43+
name: '/test/fixture/syntaxTest/langIsTypeScript.vue',
44+
props: '',
45+
size: 198,
46+
lastModifiedTime: 0,
47+
children: [],
48+
});
49+
});
50+
51+
it('langIsTypeScriptWithSetup.vue', async () => {
52+
const filename = 'syntaxTest/langIsTypeScriptWithSetup';
53+
const declaration = await getImportDeclarationTree(join(fixturesDir, `${filename}.vue`), [], true);
54+
55+
expect(declaration).toStrictEqual({
56+
name: '/test/fixture/syntaxTest/langIsTypeScriptWithSetup.vue',
57+
props: '',
58+
size: 142,
59+
lastModifiedTime: 0,
60+
children: [],
61+
});
62+
});
3763
});

0 commit comments

Comments
 (0)