question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
SimenBcommented, Mar 26, 2020

25.2.2 released with the fix. If it’s still broken somehow we’ll need to revert #9469 and revisit it later

2reactions
SimenBcommented, Mar 26, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found