1
1
import { join } from 'path' ;
2
+ import process from 'process' ;
2
3
import { readFixture } from './sandbox/Fixture' ;
3
4
import { Sandbox , createSandbox } from './sandbox/Sandbox' ;
4
5
import {
8
9
} from './sandbox/WebpackDevServerDriver' ;
9
10
import { FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION } from './sandbox/Plugin' ;
10
11
12
+ const ignored = process . version . startsWith ( 'v10' ) ;
13
+
11
14
describe ( 'EsLint' , ( ) => {
12
15
let sandbox : Sandbox ;
13
16
@@ -24,17 +27,27 @@ describe('EsLint', () => {
24
27
} ) ;
25
28
26
29
it . each ( [
27
- { async : false , webpack : '4.0.0' , absolute : false } ,
28
- { async : true , webpack : '^4.0.0' , absolute : true } ,
29
- { async : false , webpack : '^5.0.0' , absolute : true } ,
30
- { async : true , webpack : '^5.0.0' , absolute : false } ,
31
- ] ) ( 'reports lint error for %p' , async ( { async, webpack, absolute } ) => {
30
+ { async : false , webpack : '4.0.0' , eslint : '^6.0.0' , absolute : false } ,
31
+ { async : true , webpack : '^4.0.0' , eslint : '^7.0.0' , absolute : true } ,
32
+ { async : false , webpack : '^5.0.0' , eslint : '^7.0.0' , absolute : true } ,
33
+ {
34
+ async : true ,
35
+ webpack : '^5.0.0' ,
36
+ eslint : '^8.0.0' ,
37
+ absolute : false ,
38
+ } ,
39
+ ] ) ( 'reports lint error for %p' , async ( { async, webpack, eslint, absolute } ) => {
40
+ if ( ignored ) {
41
+ console . warn ( 'Ignoring test - incompatible node version' ) ;
42
+ return ;
43
+ }
32
44
await sandbox . load ( [
33
45
await readFixture ( join ( __dirname , 'fixtures/environment/eslint-basic.fixture' ) , {
34
46
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION : JSON . stringify (
35
47
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION
36
48
) ,
37
49
TS_LOADER_VERSION : JSON . stringify ( '^5.0.0' ) ,
50
+ ESLINT_VERSION : JSON . stringify ( eslint ) ,
38
51
TYPESCRIPT_VERSION : JSON . stringify ( '~3.8.0' ) ,
39
52
WEBPACK_VERSION : JSON . stringify ( webpack ) ,
40
53
WEBPACK_CLI_VERSION : JSON . stringify ( WEBPACK_CLI_VERSION ) ,
@@ -61,7 +74,7 @@ describe('EsLint', () => {
61
74
'WARNING in src/authenticate.ts:14:34' ,
62
75
'@typescript-eslint/no-explicit-any: Unexpected any. Specify a different type.' ,
63
76
' 12 | }' ,
64
- ' 13 | ' ,
77
+ ' 13 |' ,
65
78
' > 14 | async function logout(): Promise<any> {' ,
66
79
' | ^^^' ,
67
80
' 15 | const response = await fetch(' ,
@@ -76,7 +89,7 @@ describe('EsLint', () => {
76
89
" > 31 | loginForm.addEventListener('submit', async event => {" ,
77
90
' | ^^^^^' ,
78
91
' 32 | const user = await login(email, password);' ,
79
- ' 33 | ' ,
92
+ ' 33 |' ,
80
93
" 34 | if (user.role === 'admin') {" ,
81
94
] . join ( '\n' ) ,
82
95
] ) ;
@@ -127,34 +140,39 @@ describe('EsLint', () => {
127
140
'WARNING in src/model/User.ts:11:5' ,
128
141
"@typescript-eslint/no-unused-vars: 'temporary' is defined but never used." ,
129
142
' 9 | }' ,
130
- ' 10 | ' ,
143
+ ' 10 |' ,
131
144
' > 11 | let temporary: any;' ,
132
145
' | ^^^^^^^^^^^^^^' ,
133
- ' 12 | ' ,
134
- ' 13 | ' ,
146
+ ' 12 |' ,
147
+ ' 13 |' ,
135
148
' 14 | function getUserName(user: User): string {' ,
136
149
] . join ( '\n' ) ,
137
150
[
138
151
'WARNING in src/model/User.ts:11:16' ,
139
152
'@typescript-eslint/no-explicit-any: Unexpected any. Specify a different type.' ,
140
153
' 9 | }' ,
141
- ' 10 | ' ,
154
+ ' 10 |' ,
142
155
' > 11 | let temporary: any;' ,
143
156
' | ^^^' ,
144
- ' 12 | ' ,
145
- ' 13 | ' ,
157
+ ' 12 |' ,
158
+ ' 13 |' ,
146
159
' 14 | function getUserName(user: User): string {' ,
147
160
] . join ( '\n' ) ,
148
161
] ) ;
149
162
} ) ;
150
163
151
164
it ( 'adds files dependencies to webpack' , async ( ) => {
165
+ if ( ignored ) {
166
+ console . warn ( 'Ignoring test - incompatible node version' ) ;
167
+ return ;
168
+ }
152
169
await sandbox . load ( [
153
170
await readFixture ( join ( __dirname , 'fixtures/environment/eslint-basic.fixture' ) , {
154
171
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION : JSON . stringify (
155
172
FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION
156
173
) ,
157
174
TS_LOADER_VERSION : JSON . stringify ( '^5.0.0' ) ,
175
+ ESLINT_VERSION : JSON . stringify ( '~6.8.0' ) ,
158
176
TYPESCRIPT_VERSION : JSON . stringify ( '~3.8.0' ) ,
159
177
WEBPACK_VERSION : JSON . stringify ( '^4.0.0' ) ,
160
178
WEBPACK_CLI_VERSION : JSON . stringify ( WEBPACK_CLI_VERSION ) ,
@@ -210,54 +228,65 @@ describe('EsLint', () => {
210
228
await driver . waitForNoErrors ( ) ;
211
229
} ) ;
212
230
213
- it ( 'fixes errors with `fix: true` option' , async ( ) => {
214
- await sandbox . load ( [
215
- await readFixture ( join ( __dirname , 'fixtures/environment/eslint-basic.fixture' ) , {
216
- FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION : JSON . stringify (
217
- FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION
218
- ) ,
219
- TS_LOADER_VERSION : JSON . stringify ( '^5.0.0' ) ,
220
- TYPESCRIPT_VERSION : JSON . stringify ( '~3.8.0' ) ,
221
- WEBPACK_VERSION : JSON . stringify ( '^4.0.0' ) ,
222
- WEBPACK_CLI_VERSION : JSON . stringify ( WEBPACK_CLI_VERSION ) ,
223
- WEBPACK_DEV_SERVER_VERSION : JSON . stringify ( WEBPACK_DEV_SERVER_VERSION ) ,
224
- ASYNC : JSON . stringify ( false ) ,
225
- } ) ,
226
- await readFixture ( join ( __dirname , 'fixtures/implementation/typescript-basic.fixture' ) ) ,
227
- ] ) ;
228
-
229
- // fix initial issues
230
- await sandbox . patch (
231
- 'src/authenticate.ts' ,
232
- 'async function logout(): Promise<any> {' ,
233
- 'async function logout(): Promise<unknown> {'
234
- ) ;
235
- await sandbox . patch (
236
- 'src/index.ts' ,
237
- "loginForm.addEventListener('submit', async event => {" ,
238
- "loginForm.addEventListener('submit', async () => {"
239
- ) ;
231
+ it . each ( [ { eslint : '^6.0.0' } , { eslint : '^7.0.0' } , { eslint : '^8.0.0' } ] ) (
232
+ 'fixes errors with `fix: true` option for %p' ,
233
+ async ( { eslint } ) => {
234
+ if ( ignored ) {
235
+ console . warn ( 'Ignoring test - incompatible node version' ) ;
236
+ return ;
237
+ }
238
+ await sandbox . load ( [
239
+ await readFixture ( join ( __dirname , 'fixtures/environment/eslint-basic.fixture' ) , {
240
+ FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION : JSON . stringify (
241
+ FORK_TS_CHECKER_WEBPACK_PLUGIN_VERSION
242
+ ) ,
243
+ TS_LOADER_VERSION : JSON . stringify ( '^5.0.0' ) ,
244
+ ESLINT_VERSION : JSON . stringify ( eslint ) ,
245
+ TYPESCRIPT_VERSION : JSON . stringify ( '~3.8.0' ) ,
246
+ WEBPACK_VERSION : JSON . stringify ( '^4.0.0' ) ,
247
+ WEBPACK_CLI_VERSION : JSON . stringify ( WEBPACK_CLI_VERSION ) ,
248
+ WEBPACK_DEV_SERVER_VERSION : JSON . stringify ( WEBPACK_DEV_SERVER_VERSION ) ,
249
+ ASYNC : JSON . stringify ( false ) ,
250
+ } ) ,
251
+ await readFixture ( join ( __dirname , 'fixtures/implementation/typescript-basic.fixture' ) ) ,
252
+ ] ) ;
253
+
254
+ // fix initial issues
255
+ await sandbox . patch (
256
+ 'src/authenticate.ts' ,
257
+ 'async function logout(): Promise<any> {' ,
258
+ 'async function logout(): Promise<unknown> {'
259
+ ) ;
260
+ await sandbox . patch (
261
+ 'src/index.ts' ,
262
+ "loginForm.addEventListener('submit', async event => {" ,
263
+ "loginForm.addEventListener('submit', async () => {"
264
+ ) ;
240
265
241
- // set fix option for the eslint
242
- await sandbox . write (
243
- 'fork-ts-checker.config.js' ,
244
- 'module.exports = { eslint: { enabled: true, options: { fix: true } } };'
245
- ) ;
266
+ // set fix option for the eslint
267
+ await sandbox . write (
268
+ 'fork-ts-checker.config.js' ,
269
+ 'module.exports = { eslint: { enabled: true, options: { fix: true } } };'
270
+ ) ;
246
271
247
- // add fixable issue
248
- await sandbox . patch (
249
- 'src/authenticate.ts' ,
250
- 'const response = await fetch(' ,
251
- 'let response = await fetch('
252
- ) ;
272
+ // add fixable issue
273
+ await sandbox . patch (
274
+ 'src/authenticate.ts' ,
275
+ 'const response = await fetch(' ,
276
+ 'let response = await fetch('
277
+ ) ;
253
278
254
- const driver = createWebpackDevServerDriver ( sandbox . spawn ( 'npm run webpack-dev-server' ) , false ) ;
279
+ const driver = createWebpackDevServerDriver (
280
+ sandbox . spawn ( 'npm run webpack-dev-server' ) ,
281
+ false
282
+ ) ;
255
283
256
- // it should be automatically fixed
257
- await driver . waitForNoErrors ( ) ;
284
+ // it should be automatically fixed
285
+ await driver . waitForNoErrors ( ) ;
258
286
259
- // check if issue has been fixed
260
- const content = await sandbox . read ( 'src/authenticate.ts' ) ;
261
- expect ( content ) . not . toContain ( 'let response = await fetch(' ) ;
262
- } ) ;
287
+ // check if issue has been fixed
288
+ const content = await sandbox . read ( 'src/authenticate.ts' ) ;
289
+ expect ( content ) . not . toContain ( 'let response = await fetch(' ) ;
290
+ }
291
+ ) ;
263
292
} ) ;
0 commit comments