mobile-dev-inc / maestro

Painless Mobile UI Automation
https://maestro.mobile.dev/
Apache License 2.0
5.66k stars 255 forks source link

Importing JS modules (both CJS and ESM) doesn't work in GraalJS #1637

Open valdero opened 8 months ago

valdero commented 8 months ago

Describe the bug Graaljs supports importing CommonJS or ECMAScript modules. However, due to maestro's GraalJsEngine implementation, no module imports work currently.

This most likely happens as Context.newBuilder("js") is missing .allowIO(true) here: https://github.com/mobile-dev-inc/maestro/blob/main/maestro-client/src/main/java/maestro/js/GraalJsEngine.kt#L83

See more info on module imports in the graalVM reference manual: https://www.graalvm.org/latest/reference-manual/js/Modules/#ecmascript-modules-esm

To Reproduce

  1. Create two js files, e.g. main.js and env.mjs
// main.js
import { env } from "./two.mjs";

const testImport = () => {
  console.log(`${env.URL}`);
  return env.URL;
};

output.url = testImport();
// env.mjs
export const env = {
  URL: "https://example.com",
  ANOTHER_URL: "https://another-example.com",
};
  1. Include main.js in e.g. main.yaml
    appId: com.example.myapplication
    jsEngine: graaljs
    ---
    - runScript: main.js
    - evalScript: ${console.log(output.url)}
  2. Run maestro test main.yaml

Expected behavior Importing CommonJS or ECMAScript modules should work.

Screenshots Currently maestro tries to evaluate the import as a script.

Screenshot 2023-12-30 at 0 28 29
JohnValanidas commented 8 months ago

Is there any traction on this issue? Our team is evaluating Maestro, and we're running into an issue similar to the above.

yonice7 commented 7 months ago

Having the same problem here

karamangokhan commented 6 months ago

same issue

monaelaidy commented 3 months ago

Same issue :(

tiagodread commented 2 months ago

Hey @axelniklasson @igorsmotto any expectations for fixing this bug?

bartekpacia commented 2 months ago

hey @tiagodread! Bartek from mobile.dev team here. I see this issue is highly requested. I'll try to prioritize it in the coming weeks, because it looks like the benefit/effort required ratio is pretty good here.

In the meantime, of course, we're always happy to accept contributions.

itinsley-cnd commented 1 month ago

Same issue.