Skip to content
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

fix: export default in test environments #11335

Closed
wants to merge 1 commit into from
Closed

fix: export default in test environments #11335

wants to merge 1 commit into from

Conversation

mrazauskas
Copy link
Contributor

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'). Perhaps export default could be used instead of export =? 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.

@SimenB
Copy link
Member

SimenB commented Apr 30, 2021

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

@mrazauskas
Copy link
Contributor Author

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). export default is alright for a library in transition.

One test is now failing. Is it really related with my PR? Seemed like all was good before. Can’t figure out what happened.

@mrazauskas mrazauskas closed this Jul 15, 2021
@mrazauskas mrazauskas deleted the fix-export-default branch July 15, 2021 09:52
@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants