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

An exception is thrown when executing jest. #293

Closed
MSakamaki opened this issue Aug 11, 2021 · 6 comments
Closed

An exception is thrown when executing jest. #293

MSakamaki opened this issue Aug 11, 2021 · 6 comments

Comments

@MSakamaki
Copy link

Describe the bug

When I run jest on a stackblitz nodejs, I get the following error
this does not happen with local nodejs.

TypeError: 'getOwnPropertyDescriptor' on proxy: trap returned undefined for property 'jest-symbol-do-not-touch' which is non-configurable in the proxy target

Link to the blitz that caused the error

https://stackblitz.com/edit/node-ked4s2

Steps to reproduce

I looked into it as much as I could, but it seems that if you add properties to a global object defined in node-vm by Object.defineProperties, it crashes when you access it.

Here is a small piece of code to reproduce it.

const { runInContext, createContext } = require('vm');

const context = createContext();
const global = (this.global = runInContext('this', context));

Object.defineProperties(global, {
  'jest-symbol-do-not-touch': {
    enumerable: false,
    value: global.Symbol,
    writable: false
  }
});

console.log(global['x']); // success
console.log(global['jest-symbol-do-not-touch']); // error
Object.keys(global); // error

Expected behavior

the reproduced code above works fine locally, so it should also work fine on stackblitz.

Screenshots

error

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 92.0.4515.131

Additional context

No response

@freehuntx
Copy link

freehuntx commented Aug 20, 2021

I think this is related to how "Proxy" is implemented inside of WebContainers node.
jest relies on Proxy as you can see here: https://github.com/facebook/jest/blob/bc50e7f360ab1845abbaa0b3ad788caead0d3174/packages/jest-util/src/createProcessObject.ts
and
https://github.com/facebook/jest/blob/59f42d86756fcc3c9caf0c8a5cf1b13324941d4e/packages/jest-runtime/src/index.ts
So if the implementation of Proxy is broken inside of WebContainers node, that might be the reason.

Logging global.Proxy inside of my main machine gives me: [Function: Proxy]
Logging it inside of WebContainers node gives me: [Function: bound Proxy]

@freehuntx
Copy link

Maybe related with:
nodejs/node#30985
nodejs/node#17465

@freehuntx
Copy link

freehuntx commented Aug 20, 2021

A workaround is, to set configurable to true.
test/test-environment.js

const defineProperties = Object.defineProperties;
Object.defineProperties = function(obj, props) {
  if (props['jest-symbol-do-not-touch']) {
    props['jest-symbol-do-not-touch'].configurable = true;
  }
  return defineProperties(obj, props);
};

module.exports = require('jest-environment-node');

package.json

...
  "jest": {
    "testEnvironment": "./test/test-environment.js"
  }
...

Note: This issue has been fixed. So this workaround is not needed anymore!

@MSakamaki
Copy link
Author

Thanks for the kind reply!
I have confirmed that jest 27 will run with the solution you suggested.
https://stackblitz.com/edit/node-qsuzv8

since my issue has been solved, I will close this issue.

@freehuntx
Copy link

This still looks like a bug that shouldnt happen imo. I would not close it as such a bug can cause alot of different bugs.
It should definitely be investigated.

@freehuntx
Copy link

Note: This has been fixed. So no workaround anymore needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants