jest icon indicating copy to clipboard operation
jest copied to clipboard

[jest-runtime] Allow to `import` native addon modules (binary files) created by node-gyp

Open arzeth opened this issue 3 years ago • 2 comments

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.

arzeth avatar Jul 31 '22 21:07 arzeth

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 👍

SimenB avatar Aug 01 '22 15:08 SimenB

@arzeth ping 🙂

SimenB avatar Aug 07 '22 16:08 SimenB

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.

github-actions[bot] avatar Nov 05 '22 16:11 github-actions[bot]

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.

github-actions[bot] avatar Dec 05 '22 16:12 github-actions[bot]

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[bot] avatar Jan 05 '23 00:01 github-actions[bot]