[gjs/ewlsh/fix-dynamic-module-resolution: 4/4] Add test for dynamic import resolution




commit a580c92984df1025b6db0d13f09914d7a52fde13
Author: Evan Welsh <contact evanwelsh com>
Date:   Sat Jul 17 15:33:01 2021 -0700

    Add test for dynamic import resolution

 installed-tests/meson.build                       |  9 +++-
 installed-tests/scripts/testCommandLineModules.sh | 54 +++++++++++++++++++++++
 2 files changed, 62 insertions(+), 1 deletion(-)
---
diff --git a/installed-tests/meson.build b/installed-tests/meson.build
index 918b6f82..10ac735a 100644
--- a/installed-tests/meson.build
+++ b/installed-tests/meson.build
@@ -10,21 +10,28 @@ installed_tests_metadir = abs_datadir / 'installed-tests' / meson.project_name()
 # Simple shell script tests #
 
 simple_tests = []
+non_thread_safe = ['CommandLineModules']
 
 # The test scripts need to be ported from shell scripts
 # for clang-cl builds, which do not use BASH-style shells
 if cxx.get_argument_syntax() != 'msvc'
     simple_tests += [
         'CommandLine',
+        'CommandLineModules',
         'Warnings',
     ]
 endif
 
 foreach test : simple_tests
     test_file = files('scripts' / 'test@0@.sh'.format(test))
+    suite = ['Scripts']
+    if test not in non_thread_safe
+        suite += 'thread-safe'
+    endif
 
     test(test, test_file, env: tests_environment, protocol: 'tap',
-        suite: ['Scripts', 'thread-safe'])
+         suite: suite)
+    
 
     test_description_subst = {
         'name': 'test@0@.sh'.format(test),
diff --git a/installed-tests/scripts/testCommandLineModules.sh 
b/installed-tests/scripts/testCommandLineModules.sh
new file mode 100755
index 00000000..8673879b
--- /dev/null
+++ b/installed-tests/scripts/testCommandLineModules.sh
@@ -0,0 +1,54 @@
+#!/bin/sh
+# SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
+# SPDX-FileCopyrightText: 2016 Endless Mobile, Inc.
+# SPDX-FileCopyrightText: 2016 Philip Chimento <philip chimento gmail com>
+
+if test "$GJS_USE_UNINSTALLED_FILES" = "1"; then
+    gjs="$TOP_BUILDDIR/gjs-console"
+else
+    gjs="gjs-console"
+fi
+
+# Avoid interference in the profiler tests from stray environment variable
+unset GJS_ENABLE_PROFILER
+
+# Avoid interference in the warning tests from G_DEBUG=fatal-warnings/criticals
+OLD_G_DEBUG="$G_DEBUG"
+
+cat <<EOF >doubledynamicImportee.js
+export function noop() {}
+EOF
+
+# this JS script should succeed without an error on the second import
+cat <<EOF >doubledynamic.js
+let done = false;
+
+import("./doubledynamicImportee.js")
+    .then(ddi => {
+        ddi.noop();
+    })
+    .finally(() => {
+        if (done)
+            imports.mainloop.quit();
+        done = true;
+    });
+
+import("./doubledynamicImportee.js")
+    .then(ddi => {
+        ddi.noop();
+    })
+    .finally(() => {
+        if (done)
+            imports.mainloop.quit();
+        done = true;
+    });
+
+imports.mainloop.run();
+EOF
+
+$gjs doubledynamic.js
+report "ensure dynamic imports load even if the same import resolves elsewhere first"
+
+rm -f doubledynamic.js doubledynamicImportee.js
+
+echo "1..$total"


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