Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 89 additions & 1 deletion docs/rules/no-skipped-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ test.describe('skip test inside describe', () => {
test.describe('skip test conditionally', async ({ browserName }) => {
test.skip(browserName === 'firefox', 'Working on it')
})

test('skip using testInfo', async ({ page }, testInfo) => {
testInfo.skip()
})
```

With the `disallowFixme` option enabled, the following are also incorrect:
Expand All @@ -29,6 +33,10 @@ test.fixme('temporarily disabled', async ({ page }) => {})
test.fixme() // marks all tests in the file as fixme

test.describe.fixme('skip this describe', () => {})

test('fixme using testInfo', async ({ page }, testInfo) => {
testInfo.fixme()
})
```

Examples of **correct** code for this rule:
Expand Down Expand Up @@ -85,7 +93,87 @@ test('foo', ({ browserName }) => {
})
```

`allowConditional` can also be an object to configure the `skip` and `fixme`
annotations separately, which is useful if you rely on conditional skips but
never want to allow `.fixme()`:

```json
{
"playwright/no-skipped-test": [
"error",
{
"allowConditional": { "fixme": false, "skip": true },
"disallowFixme": true
}
]
}
```

Examples of **incorrect** code for the
`{ "allowConditional": { "skip": true }, "disallowFixme": true }` option:

```javascript
test('foo', ({ isMobile }) => {
test.fixme(isMobile, 'Not ready for mobile yet')
expect(1).toBe(1)
})
```

Example of **correct** code for the same option:

```javascript
test('foo', ({ browserName }) => {
test.skip(browserName === 'firefox', 'Still working on it')
expect(1).toBe(1)
})
```

The inverse is just as common, and is arguably the more useful of the two: a
team that treats `.fixme()` as documentation for a known, ticketed bug wants
conditional `.fixme()` allowed while still catching an unconditional skip that
someone left behind.

```json
{
"playwright/no-skipped-test": [
"error",
{
"allowConditional": { "fixme": true, "skip": false },
"disallowFixme": true
}
]
}
```

Example of **correct** code for that option:

```javascript
test('foo', ({ isMobile }) => {
test.fixme(isMobile, 'ref WET-204 — layout breaks below 768px')
expect(1).toBe(1)
})
```

Examples of **incorrect** code for the same option:

```javascript
// Unconditional — nothing says when this comes back
test.fixme('foo', ({}) => {
expect(1).toBe(1)
})

test('bar', ({ browserName }) => {
test.skip(browserName === 'firefox', 'Still working on it')
expect(1).toBe(1)
})
```

Passing a boolean is equivalent to setting both keys to that value, so
`{ "allowConditional": true }` is the same as
`{ "allowConditional": { "fixme": true, "skip": true } }`.

### `disallowFixme`

Setting this option to `true` will also disallow the `.fixme()` annotation
(`test.fixme()`, `test.describe.fixme()`, etc.). Default is `false`.
(`test.fixme()`, `test.describe.fixme()`, `testInfo.fixme()`, etc.). Default is
`false`.
132 changes: 132 additions & 0 deletions src/rules/no-skipped-test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,121 @@ runRuleTester('no-skipped-test', rule, {
],
options: [{ disallowFixme: true }],
},
// Conditional fixme can be disallowed while conditional skip is allowed
{
code: 'test("foo", ({ isMobile }) => { test.fixme(isMobile, "Not ready") })',
errors: [
{
column: 33,
data: { annotation: 'fixme' },
endColumn: 66,
line: 1,
messageId: 'noSkippedTest',
suggestions: [
{
data: { annotation: 'fixme' },
messageId: 'removeAnnotation',
output: 'test("foo", ({ isMobile }) => { })',
},
],
},
],
options: [{ allowConditional: { skip: true }, disallowFixme: true }],
},
// testInfo annotations
{
code: dedent`
test("foo", async ({ page }, testInfo) => {
testInfo.skip();
});
`,
errors: [
{
column: 3,
data: { annotation: 'skip' },
endColumn: 18,
line: 2,
messageId: 'noSkippedTest',
suggestions: [
{
data: { annotation: 'skip' },
messageId: 'removeAnnotation',
output: 'test("foo", async ({ page }, testInfo) => {\n \n});',
},
],
},
],
},
{
code: dedent`
test("foo", async ({ page }, testInfo) => {
testInfo.skip(isMobile, "Not ready");
});
`,
errors: [
{
column: 3,
data: { annotation: 'skip' },
endColumn: 39,
line: 2,
messageId: 'noSkippedTest',
suggestions: [
{
data: { annotation: 'skip' },
messageId: 'removeAnnotation',
output: 'test("foo", async ({ page }, testInfo) => {\n \n});',
},
],
},
],
},
{
code: dedent`
test("foo", async ({ page }, testInfo) => {
testInfo.fixme(isMobile, "Not ready");
});
`,
errors: [
{
column: 3,
data: { annotation: 'fixme' },
endColumn: 40,
line: 2,
messageId: 'noSkippedTest',
suggestions: [
{
data: { annotation: 'fixme' },
messageId: 'removeAnnotation',
output: 'test("foo", async ({ page }, testInfo) => {\n \n});',
},
],
},
],
options: [{ allowConditional: { skip: true }, disallowFixme: true }],
},
{
code: dedent`
test.beforeEach(async ({ page }, testInfo) => {
testInfo["skip"]();
});
`,
errors: [
{
column: 3,
data: { annotation: 'skip' },
endColumn: 21,
line: 2,
messageId: 'noSkippedTest',
suggestions: [
{
data: { annotation: 'skip' },
messageId: 'removeAnnotation',
output: 'test.beforeEach(async ({ page }, testInfo) => {\n \n});',
},
],
},
],
},
],
valid: [
'test("a test", () => {});',
Expand Down Expand Up @@ -606,6 +721,23 @@ runRuleTester('no-skipped-test', rule, {
`,
options: [{ allowConditional: true }],
},
{
code: 'test("foo", ({ browserName }) => { test.skip(browserName === "firefox", "Still working on it") })',
options: [{ allowConditional: { skip: true } }],
},
{
code: 'test("foo", ({ isMobile }) => { test.fixme(isMobile, "Not ready") })',
options: [{ allowConditional: { fixme: true, skip: true }, disallowFixme: true }],
},
// testInfo annotations
'test("foo", async ({ page }, testInfo) => { testInfo.slow(); });',
'test("foo", async ({ page }, testInfo) => { testInfo.fixme(); });',
'test("foo", async (fixtures) => { fixtures.skip(); });',
'notATest(async ({ page }, testInfo) => { testInfo.skip(); });',
{
code: 'test("foo", async ({ page }, testInfo) => { testInfo.skip(isMobile, "Not ready"); });',
options: [{ allowConditional: true }],
},
// Global aliases
{
code: 'it("a test", () => {});',
Expand Down
Loading