-
-
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
[Bug]: Worker
class of jest-worker
does not support ESM worker modules
#12274
Comments
@SimenB Would it be possible to include this issue in Jest 28 milestone? I really need it for one work-in-progress test runner (; Might be there is better solution, but it seemed like having async The problem is that constructor of the class cannot be asynchronous. Async |
yes! factory pattern is how we've solved other "class does |
@mrazauskas wanna send a PR for this one? 🙂 |
Yes, I would love to. Next week (; |
yay! |
This step required to use CommonJS instead of ESM since neither bull nor jest-worker support it. See: - jestjs/jest#12274 - OptimalBits/bull#924
This is so old. Probably nobody needs it anymore. Closing. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Version
v27.4.7
Steps to reproduce
An exception is raised, if I try to initialise a worker with an ESM module:
new Worker('path/to/ESMworker.mjs')
. Looks likejest-worker
is simply trying torequire
the module and that does not work:https://github.com/facebook/jest/blob/d1bc333c549ffb53691e1ba68b16a21915fc5fdc/packages/jest-worker/src/workers/processChild.ts#L113-L114
https://github.com/facebook/jest/blob/d1bc333c549ffb53691e1ba68b16a21915fc5fdc/packages/jest-worker/src/workers/processChild.ts#L96-L97
https://github.com/facebook/jest/blob/d1bc333c549ffb53691e1ba68b16a21915fc5fdc/packages/jest-worker/src/index.ts#L32-L33
I was trying to refactor the code using the
requireOrImportModule
fromjest-utils
. Unfortunately the private methodthis._bindExposedWorkerMethods()
of theWorker
class has to become async, but it is called in the constructor. Async calls are not possible in constructors.Good news:
Worker
is a named export. If I get it right, this makes it possible to export something else fromjest-worker
. So perhaps an asynchronouscreateWorker()
factory function could be a non-breaking solution?@SimenB Does it look acceptable for you? Feels like I could solve it this way.
Expected behavior
Would be great to support ESM worker modules in
jest-worker
package.Actual behavior
jest-worker
package does not support ESM worker modules.Additional context
No response
Environment
The text was updated successfully, but these errors were encountered: