Search code examples
eslintplaywright

Why are my skipped and focused tests not raising errors for eslint-plugin-jest?


I have skipped Playwright Node tests but they are not being reported as violations when I run linting with eslint ..

I am using the eslint-plugin-jest package that I've used before in other projects. The rule I use is jest/no-disabled-tests

My tests are using the format test.skip. I don't get an error, just no violations reported.


Solution

  • The Jest plugin's rules only apply to Jest's globals, by default. You've imported test from @playwright/test, so it knows that's not from Jest. Per the documentation:

    You can tell [eslint-plugin-jest] to treat a different package as the source of Jest globals using the globalPackage setting:

    In this case:

        settings: {
          jest: {
            globalPackage: "@playwright/test",
          },
        },
    

    As they note, though:

    While this can be used to apply rules when using alternative testing libraries and frameworks like bun, vitest and node, there's no guarantee the semantics this plugin assumes will hold outside of Jest

    For example, the Jest plugin would not detect the following:

    test.describe.skip(/* ... */);
    

    whereas the Playwright plugin would report an "Unexpected use of the .skip() annotation". Also the Playwright plugin lets you allowConditional to support conditional skips, which the Jest plugin would always report on.

    Fundamentally it's better to use the plugin actually designed for Playwright.