oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.42k stars 1.64k forks source link

Node GraalVM does not work with Jest framework #5679

Open kfiron opened 1 year ago

kfiron commented 1 year ago

Describe the issue Running Jest tests with Node that comes with GraalVM Node gives an error

Steps to reproduce the issue Just run any Jest test but with Node process from: /Users/{$user}/graalvm-ce-java17-22.3.0/Contents/Home/bin/node

Describe GraalVM and your environment: openjdk 17.0.5 2022-10-18 OpenJDK Runtime Environment GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08) OpenJDK 64-Bit Server VM GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08, mixed mode, sharing) Node version of GraalVM: v16.17.1

More details


  ● Test suite failed to run

    TypeError: Cannot redefine property: NaN
        at Function.defineProperty (native)

      at new NodeEnvironment (node_modules/jest-environment-node/build/index.js:92:16)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.347s
error Command failed with exit code 1.```
TheTaha-Alamine commented 1 year ago

Thank you for reporting this, we will look into it and get back to you.

TheTaha-Alamine commented 1 year ago

We couldn't reproduce the error, are you sure the error comes from GraalVM NodeJs, may I ask you how did you get to the assumption of the issue is coming from GraalVM's NodeJs? did you run the same tests with another Node and it gives you different results?

kfiron commented 1 year ago

Thanks for quick response, I even tried it on a clean project with the following example: https://jestjs.io/docs/getting-started I got the same error.

TheTaha-Alamine commented 1 year ago

Did you check if you've added "jest" in the script section in your package.json file : "scripts": { "test": "jest" }

kfiron commented 1 year ago

Yes sure, I got the same error. The same code under regular node is running perfectly

On Tue, Dec 27, 2022 at 20:35 Taha Alamine Boukhalf < @.***> wrote:

Did you check if you've added "jest" in the script section in your package.json file : "scripts": { "test": "jest" }

— Reply to this email directly, view it on GitHub https://github.com/oracle/graal/issues/5679#issuecomment-1366097625, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARC3JHJNKY6GGMBZWMJPELWPNAJJANCNFSM6AAAAAATJVHK6Q . You are receiving this because you authored the thread.Message ID: @.***>

-- Kfir Bloch

Cell: 054-568-5848

TheTaha-Alamine commented 1 year ago

Can you please specify which Os & arch you're wotking with?

kfiron commented 1 year ago

Hi i created a repo with the problem, just run npm install and then npm test and you'll get the error if you node is from GraalVM. the repo: https://github.com/kfiron/graalvm-node-jest

I am using Mac OSX Monterey with Inter processor

kfiron commented 1 year ago

Adding full stacktrace:

  ● Test suite failed to run

    TypeError: Cannot redefine property: NaN
        at Function.defineProperty (native)

      at new NodeEnvironment (node_modules/jest-environment-node/build/index.js:92:16)
      at runMicrotasks (native)
kfiron commented 1 year ago

Hi any news about this issue?

kfiron commented 1 year ago

@TheTaha-Alamine can you tell me if there is any progress with this issue?

alexeevg commented 1 year ago

Seems like the problem is caused by different vm module behaviour. Under GraalVM, runInContext returns a proxy:

$ node
Welcome to Node.js v16.18.1.
Type ".help" for more information.
> g = vm.runInContext('this', vm.createContext())
Proxy [
  Object [global] {},
  {
    get: [Function (anonymous)],
    set: [Function (anonymous)],
    has: [Function (anonymous)],
    deleteProperty: [Function (anonymous)],
    ownKeys: [Function (anonymous)],
    getOwnPropertyDescriptor: [Function (anonymous)],
    defineProperty: [Function (anonymous)],
    getPrototypeOf: [Function (anonymous)]
  }
]
> util.types.isProxy(g)
true
>  Object.getOwnPropertyNames(g)
[]

For comparison, on native node.js:

$ node
Welcome to Node.js v16.17.0.
Type ".help" for more information.
> vm.runInContext('this', vm.createContext())
{}
> util.types.isProxy({})
false
> g = vm.runInContext('this', vm.createContext())
{}
> util.types.isProxy(g)
false
> Object.getOwnPropertyNames(g)
[
  'Object',               'Function',          'Array',
  'Number',               'parseFloat',        'parseInt',
  'Infinity',             'NaN',               'undefined',
  'Boolean',              'String',            'Symbol',
  'Date',                 'Promise',           'RegExp',
  'Error',                'AggregateError',    'EvalError',
  'RangeError',           'ReferenceError',    'SyntaxError',
  'TypeError',            'URIError',          'globalThis',
  'JSON',                 'Math',              'console',
  'Intl',                 'ArrayBuffer',       'Uint8Array',
  'Int8Array',            'Uint16Array',       'Int16Array',
  'Uint32Array',          'Int32Array',        'Float32Array',
  'Float64Array',         'Uint8ClampedArray', 'BigUint64Array',
  'BigInt64Array',        'DataView',          'Map',
  'BigInt',               'Set',               'WeakMap',
  'WeakSet',              'Proxy',             'Reflect',
  'FinalizationRegistry', 'WeakRef',           'decodeURI',
  'decodeURIComponent',   'encodeURI',         'encodeURIComponent',
  'escape',               'unescape',          'eval',
  'isFinite',             'isNaN',             'SharedArrayBuffer',
  'Atomics',              'WebAssembly'
]