-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
fixtures.test.ts
97 lines (93 loc) · 2.62 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
import path from 'node:path'
import { ESLint } from 'eslint'
const getCli = (lintCodeBlocks = false, fix?: boolean) =>
new ESLint({
fix,
ignore: false,
useEslintrc: false,
baseConfig: {
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
env: {
node: true,
},
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:unicorn/recommended',
'plugin:prettier/recommended',
'plugin:mdx/recommended',
],
settings: {
react: {
version: 'detect',
},
},
rules: {
'react/jsx-curly-brace-presence': 'error',
'react/jsx-sort-props': 'error',
'react/self-closing-comp': 'error',
},
overrides: lintCodeBlocks
? [
{
files: '**/*.{md,mdx}/**',
rules: {
'no-var': 'error',
'prefer-const': 'error',
'prettier/prettier': 'off',
},
},
{
files: '*.{md,mdx}',
settings: {
'mdx/code-blocks': true,
},
},
]
: [],
},
reportUnusedDisableDirectives: 'error',
})
describe('fixtures', () => {
it('should match all snapshots', async () => {
let results = await getCli().lintFiles([
'test/fixtures/*',
'test/fixtures/**/*{md,mdx}',
])
for (const { filePath, messages } of results) {
expect(messages).toMatchSnapshot(path.basename(filePath))
}
results = await getCli(false, true).lintFiles([
'test/fixtures/*',
'test/fixtures/**/*{md,mdx}',
])
for (const { filePath, source, output } of results) {
if (output != null && source !== output) {
// eslint-disable-next-line jest/no-conditional-expect
expect(output).toMatchSnapshot(path.basename(filePath))
}
}
})
describe('lint code blocks', () => {
it('should work as expected', async () => {
let results = await getCli(true).lintFiles(
'test/fixtures/**/code-blocks.{md,mdx}',
)
for (const { filePath, messages } of results) {
expect(messages).toMatchSnapshot(path.basename(filePath))
}
results = await getCli(true, true).lintFiles(
'test/fixtures/**/code-blocks.{md,mdx}',
)
for (const { filePath, source, output } of results) {
if (output != null && source !== output) {
// eslint-disable-next-line jest/no-conditional-expect
expect(output).toMatchSnapshot(path.basename(filePath))
}
}
})
})
})