diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/013_dynamic_import.test (renamed from tests/013_dynamic_import.disabled) | 0 | ||||
-rw-r--r-- | tests/014_duplicate_import.test (renamed from tests/014_duplicate_import.disabled) | 0 | ||||
-rw-r--r-- | tests/015_duplicate_parallel_import.js | 20 | ||||
-rw-r--r-- | tests/015_duplicate_parallel_import.js.out | 1 | ||||
-rw-r--r-- | tests/015_duplicate_parallel_import.test | 2 | ||||
-rw-r--r-- | tests/error_014_catch_dynamic_import_error.js | 31 | ||||
-rw-r--r-- | tests/error_014_catch_dynamic_import_error.js.out | 12 | ||||
-rw-r--r-- | tests/error_014_catch_dynamic_import_error.test | 2 | ||||
-rw-r--r-- | tests/subdir/indirect_import_error.js | 1 | ||||
-rw-r--r-- | tests/subdir/indirect_throws.js | 1 | ||||
-rw-r--r-- | tests/subdir/throws.js | 5 |
11 files changed, 75 insertions, 0 deletions
diff --git a/tests/013_dynamic_import.disabled b/tests/013_dynamic_import.test index 8fe463b20..8fe463b20 100644 --- a/tests/013_dynamic_import.disabled +++ b/tests/013_dynamic_import.test diff --git a/tests/014_duplicate_import.disabled b/tests/014_duplicate_import.test index 57d5b6e8b..57d5b6e8b 100644 --- a/tests/014_duplicate_import.disabled +++ b/tests/014_duplicate_import.test diff --git a/tests/015_duplicate_parallel_import.js b/tests/015_duplicate_parallel_import.js new file mode 100644 index 000000000..37033cfa2 --- /dev/null +++ b/tests/015_duplicate_parallel_import.js @@ -0,0 +1,20 @@ +// Importing the same module in parallel, the module should only be +// instantiated once. + +const promises = new Array(100) + .fill(null) + .map(() => import("./subdir/mod1.ts")); + +Promise.all(promises).then(imports => { + const mod = imports.reduce((first, cur) => { + if (typeof first !== "object") { + throw new Error("Expected an object."); + } + if (first !== cur) { + throw new Error("More than one instance of the same module."); + } + return first; + }); + + mod.printHello3(); +}); diff --git a/tests/015_duplicate_parallel_import.js.out b/tests/015_duplicate_parallel_import.js.out new file mode 100644 index 000000000..e965047ad --- /dev/null +++ b/tests/015_duplicate_parallel_import.js.out @@ -0,0 +1 @@ +Hello diff --git a/tests/015_duplicate_parallel_import.test b/tests/015_duplicate_parallel_import.test new file mode 100644 index 000000000..ec8c79b21 --- /dev/null +++ b/tests/015_duplicate_parallel_import.test @@ -0,0 +1,2 @@ +args: tests/015_duplicate_parallel_import.js --reload +output: tests/015_duplicate_parallel_import.js.out diff --git a/tests/error_014_catch_dynamic_import_error.js b/tests/error_014_catch_dynamic_import_error.js new file mode 100644 index 000000000..ad3735fc3 --- /dev/null +++ b/tests/error_014_catch_dynamic_import_error.js @@ -0,0 +1,31 @@ +(async () => { + try { + await import("does not exist"); + } catch (err) { + console.log("Caught direct dynamic import error."); + console.log(err); + } + + try { + await import("./subdir/indirect_import_error.js"); + } catch (err) { + console.log("Caught indirect direct dynamic import error."); + console.log(err); + } + + try { + await import("./subdir/throws.js"); + } catch (err) { + console.log("Caught error thrown by dynamically imported module."); + console.log(err); + } + + try { + await import("./subdir/indirect_throws.js"); + } catch (err) { + console.log( + "Caught error thrown indirectly by dynamically imported module." + ); + console.log(err); + } +})(); diff --git a/tests/error_014_catch_dynamic_import_error.js.out b/tests/error_014_catch_dynamic_import_error.js.out new file mode 100644 index 000000000..c18b680a1 --- /dev/null +++ b/tests/error_014_catch_dynamic_import_error.js.out @@ -0,0 +1,12 @@ +Caught direct dynamic import error. +TypeError: relative import path "does not exist" not prefixed with / or ./ or ../ + +Caught indirect direct dynamic import error. +TypeError: relative import path "does not exist either" not prefixed with / or ./ or ../ + +Caught error thrown by dynamically imported module. +Error: An error + at file:///[WILDCARD]tests/subdir/throws.js:5:7 +Caught error thrown indirectly by dynamically imported module. +Error: An error + at file:///[WILDCARD]tests/subdir/throws.js:5:7 diff --git a/tests/error_014_catch_dynamic_import_error.test b/tests/error_014_catch_dynamic_import_error.test new file mode 100644 index 000000000..8345ad1c8 --- /dev/null +++ b/tests/error_014_catch_dynamic_import_error.test @@ -0,0 +1,2 @@ +args: tests/error_014_catch_dynamic_import_error.js --reload +output: tests/error_014_catch_dynamic_import_error.js.out diff --git a/tests/subdir/indirect_import_error.js b/tests/subdir/indirect_import_error.js new file mode 100644 index 000000000..84011d291 --- /dev/null +++ b/tests/subdir/indirect_import_error.js @@ -0,0 +1 @@ +export * from "does not exist either"; diff --git a/tests/subdir/indirect_throws.js b/tests/subdir/indirect_throws.js new file mode 100644 index 000000000..e1810a66c --- /dev/null +++ b/tests/subdir/indirect_throws.js @@ -0,0 +1 @@ +export * from "./throws.js"; diff --git a/tests/subdir/throws.js b/tests/subdir/throws.js new file mode 100644 index 000000000..b77e7104f --- /dev/null +++ b/tests/subdir/throws.js @@ -0,0 +1,5 @@ +export function boo() { + console.log("Boo!"); +} + +throw new Error("An error"); |