Skip to content

Fix documentation of running ESM jest#11717

Merged
SimenB merged 4 commits intojestjs:mainfrom
edemaine:patch-1
Sep 29, 2021
Merged

Fix documentation of running ESM jest#11717
SimenB merged 4 commits intojestjs:mainfrom
edemaine:patch-1

Conversation

@edemaine
Copy link
Copy Markdown
Contributor

@edemaine edemaine commented Aug 2, 2021

Summary

node --experimental-vm-modules node_modules/.bin/jest doesn't work (at least on Windows) because node_modules/.bin/jest is a shell script:

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  exec "$basedir/node"  "$basedir/../jest/bin/jest.js" "$@"
else
  exec node  "$basedir/../jest/bin/jest.js" "$@"
fi

node --experimental-vm-modules node_modules/jest/bin/jest.js works well for me by pointing directly to the JavaScript that Node can run. I saw this version
in this StackOverflow post.

Test plan

$ node --experimental-vm-modules node_modules/.bin/jest
C:\...\node_modules\.bin\jest:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1031:15)
    at Module._compile (node:internal/modules/cjs/loader:1065:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
    at node:internal/main/run_main_module:17:47
$ node --experimental-vm-modules node_modules/jest/bin/jest.js
(node:11736) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
 PASS  ./index.test.js
...

`node_modules/.bin/jest` is a shell script; point instead to actual JavaScript which Node can run.
Copy link
Copy Markdown
Member

@orta orta left a comment

Choose a reason for hiding this comment

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

Looks good, and we can ignore the reds - can you duplicate the change in https://github.com/facebook/jest/blob/master/docs/ECMAScriptModules.md so that it ends up in all future docs too please 👍🏻

@SimenB
Copy link
Copy Markdown
Member

SimenB commented Sep 29, 2021

@edemaine could you update all editions of the versioned docs as well?

image

@edemaine
Copy link
Copy Markdown
Contributor Author

Sorry for the delay. This should be fully propagated now.

Copy link
Copy Markdown
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

thanks!

@SimenB SimenB merged commit ad240ed into jestjs:main Sep 29, 2021
@github-actions
Copy link
Copy Markdown

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 Oct 30, 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.

4 participants