[jest-runtime] Allow to `import` native addon modules (binary files) created by node-gyp
Summary
Without this commit
NODE_OPTIONS="--es-module-specifier-resolution=node --experimental-vm-modules --experimental-modules" npm exec jest
on a .(m)js file (ESM)
export default (
await import('../Release/SomeProject.node')
).default;
results in
Unterminated string.
at @:1:155
at @:1:155
at stringLiteral (node_modules/cjs-module-lexer/lexer.js:1262:9)
at parseSource (node_modules/cjs-module-lexer/lexer.js:201:9)
at parseCJS (node_modules/cjs-module-lexer/lexer.js:43:5)
at build/src/SomeProject.js:12:17
because jest-runtime has ordered cjs-module-lexer
to parse a binary file (already converted to UTF-8 by readFile) as JavaScript.
Test plan
I've attached a nodeGypTestCase.tar.gz (997 bytes)
mkdir /tmp/nodeGypTestCase
cd /tmp/nodeGypTestCase
wget https://github.com/facebook/jest/files/9229734/nodeGypTestCase.tar.gz
tar xf nodeGypTestCase.tar.gz
then
npm install
npm run build
npm run test
or
yarn
yarn build
yarn test
I don't know whether my change is a feature or a fix, so I didn't touch the changelog.
Can you add an integration test?
I don't know whether my change is a feature or a fix, so I didn't touch the changelog.
Feature, I think 👍
@arzeth ping 🙂
This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days.
This PR was closed because it has been stalled for 30 days with no activity. Please open a new PR if the issue is still relevant, linking to this one.
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.