summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/ports/webassembly/register_js_module.js39
-rw-r--r--tests/ports/webassembly/register_js_module.js.exp10
2 files changed, 49 insertions, 0 deletions
diff --git a/tests/ports/webassembly/register_js_module.js b/tests/ports/webassembly/register_js_module.js
index b512f2c0d..f58d12e50 100644
--- a/tests/ports/webassembly/register_js_module.js
+++ b/tests/ports/webassembly/register_js_module.js
@@ -1,6 +1,45 @@
+// Test the registerJsModule() public API method.
+
import(process.argv[2]).then((mp) => {
mp.loadMicroPython().then((py) => {
+ // Simple module.
py.registerJsModule("js_module", { y: 2 });
py.runPython("import js_module; print(js_module); print(js_module.y)");
+
+ // Module with functions.
+ // In particular test how "this" behaves.
+ py.registerJsModule("js_module2", {
+ yes: true,
+ add1(x) {
+ return x + 1;
+ },
+ getThis() {
+ return this;
+ },
+ });
+
+ console.log("====");
+
+ // Test using simple import.
+ py.runPython(`
+import js_module2
+
+print(js_module2.yes)
+print(js_module2.add1(1))
+print(js_module2.getThis())
+print(js_module2.getThis().yes)
+`);
+
+ console.log("====");
+
+ // Test using "from ... import".
+ py.runPython(`
+from js_module2 import yes, add1, getThis
+
+print(yes)
+print(add1(2))
+print(getThis())
+print(getThis().yes)
+`);
});
});
diff --git a/tests/ports/webassembly/register_js_module.js.exp b/tests/ports/webassembly/register_js_module.js.exp
index 6e2bad3ce..34bfd345d 100644
--- a/tests/ports/webassembly/register_js_module.js.exp
+++ b/tests/ports/webassembly/register_js_module.js.exp
@@ -1,2 +1,12 @@
<JsProxy 2>
2
+====
+True
+2
+<JsProxy 3>
+True
+====
+True
+3
+<JsProxy 3>
+True