I reckon that what you want to do is to run tests that are generated using playwright codegen with Jest.
However, this does not seem to be possible: The tests are generated with import { test, expect } from '@playwright/test' at the top, and this is the module that throws the error. The tests that are generated with Playwright use the API from this module, and this is slightly different than the one from Jest. (It gets fixtures as parameters).
If you use the implementation from Playwright (for instance by mocking away the throwIfRunningInsideJest function), it still won't work because then the tests won't be registered in the Jest test runner.
I reckon that what you want to do is to run tests that are generated using playwright codegen with Jest.
However, this does not seem to be possible: The tests are generated with import { test, expect } from '@playwright/test' at the top, and this is the module that throws the error. The tests that are generated with Playwright use the API from this module, and this is slightly different than the one from Jest. (It gets fixtures as parameters).
If you use the implementation from Playwright (for instance by mocking away the throwIfRunningInsideJest function), it still won't work because then the tests won't be registered in the Jest test runner.
If you have a different extension for your jest tests vs your playwright tests, excluding is what solved this for me.
For example, I have .test.js for jest and .spec.js for playwright. In jest config, I added modulePathIgnorePatterns: ["spec.js"], and it solved the issue.
[Question] @playwright/test - Ignore .tsx files when running tests
typescript - How to ignore multiple spec files in playwright? - Stack Overflow
exclude default setting should exclude e2e tests folder
@nx/playwright:configuration doesn't exclude e2e files from unit test config
You can use grep or grepInvert to skip over certain tests in projects. So something like this might work:
{
name: 'Admin Users',
grep: /.*limited.spec.ts/,
grepInvert: /.*comments.spec.ts/
use: {
baseURL: process.env.URL,
screenshot: "only-on-failure",
video: "retain-on-failure",
storageState: 'login2.json',
headless: true,
channel: 'chrome',
viewport: { width: 1536, height: 850 },
ignoreHTTPSErrors: true,
}
},
Maybe you need to adapt the regex to match your needs.
If you wish to ignore several files that located in different locations,
you can use an Array instead of a single string/regex, since testIgnore type is string | RegExp | Array<string | RegExp>.
For example:
projects: [
{
name: "Admin",
testIgnore: [
"/userOnlyFolder/**/*.spec.ts", // Any test file under a specified folder or anywhere under it's sub-directories
"**/userOnlyTestFile.spec.ts", // A specific test file anywhere in the folder tree
"/tests/someOtherFolder/userOnlyTestFile.spec.ts", // Full path specified
],
},
]
Playwright testconfig ignore docs
Hi everyone! I'm in charge of deciding which automation frameworks we should use at our company. For QA, I want them to use Playwright Test Runner + Playwright, esp since they have webkit (and a lot of our users use both Chrome and Safari), but our eng team already uses Jest for all of their unit tests.
Would it be better to do Jest + Playwright (to remain consistent with the rest of eng team) or do Playwright Test Runner + Playwright (since it's already similar to Jest and does a lot more than Jest from a QA's perspective)?
And if we should do the latter, then should we just let the eng team continue with Jest? I'm just not sure what to do so if anyone can give some advice about this, that would be great! Thank you!