7
7
WEBPACK_DEV_SERVER_VERSION ,
8
8
} from './sandbox/WebpackDevServerDriver' ;
9
9
import { FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION } from './sandbox/Plugin' ;
10
+ import semver from 'semver/preload' ;
10
11
11
12
describe ( 'TypeScript Vue Extension' , ( ) => {
12
13
let sandbox : Sandbox ;
@@ -29,21 +30,23 @@ describe('TypeScript Vue Extension', () => {
29
30
typescript : '^3.8.0' ,
30
31
tsloader : '^7.0.0' ,
31
32
vueloader : '^15.8.3' ,
32
- vue : '^2.6.11 ' ,
33
+ vue : '^2.0.0 ' ,
33
34
compiler : 'vue-template-compiler' ,
35
+ qrcodevue : '^1.7.0' ,
34
36
} ,
35
37
{
36
38
async : true ,
37
39
typescript : '^3.8.0' ,
38
40
tsloader : '^7.0.0' ,
39
- vueloader : 'v16.0.0-beta .3' ,
40
- vue : '^3.0.0-beta.14 ' ,
41
+ vueloader : 'v16.8 .3' ,
42
+ vue : '^3.0.0' ,
41
43
compiler : '@vue/compiler-sfc' ,
44
+ qrcodevue : '^3.0.0' ,
42
45
} ,
43
46
] ) (
44
47
'reports semantic error for %p' ,
45
- async ( { async, typescript, tsloader, vueloader, vue, compiler } ) => {
46
- await sandbox . load ( [
48
+ async ( { async, typescript, tsloader, vueloader, vue, compiler, qrcodevue } ) => {
49
+ const fixtures = [
47
50
await readFixture ( join ( __dirname , 'fixtures/environment/typescript-vue.fixture' ) , {
48
51
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION : JSON . stringify (
49
52
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION
@@ -56,12 +59,23 @@ describe('TypeScript Vue Extension', () => {
56
59
VUE_LOADER_VERSION : JSON . stringify ( vueloader ) ,
57
60
VUE_VERSION : JSON . stringify ( vue ) ,
58
61
VUE_COMPILER : JSON . stringify ( compiler ) ,
62
+ QRCODE_VUE_VERSION : JSON . stringify ( qrcodevue ) ,
59
63
ASYNC : JSON . stringify ( async ) ,
60
64
} ) ,
61
- await readFixture ( join ( __dirname , 'fixtures/implementation/typescript-vue.fixture' ) ) ,
62
- ] ) ;
65
+ await readFixture ( join ( __dirname , 'fixtures/implementation/typescript-vue-shared.fixture' ) ) ,
66
+ ] ;
67
+ if ( semver . satisfies ( '2.0.0' , vue ) ) {
68
+ fixtures . push (
69
+ await readFixture ( join ( __dirname , 'fixtures/implementation/typescript-vue2.fixture' ) )
70
+ ) ;
71
+ } else if ( semver . satisfies ( '3.0.0' , vue ) ) {
72
+ fixtures . push (
73
+ await readFixture ( join ( __dirname , 'fixtures/implementation/typescript-vue3.fixture' ) )
74
+ ) ;
75
+ }
76
+ await sandbox . load ( fixtures ) ;
63
77
64
- if ( vue === '^2.6.11' ) {
78
+ if ( semver . satisfies ( '2.0.0' , vue ) ) {
65
79
await sandbox . write (
66
80
'src/vue-shim.d.ts' ,
67
81
[
@@ -71,7 +85,7 @@ describe('TypeScript Vue Extension', () => {
71
85
'}' ,
72
86
] . join ( '\n' )
73
87
) ;
74
- } else {
88
+ } else if ( semver . satisfies ( '3.0.0' , vue ) ) {
75
89
await sandbox . write ( 'src/vue-shim.d.ts' , 'declare module "*.vue";' ) ;
76
90
}
77
91
@@ -98,7 +112,7 @@ describe('TypeScript Vue Extension', () => {
98
112
'ERROR in src/component/LoggedIn.vue:27:21' ,
99
113
"TS2304: Cannot find name 'getUserName'." ,
100
114
' 25 | const user: User = this.user;' ,
101
- ' 26 | ' ,
115
+ ' 26 |' ,
102
116
" > 27 | return user ? getUserName(user) : '';" ,
103
117
' | ^^^^^^^^^^^' ,
104
118
' 28 | }' ,
@@ -126,7 +140,7 @@ describe('TypeScript Vue Extension', () => {
126
140
'ERROR in src/component/LoggedIn.vue:27:29' ,
127
141
"TS2339: Property 'firstName' does not exist on type 'User'." ,
128
142
' 25 | const user: User = this.user;' ,
129
- ' 26 | ' ,
143
+ ' 26 |' ,
130
144
" > 27 | return user ? `${user.firstName} ${user.lastName}` : '';" ,
131
145
' | ^^^^^^^^^' ,
132
146
' 28 | }' ,
@@ -136,7 +150,7 @@ describe('TypeScript Vue Extension', () => {
136
150
[
137
151
'ERROR in src/model/User.ts:11:16' ,
138
152
"TS2339: Property 'firstName' does not exist on type 'User'." ,
139
- ' 9 | ' ,
153
+ ' 9 |' ,
140
154
' 10 | function getUserName(user: User): string {' ,
141
155
' > 11 | return [user.firstName, user.lastName]' ,
142
156
' | ^^^^^^^^^' ,
@@ -145,6 +159,62 @@ describe('TypeScript Vue Extension', () => {
145
159
' 14 | }' ,
146
160
] . join ( '\n' ) ,
147
161
] ) ;
162
+
163
+ // fix the error
164
+ await sandbox . patch (
165
+ 'src/model/User.ts' ,
166
+ ' lastName?: string;' ,
167
+ [ ' firstName?: string;' , ' lastName?: string;' ] . join ( '\n' )
168
+ ) ;
169
+ await driver . waitForNoErrors ( ) ;
170
+
171
+ if ( semver . satisfies ( '3.0.0' , vue ) ) {
172
+ await sandbox . patch (
173
+ 'src/component/Header.vue' ,
174
+ 'defineProps({' ,
175
+ [ 'let x: number = "1"' , 'defineProps({' ] . join ( '\n' )
176
+ ) ;
177
+
178
+ errors = await driver . waitForErrors ( ) ;
179
+ expect ( errors ) . toEqual ( [
180
+ [
181
+ 'ERROR in src/component/Header.vue:6:5' ,
182
+ "TS2322: Type '\"1\"' is not assignable to type 'number'." ,
183
+ ' 4 |' ,
184
+ ' 5 | <script setup lang="ts">' ,
185
+ ' > 6 | let x: number = "1"' ,
186
+ ' | ^' ,
187
+ ' 7 | defineProps({' ,
188
+ ' 8 | title: String,' ,
189
+ ' 9 | });' ,
190
+ ] . join ( '\n' ) ,
191
+ ] ) ;
192
+ // fix the issue
193
+ await sandbox . patch ( 'src/component/Header.vue' , 'let x: number = "1"' , '' ) ;
194
+ await driver . waitForNoErrors ( ) ;
195
+
196
+ // introduce error in second <script>
197
+ await sandbox . patch (
198
+ 'src/component/Logo.vue' ,
199
+ 'export default {' ,
200
+ [ 'let x: number = "1";' , 'export default {' ] . join ( '\n' )
201
+ ) ;
202
+
203
+ errors = await driver . waitForErrors ( ) ;
204
+ expect ( errors ) . toEqual ( [
205
+ [
206
+ 'ERROR in src/component/Logo.vue:15:5' ,
207
+ "TS2322: Type '\"1\"' is not assignable to type 'number'." ,
208
+ ' 13 |' ,
209
+ ' 14 | <script lang="ts">' ,
210
+ ' > 15 | let x: number = "1";' ,
211
+ ' | ^' ,
212
+ ' 16 | export default {' ,
213
+ ' 17 | inheritAttrs: false,' ,
214
+ ' 18 | customOptions: {}' ,
215
+ ] . join ( '\n' ) ,
216
+ ] ) ;
217
+ }
148
218
}
149
219
) ;
150
220
} ) ;
0 commit comments