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.
jestjs - Configuring PlayWright and Jest returns 'Playwright Test needs to be invoked via 'npx playwright test' and excluded from Jest test runs' - Stack Overflow
What should I know about testing?
Jest vs Playwright
If you have the chance to switch TODAY, which testing stack for component testing to use?
Videos
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!
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.
ยป npm install jest-playwright-preset