jest-runtime breaks node.js 'module' module API
See original GitHub issueš Bug Report
Node.jsās module module API is not compliant after gets instrumented by JEST
To Reproduce
const jq = require('jsonpath');
describe('JEST test', () => {
test('hello world', async () => {
expect(1).toBe(1);
});
});
This test will fail with TypeError: Module is not a constructor
Expected behavior
Test should pass
Link to repl or repo (highly encouraged)
https://github.com/hugebdu/jest-bug
envinfo
System:
OS: macOS 10.15.3
CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
Binaries:
Node: 12.13.1 - ~/.nvm/versions/node/v12.13.1/bin/node
Yarn: 1.21.1 - ~/.nvm/versions/node/v12.13.1/bin/yarn
npm: 6.12.1 - ~/.nvm/versions/node/v12.13.1/bin/npm
npmPackages:
jest: ~25.2.1 => 25.2.1
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:11 (1 by maintainers)
Top Results From Across the Web
Modules: node:module API | Node.js v19.3.0 Documentation
Provides general utility methods when interacting with instances of Module , the module variable often seen in CommonJS modules. Accessed via import 'node:Ā ......
Read more >javascript - How to unit test a Node.js module that requires ...
Proxyquire has a very simple api which allows resolving the module you are trying to test and pass along mocks/stubs for its required...
Read more >babel-jest - Awesome JS
[jest-runtime] Support WebAssembly (Wasm) imports in ESM modules (#13505) ... [BREAKING] Drop support for Node v12 and v17 (#13033); [docs] Fix webpack nameĀ ......
Read more >jest 27.0.0 on Node.js Yarn - NewReleases.io
New release jest version 27.0.0 on Node.js Yarn. ... [jest-runtime] [BREAKING] Do not inject global variable into module wrapper (#10644); [jest-runtime]Ā ...
Read more >Node.js Modules - GeeksforGeeks
The reason programmers are heavily reliant on modules is because of their re-usability as well as the ability to break down a complex...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

25.2.2 released with the fix. If itās still broken somehow weāll need to revert #9469 and revisit it later
Oops, comes from #9469, /cc @doniyor2109.
I didnāt know
require('module');returned a constructible class - doesnāt seem to be documented behavior. We need to fix this of course