@@ -14,7 +14,11 @@ function runLintAgainst(projectName: string) {
14
14
const projectDir = path . join ( __dirname , '../examples' , projectName )
15
15
// Use `pnpm` to avoid locating each `eslint` bin ourselves.
16
16
// Use `--silent` to only print the output of the command, stripping the pnpm log.
17
- return execa ( { preferLocal : true , cwd : projectDir , reject : false } ) `pnpm --silent lint`
17
+ return execa ( {
18
+ preferLocal : true ,
19
+ cwd : projectDir ,
20
+ reject : false ,
21
+ } ) `pnpm --silent lint`
18
22
}
19
23
20
24
function setupFileMutations ( filename : string ) {
@@ -55,6 +59,9 @@ describe('should pass lint without error in new projects', () => {
55
59
} )
56
60
57
61
describe ( 'should report error on recommended rule violations in .vue files' , ( ) => {
62
+ function appendBannedTsCommentToVueScript ( oldContents : string ) {
63
+ return oldContents . replace ( '</script>' , '// @ts-ignore\n</script>' )
64
+ }
58
65
for ( const projectName of [
59
66
'minimal' ,
60
67
'allow-js' ,
@@ -68,45 +75,106 @@ describe('should report error on recommended rule violations in .vue files', ()
68
75
'with-playwright' ,
69
76
'with-vitest' ,
70
77
] ) {
71
- test ( projectName , async ( ) => {
78
+ test ( `src/App.vue in ${ projectName } ` , async ( ) => {
72
79
const appVuePath = path . join (
73
80
__dirname ,
74
81
'../examples' ,
75
82
projectName ,
76
83
'src/App.vue' ,
77
84
)
78
- const { modify, restore } = setupFileMutations ( appVuePath )
79
-
80
- modify ( oldContents =>
81
- oldContents . replace ( '</script>' , '// @ts-ignore\n</script>' ) ,
82
- )
83
85
86
+ const { modify, restore } = setupFileMutations ( appVuePath )
87
+ modify ( appendBannedTsCommentToVueScript )
84
88
const { failed, stdout } = await runLintAgainst ( projectName )
85
89
restore ( )
86
90
87
91
expect ( failed ) . toBe ( true )
88
- expect ( stdout ) . toContain ( ' @typescript-eslint/ban-ts-comment' )
92
+ expect ( stdout ) . toContain ( 'src/App.vue' )
93
+ expect ( stdout ) . toContain ( '@typescript-eslint/ban-ts-comment' )
89
94
} )
90
95
}
91
96
} )
92
97
93
- describe . todo (
94
- 'should report error on recommended rule violations in other script files' ,
95
- ( ) => {
96
- test . todo ( 'minimal' , ( ) => { } )
97
- test . todo ( 'allow-js' , ( ) => { } )
98
+ describe ( 'should report error on recommended rule violations in other script files' , ( ) => {
99
+ function appendBannedTsComment ( oldContents : string ) {
100
+ return oldContents + '\n// @ts-ignore\n'
101
+ }
98
102
99
- test . todo ( 'with-tsx' , ( ) => { } )
100
- test . todo ( 'with-tsx-in-vue' , ( ) => { } )
101
- test . todo ( 'with-jsx' , ( ) => { } )
102
- test . todo ( 'with-jsx-in-vue' , ( ) => { } )
103
+ for ( const projectName of [
104
+ 'minimal' ,
105
+ 'allow-js' ,
106
+ 'with-tsx' ,
107
+ 'with-tsx-in-vue' ,
108
+ 'with-jsx' ,
109
+ 'with-jsx-in-vue' ,
110
+ 'with-prettier' ,
111
+ 'with-cypress' ,
112
+ 'with-nightwatch' ,
113
+ 'with-playwright' ,
114
+ 'with-vitest' ,
115
+ ] ) {
116
+ test ( `main.ts in ${ projectName } ` , async ( ) => {
117
+ const mainTsPath = path . join (
118
+ __dirname ,
119
+ '../examples' ,
120
+ projectName ,
121
+ 'src/main.ts' ,
122
+ )
103
123
104
- test . todo ( 'with-prettier' , ( ) => { } )
124
+ const { modify, restore } = setupFileMutations ( mainTsPath )
125
+ modify ( appendBannedTsComment )
126
+ const { failed, stdout } = await runLintAgainst ( projectName )
127
+ restore ( )
105
128
106
- test . todo ( 'with-cypress' , ( ) => { } )
107
- test . todo ( 'with-nightwatch' , ( ) => { } )
108
- test . todo ( 'with-playwright' , ( ) => { } )
129
+ expect ( failed ) . toBe ( true )
130
+ expect ( stdout ) . toContain ( 'main.ts' )
131
+ expect ( stdout ) . toContain ( ' @typescript-eslint/ban-ts-comment' )
132
+ } )
133
+ }
134
+
135
+ function appendThisAlias ( oldContents : string ) {
136
+ return (
137
+ oldContents +
138
+ `
139
+ class Example {
140
+ method() {
141
+ const that = this;
142
+ console.log(that.method)
143
+ }
144
+ }
145
+ new Example()
146
+ `
147
+ )
148
+ }
109
149
110
- test . todo ( 'with-vitest' , ( ) => { } )
111
- } ,
112
- )
150
+ test ( '.js in allow-js' , async ( ) => {
151
+ const jsPath = path . join ( __dirname , '../examples/allow-js/src/foo.js' )
152
+ const { modify, restore } = setupFileMutations ( jsPath )
153
+ modify ( appendThisAlias )
154
+ const { failed, stdout } = await runLintAgainst ( 'allow-js' )
155
+ restore ( )
156
+
157
+ expect ( failed ) . toBe ( true )
158
+ expect ( stdout ) . toContain ( '@typescript-eslint/no-this-alias' )
159
+ } )
160
+ test ( '.tsx in with-tsx' , async ( ) => {
161
+ const tsxPath = path . join ( __dirname , '../examples/with-tsx/src/FooComp.tsx' )
162
+ const { modify, restore } = setupFileMutations ( tsxPath )
163
+ modify ( appendThisAlias )
164
+ const { failed, stdout } = await runLintAgainst ( 'with-tsx' )
165
+ restore ( )
166
+
167
+ expect ( failed ) . toBe ( true )
168
+ expect ( stdout ) . toContain ( '@typescript-eslint/no-this-alias' )
169
+ } )
170
+ test ( '.jsx in with-jsx' , async ( ) => {
171
+ const jsxPath = path . join ( __dirname , '../examples/with-jsx/src/FooComp.jsx' )
172
+ const { modify, restore } = setupFileMutations ( jsxPath )
173
+ modify ( appendThisAlias )
174
+ const { failed, stdout } = await runLintAgainst ( 'with-jsx' )
175
+ restore ( )
176
+
177
+ expect ( failed ) . toBe ( true )
178
+ expect ( stdout ) . toContain ( '@typescript-eslint/no-this-alias' )
179
+ } )
180
+ } )
0 commit comments