-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
feat(jest-core): add support for globalSetup
and globalTeardown
written in ESM
#11267
Conversation
Not sure why the snapshot test file has been affected here. |
Only Windows latest failing at the installation step now. |
@SimenB do you know why the Windows / Node 15 would fail? |
@aledalgrande sorry about the slow response here. Windows is failing due to an install issue (#11229) and can be safely ignored 🙂 |
Codecov Report
@@ Coverage Diff @@
## master #11267 +/- ##
==========================================
- Coverage 64.23% 64.20% -0.03%
==========================================
Files 308 308
Lines 13512 13521 +9
Branches 3292 3295 +3
==========================================
+ Hits 8679 8681 +2
- Misses 4120 4128 +8
+ Partials 713 712 -1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @aledalgrande, this looks good! 👍
When you update runGlobalHook.ts
you also add support for globalTeardown
- could you add a test for that as well?
globalSetup
written in ESMglobalSetup
and globalTeardown
written in ESM
@SimenB added a simple test, but I'm getting weird failures. Some about timing and others about logs. |
Thanks @aledalgrande! |
@SimenB this is not in @next yet right? |
Correct. I can make a new release later today so people can use it 👍 |
@gilles-yvetot found some time now, next.9 released |
@SimenB you are the real MVP |
I'm trying out
The function that errors: _getVirtualMockPath(virtualMocks, from, moduleName) {
console.log({virtualMocks, from, moduleName}) //my console.log
const virtualMockPath = this.getModulePath(from, moduleName);
return virtualMocks.get(virtualMockPath) // line 448
? virtualMockPath
: moduleName
? this.resolveModule(from, moduleName)
: from;
} console.logging the input gives me {
virtualMocks: {},
from: '<my-project>\\node_modules\\source-map-support\\source-map-support.js',
moduleName: 'source-map-support'
} It seems I'm only getting the error when using |
@jakobrosenberg huh, interesting! Could you open up a new issue with a (minimal) reproduction? |
@SimenB I'll see if I can get one done. In the meantime, I found the same issue here playwright-community/jest-playwright#665 Alas the proposed solution did not work for me. |
I'd assume it's an issue because they pull in v26 deps: https://github.com/playwright-community/jest-playwright/blob/f8ee23108bcac6801f073986a9bba56dfe461c2f/package.json#L48-L51 Should probably be peer deps so users can plug in their own versions.
Hah, right! Makes sense it's the outdated deps. You can try |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Adds support for
globalSetup
when using Jest in ESM mode. Potentially adds support forglobalTeardown
too, but will leave tests for that in a separate PR.Works towards completing #11167.
I did not use
requireOrImportModule
because it seemed the flow here was a bit different from the other cases, but let me know if you want that changed. Also left formatting to Prettier/ESLint, hope that worked well.Test plan
Tests are attached. I took inspiration from other PRs/existing code, hope it makes sense.