Skip to content

Commit f4cd7b6

Browse files
committed
feat(test): support cypress rules
(cherry picked from commit b0500a0)
1 parent 501bb77 commit f4cd7b6

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"astro-eslint-parser": "^1.0.2",
4848
"eslint": "^9.5.0",
4949
"eslint-plugin-astro": "^1.2.0",
50+
"eslint-plugin-cypress": "^3.5.0",
5051
"eslint-plugin-format": ">=0.1.0",
5152
"eslint-plugin-react-hooks": "^4.6.0",
5253
"eslint-plugin-react-refresh": "^0.4.4",
@@ -72,6 +73,9 @@
7273
"eslint-plugin-astro": {
7374
"optional": true
7475
},
76+
"eslint-plugin-cypress": {
77+
"optional": true
78+
},
7579
"eslint-plugin-format": {
7680
"optional": true
7781
},
@@ -152,6 +156,7 @@
152156
"bumpp": "^9.5.2",
153157
"eslint": "^9.9.1",
154158
"eslint-plugin-astro": "^1.2.3",
159+
"eslint-plugin-cypress": "^3.5.0",
155160
"eslint-plugin-format": "^0.1.2",
156161
"eslint-plugin-react-hooks": "^4.6.2",
157162
"eslint-plugin-react-refresh": "^0.4.11",

pnpm-lock.yaml

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/configs/test.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { interopDefault } from '../utils'
1+
import { isPackageExists } from 'local-pkg'
2+
import { ensurePackages, interopDefault } from '../utils'
23
import type { OptionsFiles, OptionsIsInEditor, OptionsOverrides, TypedFlatConfigItem } from '../types'
3-
import { GLOB_TESTS } from '../globs'
4+
import { GLOB_CYPRESS, GLOB_TESTS } from '../globs'
45

56
// Hold the reference so we don't redeclare the plugin on each call
67
let _pluginTest: any
@@ -14,13 +15,21 @@ export async function test(
1415
overrides = {},
1516
} = options
1617

18+
const enableCypress = isPackageExists('cypress')
19+
if (enableCypress) {
20+
await ensurePackages(['eslint-plugin-cypress'])
21+
}
22+
1723
const [
1824
pluginVitest,
1925
pluginNoOnlyTests,
26+
pluginCypress,
2027
] = await Promise.all([
2128
interopDefault(import('@vitest/eslint-plugin')),
2229
// @ts-expect-error missing types
2330
interopDefault(import('eslint-plugin-no-only-tests')),
31+
// @ts-expect-error missing types
32+
enableCypress ? interopDefault(import('eslint-plugin-cypress/flat')) : null,
2433
] as const)
2534

2635
_pluginTest = _pluginTest || {
@@ -57,5 +66,12 @@ export async function test(
5766
...overrides,
5867
},
5968
},
69+
...(pluginCypress
70+
? [{
71+
files: GLOB_CYPRESS,
72+
...pluginCypress.configs.recommended,
73+
name: 'mutoe/test/cypress-rules',
74+
}]
75+
: []),
6076
]
6177
}

src/globs.ts

+6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@ export const GLOB_GRAPHQL = '**/*.{g,graph}ql'
3232

3333
export const GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`
3434

35+
export const GLOB_CYPRESS = [
36+
`**/*.cy.${GLOB_SRC_EXT}`,
37+
`**/cypress/**/*.${GLOB_SRC_EXT}`,
38+
]
39+
3540
export const GLOB_TESTS = [
3641
`**/__tests__/**/*.${GLOB_SRC_EXT}`,
3742
`**/*.spec.${GLOB_SRC_EXT}`,
3843
`**/*.test.${GLOB_SRC_EXT}`,
3944
`**/*.bench.${GLOB_SRC_EXT}`,
4045
`**/*.benchmark.${GLOB_SRC_EXT}`,
46+
...GLOB_CYPRESS,
4147
]
4248

4349
export const GLOB_ALL_SRC = [

0 commit comments

Comments
 (0)