1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#!/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
total=0
report () {
exit_code=$?
total=$((total + 1))
if test $exit_code -eq 0; then
echo "ok $total - $1"
else
echo "not ok $total - $1"
fi
}
# Avoid interference in the profiler tests from stray environment variable
unset GJS_ENABLE_PROFILER
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"
cat <<EOF >dynamicImplicitMainloopImportee.js
export const EXIT_CODE = 21;
EOF
cat <<EOF >dynamicImplicitMainloop.js
import("./dynamicImplicitMainloopImportee.js")
.then(({ EXIT_CODE }) => {
imports.system.exit(EXIT_CODE);
});
EOF
$gjs dynamicImplicitMainloop.js
test $? -eq 21
report "ensure dynamic imports resolve without an explicit mainloop"
cat <<EOF >dynamicTopLevelAwaitImportee.js
export const EXIT_CODE = 32;
EOF
cat <<EOF >dynamicTopLevelAwait.js
const {EXIT_CODE} = await import("./dynamicTopLevelAwaitImportee.js")
const system = await import('system');
system.exit(EXIT_CODE);
EOF
$gjs -m dynamicTopLevelAwait.js
test $? -eq 32
report "ensure top level await can import modules"
rm -f doubledynamic.js doubledynamicImportee.js \
dynamicImplicitMainloop.js dynamicImplicitMainloopImportee.js \
dynamicTopLevelAwait.js dynamicTopLevelAwaitImportee.js
echo "1..$total"
|