-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core(lint): Add custom
no-focused-tests
and no-skipped-tests
rules (
#13461) Adds two simple custom rules to ignore `(it|test|describe).(skip|only)`. These rules now also flag vitest-based `skip` and `only` functions but led to duplications with the two rules from `eslint-plugin-jest`. So this patch also disables the jest versions in favour of the custom rules. To be clear, the custom rules are likely a bit less robust than the jest/vitest version but until we can use the actual vitest plugin, I think it's fine to stay with our custom version.
- Loading branch information
Showing
6 changed files
with
71 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
/** | ||
* This rule was created to flag usages of the `.only` function in vitest and jest tests. | ||
* Usually, we don't want to commit focused tests as this causes other tests to be skipped. | ||
*/ | ||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: "Do not focus tests via `.only` to ensure we don't commit accidentally skip the other tests.", | ||
}, | ||
schema: [], | ||
}, | ||
create: function (context) { | ||
return { | ||
CallExpression(node) { | ||
if ( | ||
node.callee.type === 'MemberExpression' && | ||
node.callee.object.type === 'Identifier' && | ||
['test', 'it', 'describe'].includes(node.callee.object.name) && | ||
node.callee.property.type === 'Identifier' && | ||
node.callee.property.name === 'only' | ||
) { | ||
context.report({ | ||
node, | ||
message: "Do not focus tests via `.only` to ensure we don't commit accidentally skip the other tests.", | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
/** | ||
* This rule was created to flag usages of the `.skip` function in vitest and jest tests. | ||
* Usually, we don't want to commit skipped tests as this causes other tests to be skipped. | ||
* Sometimes, skipping is valid (e.g. flaky tests), in which case, we can simply eslint-disable the rule. | ||
*/ | ||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: "Do not skip tests via `.skip` to ensure we don't commit accidentally skipped tests.", | ||
}, | ||
schema: [], | ||
}, | ||
create: function (context) { | ||
return { | ||
CallExpression(node) { | ||
if ( | ||
node.callee.type === 'MemberExpression' && | ||
node.callee.object.type === 'Identifier' && | ||
['test', 'it', 'describe'].includes(node.callee.object.name) && | ||
node.callee.property.type === 'Identifier' && | ||
node.callee.property.name === 'skip' | ||
) { | ||
context.report({ | ||
node, | ||
message: "Do not skip tests via `.skip` to ensure we don't commit accidentally skipped tests.", | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters