oracle / graaljs

GraalJS – A high-performance, ECMAScript compliant, and embeddable JavaScript runtime for Java
https://www.graalvm.org/javascript/
Universal Permissive License v1.0
1.82k stars 192 forks source link

Can't run tests in a polyglot manner using npm #364

Open janehmueller opened 4 years ago

janehmueller commented 4 years ago

Hi there,

I’m trying to run a javascript test in a polyglot manner (using GraalVM CE 20.1.0 on MacOS) and have issues starting npm in a polyglot context (using mocha - shouldn’t matter though).

I've uploaded the code to reproduce the issue to https://github.com/janehmueller/graaljs-polyglot-test/

One note: the npm script does not support the CLI argument --polyglot. Adding it manually doesn’t fix the issue either though since the npm-cli is started in a new process and the flag is not passed to the new process (not quite sure how that works in the script).

I get the following error when running my tests via npm --jvm test:

 add
    1) should add numbers correctly in python

  0 passing (151ms)
  1 failing

  1) add
       should add numbers correctly in python:
     Error: No language for id python found. Supported languages are: [js]

The code in question var add = Polyglot.eval("python", "2 + 3"); works fine in a polyglot node shell started via node --jvm --polyglot.

iamstolis commented 4 years ago

the npm script does not support the CLI argument --polyglot.

Thank you for the report. You are right, we should add the handling of this special option into our npm script.

Adding it manually doesn’t fix the issue either though since the npm-cli is started in a new process and the flag is not passed to the new process (not quite sure how that works in the script).

Propagation of configuration options into child processes is a bit tricky. We use environment variables for this purpose. Your test-case will pass if you set NODE_POLYGLOT_OPTIONS environment variable to --polyglot. Of course, we should improve our handling of this option in node launcher such that this environment variable is set for you when you pass --polyglot option on the command line.

wirthi commented 3 years ago

(internally tracked as GR-27607)