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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add info about ES modules to docs #10611

Merged
merged 3 commits into from Oct 10, 2020
Merged

Conversation

SimenB
Copy link
Member

@SimenB SimenB commented Oct 9, 2020

Summary

Ref #9430 (comment)

I haven't written too much, but it's something. Added it to all jest@26 versioned docs.

Test plan

馃し

image

With the warnings out of the way, this is how you activate ESM support in your tests.

1. Ensure you either disable [code transforms](./configuration#transform-objectstring-pathtotransformer--pathtotransformer-object) by passing `transform: {}` or otherwise configure your transformer to emit ESM rather than the default CommonJS (CJS).
1. Execute `node` with `--experimental-vm-modules`, e.g. `node --experimental-vm-modules node_modules/.bin/jest` or `NODE_OPTIONS=--experimental-vm-modules npx jest` etc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My tests for tslib didn't need these flags, just making sure that the root package json is a "type": "module" - https://github.com/microsoft/tslib/tree/master/test/esm-node-native

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orta
That鈥檚聽because your聽tests don鈥檛聽use聽Jest, which聽runs聽tests in聽vm聽contexts, where聽the聽Module聽API needs聽that聽flag.

Copy link
Member Author

@SimenB SimenB Oct 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, see the https://nodejs.org/api/vm.html#vm_class_vm_module link above.

EDIT: Ergh, same link as @ExE-Boss posted 馃槄

docs/ECMAScriptModules.md Outdated Show resolved Hide resolved
Co-authored-by: Micha毛l Zasso <targos@protonmail.com>
@SimenB SimenB merged commit c80911a into jestjs:master Oct 10, 2020
@SimenB SimenB deleted the esm-docs branch October 10, 2020 10:24
@SimenB
Copy link
Member Author

SimenB commented Oct 10, 2020

@Pomax
Copy link

Pomax commented Oct 10, 2020

This might need a quick followup: the documented way of invoking with the experimental flag set through an env var does not work on Windows, requiring cross-env or the like to keep the instructions universal.

@SimenB
Copy link
Member Author

SimenB commented Oct 11, 2020

@Pomax wanna send a PR tweaking the text to work on all platforms?

@Pomax
Copy link

Pomax commented Oct 11, 2020

I don't know what your policy on "backing" third party tools is, so I have no idea what a PR would look like, here, whereas you probably do. I can heartily recommend tell folks to use cross-env for anything that relies on command line env vars if things need to work cross-platform, but I have no idea what Facebook's policy is, and I'm very much not up for signing a CLA just to submit a docs PR... though if docs PRs are exempt I can write something up?

@SimenB
Copy link
Member Author

SimenB commented Oct 12, 2020

I can't imagine FB having a policy on that (I don't work there). I understand not wanting the sign the CLA, if just sticking cross-env in there works I can do that 馃憤

CRA just documents how to do it on different platforms, but I think that's also for educational purposes, which is not really relevant for us here: https://create-react-app.dev/docs/adding-custom-environment-variables/#adding-temporary-environment-variables-in-your-shell

(they do use cross-env themselves, tho: https://github.com/facebook/create-react-app/blob/14b78680ffe4357f379b83f51682f3c2075eb987/packages/create-react-app/package.json#L29)

@SimenB
Copy link
Member Author

SimenB commented Oct 12, 2020

@Pomax d63f18a

@Pomax
Copy link

Pomax commented Oct 12, 2020

yep, docs wise that's perfect, thanks!

@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 May 11, 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.

None yet

7 participants