Skip to content

Commit e3fb7fe

Browse files
committed
test: add tests for rule violations in .vue files
1 parent d8d2d73 commit e3fb7fe

File tree

1 file changed

+51
-22
lines changed

1 file changed

+51
-22
lines changed

test/index.spec.ts

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from 'node:fs'
12
import path from 'node:path'
23
import { fileURLToPath } from 'node:url'
34

@@ -13,7 +14,23 @@ function runLintAgainst(projectName: string) {
1314
const projectDir = path.join(__dirname, '../examples', projectName)
1415
// Use `pnpm` to avoid locating each `eslint` bin ourselves.
1516
// 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 }
1734
}
1835

1936
describe('should pass lint without error in new projects', () => {
@@ -37,29 +54,41 @@ describe('should pass lint without error in new projects', () => {
3754
}
3855
})
3956

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

56-
test.todo('with-cypress', () => {})
57-
test.todo('with-nightwatch', () => {})
58-
test.todo('with-playwright', () => {})
84+
const { failed, stdout } = await runLintAgainst(projectName)
85+
restore()
5986

60-
test.todo('with-vitest', () => {})
61-
},
62-
)
87+
expect(failed).toBe(true)
88+
expect(stdout).toContain(' @typescript-eslint/ban-ts-comment')
89+
})
90+
}
91+
})
6392

6493
describe.todo(
6594
'should report error on recommended rule violations in other script files',

0 commit comments

Comments
 (0)