Skip to content

Commit 4d06407

Browse files
committed
test: finish tests
1 parent 86f1cc3 commit 4d06407

File tree

1 file changed

+92
-24
lines changed

1 file changed

+92
-24
lines changed

Diff for: test/index.spec.ts

+92-24
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ function runLintAgainst(projectName: string) {
1414
const projectDir = path.join(__dirname, '../examples', projectName)
1515
// Use `pnpm` to avoid locating each `eslint` bin ourselves.
1616
// 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`
1822
}
1923

2024
function setupFileMutations(filename: string) {
@@ -55,6 +59,9 @@ describe('should pass lint without error in new projects', () => {
5559
})
5660

5761
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+
}
5865
for (const projectName of [
5966
'minimal',
6067
'allow-js',
@@ -68,45 +75,106 @@ describe('should report error on recommended rule violations in .vue files', ()
6875
'with-playwright',
6976
'with-vitest',
7077
]) {
71-
test(projectName, async () => {
78+
test(`src/App.vue in ${projectName}`, async () => {
7279
const appVuePath = path.join(
7380
__dirname,
7481
'../examples',
7582
projectName,
7683
'src/App.vue',
7784
)
78-
const { modify, restore } = setupFileMutations(appVuePath)
79-
80-
modify(oldContents =>
81-
oldContents.replace('</script>', '// @ts-ignore\n</script>'),
82-
)
8385

86+
const { modify, restore } = setupFileMutations(appVuePath)
87+
modify(appendBannedTsCommentToVueScript)
8488
const { failed, stdout } = await runLintAgainst(projectName)
8589
restore()
8690

8791
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')
8994
})
9095
}
9196
})
9297

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+
}
98102

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+
)
103123

104-
test.todo('with-prettier', () => {})
124+
const { modify, restore } = setupFileMutations(mainTsPath)
125+
modify(appendBannedTsComment)
126+
const { failed, stdout } = await runLintAgainst(projectName)
127+
restore()
105128

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+
}
109149

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

Comments
 (0)