Skip to content

Commit 8ac9b78

Browse files
committed
chore: ban expect.assertions in fixture tests (#8387)
To catch #8383
1 parent 252cd42 commit 8ac9b78

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

.oxlintrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"$schema": "./node_modules/oxlint/configuration_schema.json",
33
"plugins": ["import", "jsdoc", "unicorn", "typescript", "oxc"],
4+
"jsPlugins": ["./scripts/lint/index.ts"],
45
"ignorePatterns": [
56
"crates/**",
67
"packages/rollup-tests/**",
@@ -68,6 +69,12 @@
6869
}
6970
]
7071
}
72+
},
73+
{
74+
"files": ["**/packages/rolldown/tests/fixtures/context/default-value/_config.ts"],
75+
"rules": {
76+
"rolldown-custom/ban-expect-assertions": "error"
77+
}
7178
}
7279
]
7380
}

knip.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"entry": ["**/*.{test,spec}.{js,ts}"],
8989
},
9090
"scripts": {
91-
"entry": ["misc/**"],
91+
"entry": ["misc/**", "lint/index.ts"],
9292
},
9393
"packages/test-dev-server/tests/fixtures/*": {
9494
"entry": ["dev.config.mjs", "src/*.js"], // no @rolldown/test-dev-server plugin

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/lint/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { eslintCompatPlugin, type CreateOnceRule, type VisitorWithHooks } from '@oxlint/plugins';
2+
3+
const banExpectAssertionsRule: CreateOnceRule = {
4+
createOnce(context) {
5+
return {
6+
CallExpression(node) {
7+
if (
8+
node.callee.type === 'MemberExpression' &&
9+
node.callee.object.type === 'Identifier' &&
10+
node.callee.object.name === 'expect' &&
11+
node.callee.property.type === 'Identifier' &&
12+
node.callee.property.name === 'assertions'
13+
) {
14+
context.report({
15+
message:
16+
'Fixture tests run concurrently and `expect.assertions` does not work with global expect. Use `vi.fn()` instead.',
17+
node,
18+
});
19+
}
20+
},
21+
} as VisitorWithHooks;
22+
},
23+
};
24+
25+
export default eslintCompatPlugin({
26+
meta: {
27+
name: 'rolldown-custom',
28+
},
29+
rules: {
30+
'ban-expect-assertions': banExpectAssertionsRule,
31+
},
32+
});

scripts/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"devDependencies": {
2828
"@oxc-node/cli": "catalog:",
29+
"@oxlint/plugins": "^1.48.0",
2930
"acorn": "catalog:",
3031
"astring": "catalog:",
3132
"diff": "catalog:",

0 commit comments

Comments
 (0)