fix: export default in test environments#11335
fix: export default in test environments#11335mrazauskas wants to merge 1 commit intojestjs:masterfrom mrazauskas:fix-export-default
Conversation
|
Problem with default export now is that it's not actually ESM, so native ESM must do import TestEnv from 'jest-environment-node';
export default MyTestEnv extends TestEnv.default {}Using a named import (or native ESM) is better... Might go for wannabe ESM for Jest 27, then convert to native ESM for Jest 28 |
You see it better. I was thinking, Jest 27 most probably will be build as CJS. At the same time, ESM for test environment will be supported (#11033). One test is now failing. Is it really related with my PR? Seemed like all was good before. Can’t figure out what happened. |
|
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
Really nice that Jest 27 allows to write custom environments in TypeScript (#8751). I was playing with it. All works really well. Thanks!
Just a detail. Imports look clumsy in TS –
import NodeEnvironment = require('jest-environment-node'). Perhapsexport defaultcould be used instead ofexport =? This way TS and MJS imports look good, but a breaking change for CJS users is introduced. Is there a better solution?(Alternatively TS uses can set
"esModuleInterop": true, but this isn’t elegant.)Test plan
Existing tests are updated.