1
+ import fs from 'node:fs'
1
2
import path from 'node:path'
2
3
import { fileURLToPath } from 'node:url'
3
4
@@ -13,7 +14,23 @@ function runLintAgainst(projectName: string) {
13
14
const projectDir = path . join ( __dirname , '../examples' , projectName )
14
15
// Use `pnpm` to avoid locating each `eslint` bin ourselves.
15
16
// Use `--silent` to only print the output of the command, stripping the pnpm log.
16
- return execa ( { preferLocal : true , cwd : projectDir } ) `pnpm --silent lint`
17
+ return execa ( { preferLocal : true , cwd : projectDir , reject : false } ) `pnpm --silent lint`
18
+ }
19
+
20
+ function setupFileMutations ( filename : string ) {
21
+ // Read the file
22
+ const fileContents = fs . readFileSync ( filename , 'utf8' )
23
+
24
+ // Implementation for modifying and restoring the file
25
+ function modify ( getNewContents : ( oldContents : string ) => string ) {
26
+ fs . writeFileSync ( filename , getNewContents ( fileContents ) )
27
+ }
28
+
29
+ function restore ( ) {
30
+ fs . writeFileSync ( filename , fileContents )
31
+ }
32
+
33
+ return { modify, restore }
17
34
}
18
35
19
36
describe ( 'should pass lint without error in new projects' , ( ) => {
@@ -37,29 +54,41 @@ describe('should pass lint without error in new projects', () => {
37
54
}
38
55
} )
39
56
40
- describe . todo (
41
- 'should report error on recommended rule violations in .vue files' ,
42
- ( ) => {
43
- test . todo ( 'minimal' , ( ) => { } )
44
- test . todo ( 'allow-js' , ( ) => { } )
45
- // TODO:
46
- // ts-eslint disabled a few rules in eslint-recommended because tsc would catch them anyway.
47
- // Shall we check that if `vue-tsc` would catch these issues in plain `script` blocks?
48
-
49
- test . todo ( 'with-tsx' , ( ) => { } )
50
- test . todo ( 'with-tsx-in-vue' , ( ) => { } )
51
- test . todo ( 'with-jsx' , ( ) => { } )
52
- test . todo ( 'with-jsx-in-vue' , ( ) => { } )
53
-
54
- test . todo ( 'with-prettier' , ( ) => { } )
57
+ describe ( 'should report error on recommended rule violations in .vue files' , ( ) => {
58
+ for ( const projectName of [
59
+ 'minimal' ,
60
+ 'allow-js' ,
61
+ 'with-tsx' ,
62
+ 'with-tsx-in-vue' ,
63
+ 'with-jsx' ,
64
+ 'with-jsx-in-vue' ,
65
+ 'with-prettier' ,
66
+ 'with-cypress' ,
67
+ 'with-nightwatch' ,
68
+ 'with-playwright' ,
69
+ 'with-vitest' ,
70
+ ] ) {
71
+ test ( projectName , async ( ) => {
72
+ const appVuePath = path . join (
73
+ __dirname ,
74
+ '../examples' ,
75
+ projectName ,
76
+ 'src/App.vue' ,
77
+ )
78
+ const { modify, restore } = setupFileMutations ( appVuePath )
79
+
80
+ modify ( oldContents =>
81
+ oldContents . replace ( '</script>' , '// @ts-ignore\n</script>' ) ,
82
+ )
55
83
56
- test . todo ( 'with-cypress' , ( ) => { } )
57
- test . todo ( 'with-nightwatch' , ( ) => { } )
58
- test . todo ( 'with-playwright' , ( ) => { } )
84
+ const { failed, stdout } = await runLintAgainst ( projectName )
85
+ restore ( )
59
86
60
- test . todo ( 'with-vitest' , ( ) => { } )
61
- } ,
62
- )
87
+ expect ( failed ) . toBe ( true )
88
+ expect ( stdout ) . toContain ( ' @typescript-eslint/ban-ts-comment' )
89
+ } )
90
+ }
91
+ } )
63
92
64
93
describe . todo (
65
94
'should report error on recommended rule violations in other script files' ,
0 commit comments