-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] global expect overrides jest expect — is that okay? #19798
Comments
@Diokuz first of all, I'm sorry you spent a day debugging this nasty behavior!
So my naive attempt to reproduce this failed: // a.mjs
import { chromium } from '@playwright/test';
console.log(global.expect); This prints |
Unrelated: A word of advice, don't do jest + playwright - we've seen people misusing it and ending up with memory leaks, inefficient setups, poor parallelization. Should you choose to use jest though, you can't use @playwright/test, you should import playwright and use it as a library. |
Thanks for response) Ill try to go deeper in a week, but what I can say right now is that removing import solved my problem: fails: export { test } from '@playwright/test' works well: // export { test } from '@playwright/test' @pavelfeldman I agree with you for 100%, that was just a temporal solution during migration from jest to Playwright) |
I found it! https://github.com/microsoft/playwright/blob/main/packages/playwright-test/src/expect.ts#L290
|
@Diokuz Ah! So the workaround would be to avoid importing test. Seems to be good-enough to me! :) |
Hi, we just ran into the same issue and spent some good time debugging it, before we noticed that playwright is actually overriding the jest expect method. We have an npm package, which contains all our testing utilities that we share across our teams. This includes some utilities for jest unit/integration tests and playwright e2e tests. We just added shared playwright fixtures and we are importing We were also able to workaround it by adding It would be nice if playwright didn't affect other packages just by importing it. |
We spend a day on this)
So, we have some jest + puppeteer tests. We want to migrate to playwright-test, but, after some difficulties, as a first step we decided to replace just puppeteer with playwright. So, our first target – jest + playwright.
We replaced puppeteer with playwright and got this test failing in CI:
WAT? @playwright/test matchers? :)
Test failed in CI, but not locally. We spent few hours to reproduce that locally. The trick was – during local debug we just removed the second test instead of marking it as
.only
. Because of that, typescript just removed unused '@my-local-namespace/playwright-utils' import, which contains imports from@playwright/test
under the hood. So, in CI there were transitive imports from@playwright/test
, and there were no imports from@playwright/test
locally.We found out that any import from
@playwright/test
replacesimport {expect} from '@jest/globals';
Solution: use expect from
The question: what do you think about not monkey patching global object when playwright test was not launched explicitly?
The text was updated successfully, but these errors were encountered: