summaryrefslogtreecommitdiff
path: root/tests/specs/run/_015_duplicate_parallel_import
diff options
context:
space:
mode:
Diffstat (limited to 'tests/specs/run/_015_duplicate_parallel_import')
-rw-r--r--tests/specs/run/_015_duplicate_parallel_import/015_duplicate_parallel_import.js20
-rw-r--r--tests/specs/run/_015_duplicate_parallel_import/015_duplicate_parallel_import.js.out1
-rw-r--r--tests/specs/run/_015_duplicate_parallel_import/__test__.jsonc4
-rw-r--r--tests/specs/run/_015_duplicate_parallel_import/mod1.ts17
-rw-r--r--tests/specs/run/_015_duplicate_parallel_import/print_hello.ts3
-rw-r--r--tests/specs/run/_015_duplicate_parallel_import/subdir2/mod2.ts9
6 files changed, 54 insertions, 0 deletions
diff --git a/tests/specs/run/_015_duplicate_parallel_import/015_duplicate_parallel_import.js b/tests/specs/run/_015_duplicate_parallel_import/015_duplicate_parallel_import.js
new file mode 100644
index 000000000..136d80f46
--- /dev/null
+++ b/tests/specs/run/_015_duplicate_parallel_import/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("./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/specs/run/_015_duplicate_parallel_import/015_duplicate_parallel_import.js.out b/tests/specs/run/_015_duplicate_parallel_import/015_duplicate_parallel_import.js.out
new file mode 100644
index 000000000..e965047ad
--- /dev/null
+++ b/tests/specs/run/_015_duplicate_parallel_import/015_duplicate_parallel_import.js.out
@@ -0,0 +1 @@
+Hello
diff --git a/tests/specs/run/_015_duplicate_parallel_import/__test__.jsonc b/tests/specs/run/_015_duplicate_parallel_import/__test__.jsonc
new file mode 100644
index 000000000..44fe479e2
--- /dev/null
+++ b/tests/specs/run/_015_duplicate_parallel_import/__test__.jsonc
@@ -0,0 +1,4 @@
+{
+ "args": "run --quiet --reload --allow-read 015_duplicate_parallel_import.js",
+ "output": "015_duplicate_parallel_import.js.out"
+}
diff --git a/tests/specs/run/_015_duplicate_parallel_import/mod1.ts b/tests/specs/run/_015_duplicate_parallel_import/mod1.ts
new file mode 100644
index 000000000..5e58f432e
--- /dev/null
+++ b/tests/specs/run/_015_duplicate_parallel_import/mod1.ts
@@ -0,0 +1,17 @@
+import { printHello2, returnsFoo } from "./subdir2/mod2.ts";
+
+export function returnsHi(): string {
+ return "Hi";
+}
+
+export function returnsFoo2(): string {
+ return returnsFoo();
+}
+
+export function printHello3() {
+ printHello2();
+}
+
+export function throwsError() {
+ throw Error("exception from mod1");
+}
diff --git a/tests/specs/run/_015_duplicate_parallel_import/print_hello.ts b/tests/specs/run/_015_duplicate_parallel_import/print_hello.ts
new file mode 100644
index 000000000..b9c0ad527
--- /dev/null
+++ b/tests/specs/run/_015_duplicate_parallel_import/print_hello.ts
@@ -0,0 +1,3 @@
+export function printHello() {
+ console.log("Hello");
+}
diff --git a/tests/specs/run/_015_duplicate_parallel_import/subdir2/mod2.ts b/tests/specs/run/_015_duplicate_parallel_import/subdir2/mod2.ts
new file mode 100644
index 000000000..9071d0aeb
--- /dev/null
+++ b/tests/specs/run/_015_duplicate_parallel_import/subdir2/mod2.ts
@@ -0,0 +1,9 @@
+import { printHello } from "../print_hello.ts";
+
+export function returnsFoo(): string {
+ return "Foo";
+}
+
+export function printHello2() {
+ printHello();
+}