maestro icon indicating copy to clipboard operation
maestro copied to clipboard

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

Open valdero opened this issue 1 year ago • 8 comments

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)}
  1. 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

valdero avatar Dec 29 '23 22:12 valdero

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

JohnValanidas avatar Jan 16 '24 19:01 JohnValanidas

Having the same problem here

yonice7 avatar Jan 30 '24 20:01 yonice7

same issue

karamangokhan avatar Feb 19 '24 12:02 karamangokhan

Same issue :(

monaelaidy avatar Jun 07 '24 14:06 monaelaidy

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

tiagodread avatar Jul 10 '24 16:07 tiagodread

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.

bartekpacia avatar Jul 12 '24 23:07 bartekpacia

Same issue.

itinsley-cnd avatar Aug 15 '24 06:08 itinsley-cnd