[gjs/esm/dynamic-imports: 4/5] WIP - dynamic imports tests




commit 0b49cfae30150354f1d13d6417f18543d791ab4c
Author: Philip Chimento <philip chimento gmail com>
Date:   Mon Dec 14 17:39:54 2020 -0800

    WIP - dynamic imports tests

 installed-tests/js/.eslintrc.yml         |  1 +
 installed-tests/js/jsunit.gresources.xml |  1 +
 installed-tests/js/modules/say.js        |  7 +++++++
 installed-tests/js/testESModules.js      | 20 ++++++++++++++++++++
 4 files changed, 29 insertions(+)
---
diff --git a/installed-tests/js/.eslintrc.yml b/installed-tests/js/.eslintrc.yml
index 28ec04c6..c1a4c9bd 100644
--- a/installed-tests/js/.eslintrc.yml
+++ b/installed-tests/js/.eslintrc.yml
@@ -35,5 +35,6 @@ overrides:
       - testESModules.js
       - modules/importmeta.js
       - modules/exports.js
+      - modules/say.js
     parserOptions:
       sourceType: module
diff --git a/installed-tests/js/jsunit.gresources.xml b/installed-tests/js/jsunit.gresources.xml
index 3e100b1b..624ac738 100644
--- a/installed-tests/js/jsunit.gresources.xml
+++ b/installed-tests/js/jsunit.gresources.xml
@@ -21,6 +21,7 @@
     <file>modules/mutualImport/a.js</file>
     <file>modules/mutualImport/b.js</file>
     <file>modules/overrides/GIMarshallingTests.js</file>
+    <file>modules/say.js</file>
     <file>modules/subA/subB/__init__.js</file>
     <file>modules/subA/subB/baz.js</file>
     <file>modules/subA/subB/foobar.js</file>
diff --git a/installed-tests/js/modules/say.js b/installed-tests/js/modules/say.js
new file mode 100644
index 00000000..0e543cae
--- /dev/null
+++ b/installed-tests/js/modules/say.js
@@ -0,0 +1,7 @@
+export function say(str) {
+    return `<( ${str} )`;
+}
+
+export default function () {
+    return 'default export';
+}
diff --git a/installed-tests/js/testESModules.js b/installed-tests/js/testESModules.js
index d1b7210d..a36cccc5 100644
--- a/installed-tests/js/testESModules.js
+++ b/installed-tests/js/testESModules.js
@@ -77,3 +77,23 @@ describe('Builtin ES modules', function () {
         expect(exit).toBe(system.exit);
     });
 });
+
+describe('Dynamic imports', function () {
+    let module;
+    beforeEach(async function () {
+        try {
+            module = await import('resource:///org/gjs/jsunit/modules/say.js');
+        } catch (err) {
+            logError(err);
+            fail();
+        }
+    });
+
+    it('default import', function () {
+        expect(module.default()).toEqual('default export');
+    });
+
+    it('named import', function () {
+        expect(module.say('hi')).toEqual('<( hi )');
+    });
+});


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]