-
-
Notifications
You must be signed in to change notification settings - Fork 494
/
Copy pathfixtures.test.ts
161 lines (146 loc) · 3.1 KB
/
fixtures.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import type { OptionsConfig, TypedFlatConfigItem } from '../src/types'
import { join, resolve } from 'node:path'
import { execa } from 'execa'
import fg from 'fast-glob'
import fs from 'fs-extra'
import { afterAll, beforeAll, it } from 'vitest'
beforeAll(async () => {
await fs.rm('_fixtures', { recursive: true, force: true })
})
afterAll(async () => {
await fs.rm('_fixtures', { recursive: true, force: true })
})
runWithConfig('js', {
typescript: false,
vue: false,
})
runWithConfig('all', {
typescript: true,
vue: true,
svelte: true,
astro: true,
})
runWithConfig('no-style', {
typescript: true,
vue: true,
stylistic: false,
})
runWithConfig(
'tab-double-quotes',
{
typescript: true,
vue: true,
stylistic: {
indent: 'tab',
quotes: 'double',
},
},
{
rules: {
'style/no-mixed-spaces-and-tabs': 'off',
},
},
)
// https://github.com/antfu/eslint-config/issues/255
runWithConfig(
'ts-override',
{
typescript: true,
},
{
rules: {
'ts/consistent-type-definitions': ['error', 'type'],
},
},
)
// https://github.com/antfu/eslint-config/issues/255
runWithConfig(
'ts-strict',
{
typescript: {
tsconfigPath: './tsconfig.json',
},
},
{
rules: {
'ts/no-unsafe-return': ['off'],
},
},
)
// https://github.com/antfu/eslint-config/issues/618
runWithConfig(
'ts-strict-with-react',
{
typescript: {
tsconfigPath: './tsconfig.json',
},
react: true,
},
{
rules: {
'ts/no-unsafe-return': ['off'],
},
},
)
runWithConfig(
'with-formatters',
{
typescript: true,
vue: true,
astro: true,
formatters: true,
},
)
runWithConfig(
'no-markdown-with-formatters',
{
jsx: false,
vue: false,
markdown: false,
formatters: {
markdown: true,
},
},
)
function runWithConfig(name: string, configs: OptionsConfig, ...items: TypedFlatConfigItem[]) {
it.concurrent(name, async ({ expect }) => {
const from = resolve('fixtures/input')
const output = resolve('fixtures/output', name)
const target = resolve('_fixtures', name)
await fs.copy(from, target, {
filter: (src) => {
return !src.includes('node_modules')
},
})
await fs.writeFile(join(target, 'eslint.config.js'), `
// @eslint-disable
import antfu from '@antfu/eslint-config'
export default antfu(
${JSON.stringify(configs)},
...${JSON.stringify(items) ?? []},
)
`)
await execa('npx', ['eslint', '.', '--fix'], {
cwd: target,
stdio: 'pipe',
})
const files = await fg('**/*', {
ignore: [
'node_modules',
'eslint.config.js',
],
cwd: target,
})
await Promise.all(files.map(async (file) => {
const content = await fs.readFile(join(target, file), 'utf-8')
const source = await fs.readFile(join(from, file), 'utf-8')
const outputPath = join(output, file)
if (content === source) {
if (fs.existsSync(outputPath))
await fs.remove(outputPath)
return
}
await expect.soft(content).toMatchFileSnapshot(join(output, file))
}))
}, 30_000)
}