Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: playwright-community/eslint-plugin-playwright
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.17.0
Choose a base ref
...
head repository: playwright-community/eslint-plugin-playwright
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.18.0
Choose a head ref
  • 5 commits
  • 9 files changed
  • 2 contributors

Commits on Oct 19, 2023

  1. build(deps-dev): bump @babel/traverse from 7.23.0 to 7.23.2 (#171)

    Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.23.0 to 7.23.2.
    - [Release notes](https://github.com/babel/babel/releases)
    - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
    - [Commits](https://github.com/babel/babel/commits/v7.23.2/packages/babel-traverse)
    
    ---
    updated-dependencies:
    - dependency-name: "@babel/traverse"
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Oct 19, 2023
    Copy the full SHA
    f5f5c2f View commit details

Commits on Oct 20, 2023

  1. Update README.md

    mskelton authored Oct 20, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ecc406a View commit details

Commits on Oct 22, 2023

  1. Copy the full SHA
    e11113e View commit details
  2. Copy the full SHA
    2927305 View commit details
  3. Copy the full SHA
    34b3f7b View commit details
Showing with 114 additions and 25 deletions.
  1. +33 −0 CONTRIBUTING.md
  2. +1 −1 README.md
  3. +28 −0 docs/rules/no-skipped-test.md
  4. +10 −17 pnpm-lock.yaml
  5. +3 −5 src/rules/expect-expect.ts
  6. +20 −0 src/rules/no-skipped-test.ts
  7. +1 −1 src/utils/ast.ts
  8. +14 −1 test/spec/expect-expect.spec.ts
  9. +4 −0 test/spec/no-skipped-test.spec.ts
33 changes: 33 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
# Contributing

## Installing Dependencies

We use [pnpm](https://pnpm.io) for managing dependencies. You can install the
necessary dependencies using the following command:

```bash
pnpm install
```

## Running Tests

When making changes to lint rules, you can re-run the tests with the following
command:

```bash
pnpm test
```

Or run it in watch mode like so:

```bash
pnpm test -- --watch
```

## Adding new rules

When adding new rules, make sure to follow these steps:

1. Add the rule source code in `src/rules`
1. Add tests for the rule in `test/spec`
1. Add docs for the rule to `docs/rules`
1. Add a short description of the rule in `README.md`

## Releasing

To release a new version with semantic-release, run the following command.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -101,7 +101,7 @@ under the `playwright` key. It supports the following settings:
the presence of at least one assertion per test case. This allows such rules
to recognise custom assertion functions as valid assertions. The global
setting applies to all modules. The
[`expect-expect` rule accepts an option by the same name](./rules/expect-expect.md#additionalassertfunctionnames)
[`expect-expect` rule accepts an option by the same name](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/expect-expect.md#additionalassertfunctionnames)
to enable per-module configuration (.e.g, for module-specific custom assert
functions).

28 changes: 28 additions & 0 deletions docs/rules/no-skipped-test.md
Original file line number Diff line number Diff line change
@@ -31,3 +31,31 @@ test.describe('two tests', () => {
test('two', async ({ page }) => {});
});
```

## Options

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

### `allowConditional`

Setting this option to `true` will allow using `test.skip()` to
[conditionally skip a test](https://playwright.dev/docs/test-annotations#conditionally-skip-a-test).
This can be helpful if you want to prevent usage of `test.skip` being added by
mistake but still allow conditional tests based on browser/environment setup.

Example of **correct** code for the `{ "allowConditional": true }` option:

```javascript
test('foo', ({ browserName }) => {
test.skip(browserName === 'firefox', 'Still working on it');
});
```
27 changes: 10 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions src/rules/expect-expect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Rule } from 'eslint';
import * as ESTree from 'estree';
import { isExpectCall, isIdentifier, isTest } from '../utils/ast';
import { dig, isExpectCall, isTest } from '../utils/ast';
import { getAdditionalAssertFunctionNames } from '../utils/misc';

function isAssertionCall(
@@ -9,9 +9,7 @@ function isAssertionCall(
) {
return (
isExpectCall(node) ||
additionalAssertFunctionNames.find((name) =>
isIdentifier(node.callee, name),
)
additionalAssertFunctionNames.find((name) => dig(node.callee, name))
);
}

@@ -38,7 +36,7 @@ export default {
if (isTest(node, ['fixme', 'only', 'skip'])) {
unchecked.push(node);
} else if (isAssertionCall(node, additionalAssertFunctionNames)) {
checkExpressions(context.getAncestors());
checkExpressions(context.sourceCode.getAncestors(node));
}
},
'Program:exit'() {
20 changes: 20 additions & 0 deletions src/rules/no-skipped-test.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ export default {
create(context) {
return {
CallExpression(node) {
const options = context.options[0] || {};
const allowConditional = !!options.allowConditional;
const { callee } = node;

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

// If allowConditional is enabled and it's not a test/describe hook,
// we ignore any `test.skip` calls that have no arguments.
if (!isHook && allowConditional && node.arguments.length) {
return;
}

context.report({
messageId: 'noSkippedTest',
node: isHook ? callee.property : node,
@@ -52,6 +60,18 @@ export default {
noSkippedTest: 'Unexpected use of the `.skip()` annotation.',
removeSkippedTestAnnotation: 'Remove the `.skip()` annotation.',
},
schema: [
{
additionalProperties: false,
properties: {
allowConditional: {
default: false,
type: 'boolean',
},
},
type: 'object',
},
],
type: 'suggestion',
},
} as Rule.RuleModule;
2 changes: 1 addition & 1 deletion src/utils/ast.ts
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ export function getMatchers(
* Digs through a series of MemberExpressions and CallExpressions to find an
* Identifier with the given name.
*/
function dig(node: ESTree.Node, identifier: string | RegExp): boolean {
export function dig(node: ESTree.Node, identifier: string | RegExp): boolean {
return node.type === 'MemberExpression'
? dig(node.property, identifier)
: node.type === 'CallExpression'
15 changes: 14 additions & 1 deletion test/spec/expect-expect.spec.ts
Original file line number Diff line number Diff line change
@@ -93,7 +93,20 @@ runRuleTester('expect-expect', rule, {
await assertCustomCondition(page)
})
`,
name: 'Global settings only',
name: 'Custom assert function',
settings: {
playwright: {
additionalAssertFunctionNames: ['assertCustomCondition'],
},
},
},
{
code: dedent`
test('should fail', async ({ myPage, page }) => {
await myPage.assertCustomCondition(page)
})
`,
name: 'Custom assert class method',
settings: {
playwright: {
additionalAssertFunctionNames: ['assertCustomCondition'],
4 changes: 4 additions & 0 deletions test/spec/no-skipped-test.spec.ts
Original file line number Diff line number Diff line change
@@ -201,5 +201,9 @@ runRuleTester('no-skipped-test', rule, {
'this.skip();',
'this["skip"]();',
'this[`skip`]();',
{
code: 'test.skip(browserName === "firefox", "Still working on it");',
options: [{ allowConditional: true }],
},
],
});