Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: jest errors with Class constructor Process cannot be invoked without 'new' #23863

Closed
marvinhagemeister opened this issue May 17, 2024 · 0 comments · Fixed by #23865
Closed
Labels
bug Something isn't working correctly node API polyfill Related to various "node:*" modules APIs node compat

Comments

@marvinhagemeister
Copy link
Contributor

Jest does some things with the process prototype that lead to an error:

TypeError: Class constructor Process cannot be invoked without 'new'
      at createProcessObject (file:/Users/marvinh/dev/test/deno-jest/node_modules/jest-util/build/createProcessObject.js:98:25)
      at Object.runMicrotasks (ext:core/01_core.js:642:26)
      at processTicksAndRejections (ext:deno_node/_next_tick.ts:66:10)
      at runNextTicks (ext:deno_node/_next_tick.ts:86:3)
      at eventLoopTick (ext:core/01_core.js:175:21)

Excerpt of the code that throws this error:

// Sequentially execute all constructors over the object.
  let proto = process;
  while ((proto = Object.getPrototypeOf(proto))) {
    if (typeof proto.constructor === 'function') {
      proto.constructor.call(newProcess);
    }
  }

The error is thrown because process isn't a class in Node whereas it is one in Deno.

Steps to reproduce

Run this snippet:

import process from "node:process";
const obj = process.constructor.call({});

console.log(obj);
// Node: {}
// Deno: ERROR

Version: Deno 1.43.4

@marvinhagemeister marvinhagemeister added bug Something isn't working correctly node compat node API polyfill Related to various "node:*" modules APIs labels May 17, 2024
bartlomieju pushed a commit that referenced this issue May 21, 2024
Popular test runners like Jest instantiate a new `Process` object
themselves and expect the class constructor to be callable without the
`new` keyword. This PR refactors our `Process` class implementation from
a proper ES2015 class to an ES5-style class which can be invoked both
with and without the `new` keyword like in Node.

Fixes #23863
bartlomieju pushed a commit that referenced this issue May 21, 2024
Popular test runners like Jest instantiate a new `Process` object
themselves and expect the class constructor to be callable without the
`new` keyword. This PR refactors our `Process` class implementation from
a proper ES2015 class to an ES5-style class which can be invoked both
with and without the `new` keyword like in Node.

Fixes #23863
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node API polyfill Related to various "node:*" modules APIs node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant