Skip to content

Commit 34b3f7b

Browse files
authoredOct 22, 2023
feat: Add allowConditional option to no-skipped-test (#174)
1 parent 2927305 commit 34b3f7b

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
 

‎docs/rules/no-skipped-test.md

+28
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,31 @@ test.describe('two tests', () => {
3131
test('two', async ({ page }) => {});
3232
});
3333
```
34+
35+
## Options
36+
37+
```json
38+
{
39+
"playwright/no-skipped-test": [
40+
"error",
41+
{
42+
"allowConditional": false
43+
}
44+
]
45+
}
46+
```
47+
48+
### `allowConditional`
49+
50+
Setting this option to `true` will allow using `test.skip()` to
51+
[conditionally skip a test](https://playwright.dev/docs/test-annotations#conditionally-skip-a-test).
52+
This can be helpful if you want to prevent usage of `test.skip` being added by
53+
mistake but still allow conditional tests based on browser/environment setup.
54+
55+
Example of **correct** code for the `{ "allowConditional": true }` option:
56+
57+
```javascript
58+
test('foo', ({ browserName }) => {
59+
test.skip(browserName === 'firefox', 'Still working on it');
60+
});
61+
```

‎src/rules/no-skipped-test.ts

+20
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export default {
1010
create(context) {
1111
return {
1212
CallExpression(node) {
13+
const options = context.options[0] || {};
14+
const allowConditional = !!options.allowConditional;
1315
const { callee } = node;
1416

1517
if (
@@ -19,6 +21,12 @@ export default {
1921
) {
2022
const isHook = isTest(node) || isDescribeCall(node);
2123

24+
// If allowConditional is enabled and it's not a test/describe hook,
25+
// we ignore any `test.skip` calls that have no arguments.
26+
if (!isHook && allowConditional && node.arguments.length) {
27+
return;
28+
}
29+
2230
context.report({
2331
messageId: 'noSkippedTest',
2432
node: isHook ? callee.property : node,
@@ -52,6 +60,18 @@ export default {
5260
noSkippedTest: 'Unexpected use of the `.skip()` annotation.',
5361
removeSkippedTestAnnotation: 'Remove the `.skip()` annotation.',
5462
},
63+
schema: [
64+
{
65+
additionalProperties: false,
66+
properties: {
67+
allowConditional: {
68+
default: false,
69+
type: 'boolean',
70+
},
71+
},
72+
type: 'object',
73+
},
74+
],
5575
type: 'suggestion',
5676
},
5777
} as Rule.RuleModule;

‎test/spec/no-skipped-test.spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -201,5 +201,9 @@ runRuleTester('no-skipped-test', rule, {
201201
'this.skip();',
202202
'this["skip"]();',
203203
'this[`skip`]();',
204+
{
205+
code: 'test.skip(browserName === "firefox", "Still working on it");',
206+
options: [{ allowConditional: true }],
207+
},
204208
],
205209
});

0 commit comments

Comments
 (0)
Please sign in to comment.