summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/run_tests.rs33
-rw-r--r--cli/tests/testdata/import_assertions/data.json6
-rw-r--r--cli/tests/testdata/import_assertions/dynamic_error.out5
-rw-r--r--cli/tests/testdata/import_assertions/dynamic_error.ts3
-rw-r--r--cli/tests/testdata/import_assertions/dynamic_import.out2
-rw-r--r--cli/tests/testdata/import_assertions/dynamic_import.ts3
-rw-r--r--cli/tests/testdata/import_assertions/static_error.out5
-rw-r--r--cli/tests/testdata/import_assertions/static_error.ts3
-rw-r--r--cli/tests/testdata/import_assertions/static_export.out2
-rw-r--r--cli/tests/testdata/import_assertions/static_export.ts3
-rw-r--r--cli/tests/testdata/import_assertions/static_import.out2
-rw-r--r--cli/tests/testdata/import_assertions/static_import.ts3
-rw-r--r--cli/tests/testdata/import_assertions/static_reexport.ts1
-rw-r--r--cli/tests/testdata/import_assertions/type_check.out5
-rw-r--r--cli/tests/testdata/import_assertions/type_check.ts3
15 files changed, 79 insertions, 0 deletions
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs
index b6929b58a..c04e4731c 100644
--- a/cli/tests/integration/run_tests.rs
+++ b/cli/tests/integration/run_tests.rs
@@ -2407,3 +2407,36 @@ fn issue12807() {
.unwrap();
assert!(status.success());
}
+
+itest!(import_assertions_static_import {
+ args: "run --allow-read import_assertions/static_import.ts",
+ output: "import_assertions/static_import.out",
+});
+
+itest!(import_assertions_static_export {
+ args: "run --allow-read import_assertions/static_export.ts",
+ output: "import_assertions/static_export.out",
+});
+
+itest!(import_assertions_static_error {
+ args: "run --allow-read import_assertions/static_error.ts",
+ output: "import_assertions/static_error.out",
+ exit_code: 1,
+});
+
+itest!(import_assertions_dynamic_import {
+ args: "run --allow-read import_assertions/dynamic_import.ts",
+ output: "import_assertions/dynamic_import.out",
+});
+
+itest!(import_assertions_dynamic_error {
+ args: "run --allow-read import_assertions/dynamic_error.ts",
+ output: "import_assertions/dynamic_error.out",
+ exit_code: 1,
+});
+
+itest!(import_assertions_type_check {
+ args: "run --allow-read import_assertions/type_check.ts",
+ output: "import_assertions/type_check.out",
+ exit_code: 1,
+});
diff --git a/cli/tests/testdata/import_assertions/data.json b/cli/tests/testdata/import_assertions/data.json
new file mode 100644
index 000000000..37b3ee1e0
--- /dev/null
+++ b/cli/tests/testdata/import_assertions/data.json
@@ -0,0 +1,6 @@
+{
+ "a": "b",
+ "c": {
+ "d": 10
+ }
+}
diff --git a/cli/tests/testdata/import_assertions/dynamic_error.out b/cli/tests/testdata/import_assertions/dynamic_error.out
new file mode 100644
index 000000000..1ad40889b
--- /dev/null
+++ b/cli/tests/testdata/import_assertions/dynamic_error.out
@@ -0,0 +1,5 @@
+[WILDCARD]
+error: Uncaught (in promise) TypeError: Expected a "JavaScript" module but loaded a "JSON" module.
+const data = await import("./data.json");
+ ^
+ at async [WILDCARD]dynamic_error.ts:1:14
diff --git a/cli/tests/testdata/import_assertions/dynamic_error.ts b/cli/tests/testdata/import_assertions/dynamic_error.ts
new file mode 100644
index 000000000..2d9c6757f
--- /dev/null
+++ b/cli/tests/testdata/import_assertions/dynamic_error.ts
@@ -0,0 +1,3 @@
+const data = await import("./data.json");
+
+console.log(data);
diff --git a/cli/tests/testdata/import_assertions/dynamic_import.out b/cli/tests/testdata/import_assertions/dynamic_import.out
new file mode 100644
index 000000000..3280e0f53
--- /dev/null
+++ b/cli/tests/testdata/import_assertions/dynamic_import.out
@@ -0,0 +1,2 @@
+[WILDCARD]
+Module { default: { a: "b", c: { d: 10 } } }
diff --git a/cli/tests/testdata/import_assertions/dynamic_import.ts b/cli/tests/testdata/import_assertions/dynamic_import.ts
new file mode 100644
index 000000000..d6983852c
--- /dev/null
+++ b/cli/tests/testdata/import_assertions/dynamic_import.ts
@@ -0,0 +1,3 @@
+const data = await import("./data.json", { assert: { type: "json" } });
+
+console.log(data);
diff --git a/cli/tests/testdata/import_assertions/static_error.out b/cli/tests/testdata/import_assertions/static_error.out
new file mode 100644
index 000000000..8524079de
--- /dev/null
+++ b/cli/tests/testdata/import_assertions/static_error.out
@@ -0,0 +1,5 @@
+[WILDCARD]
+error: An unsupported media type was attempted to be imported as a module.
+ Specifier: [WILDCARD]data.json
+ MediaType: Json
+ at [WILDCARD]static_error.ts:1:18
diff --git a/cli/tests/testdata/import_assertions/static_error.ts b/cli/tests/testdata/import_assertions/static_error.ts
new file mode 100644
index 000000000..0bc3a93f8
--- /dev/null
+++ b/cli/tests/testdata/import_assertions/static_error.ts
@@ -0,0 +1,3 @@
+import data from "./data.json";
+
+console.log(data);
diff --git a/cli/tests/testdata/import_assertions/static_export.out b/cli/tests/testdata/import_assertions/static_export.out
new file mode 100644
index 000000000..42fbc066c
--- /dev/null
+++ b/cli/tests/testdata/import_assertions/static_export.out
@@ -0,0 +1,2 @@
+[WILDCARD]
+{ a: "b", c: { d: 10 } }
diff --git a/cli/tests/testdata/import_assertions/static_export.ts b/cli/tests/testdata/import_assertions/static_export.ts
new file mode 100644
index 000000000..ac3ee694f
--- /dev/null
+++ b/cli/tests/testdata/import_assertions/static_export.ts
@@ -0,0 +1,3 @@
+import data from "./static_reexport.ts";
+
+console.log(data);
diff --git a/cli/tests/testdata/import_assertions/static_import.out b/cli/tests/testdata/import_assertions/static_import.out
new file mode 100644
index 000000000..42fbc066c
--- /dev/null
+++ b/cli/tests/testdata/import_assertions/static_import.out
@@ -0,0 +1,2 @@
+[WILDCARD]
+{ a: "b", c: { d: 10 } }
diff --git a/cli/tests/testdata/import_assertions/static_import.ts b/cli/tests/testdata/import_assertions/static_import.ts
new file mode 100644
index 000000000..180ab75f2
--- /dev/null
+++ b/cli/tests/testdata/import_assertions/static_import.ts
@@ -0,0 +1,3 @@
+import data from "./data.json" assert { type: "json" };
+
+console.log(data);
diff --git a/cli/tests/testdata/import_assertions/static_reexport.ts b/cli/tests/testdata/import_assertions/static_reexport.ts
new file mode 100644
index 000000000..81af428be
--- /dev/null
+++ b/cli/tests/testdata/import_assertions/static_reexport.ts
@@ -0,0 +1 @@
+export { default } from "./data.json" assert { type: "json" };
diff --git a/cli/tests/testdata/import_assertions/type_check.out b/cli/tests/testdata/import_assertions/type_check.out
new file mode 100644
index 000000000..8e1387456
--- /dev/null
+++ b/cli/tests/testdata/import_assertions/type_check.out
@@ -0,0 +1,5 @@
+[WILDCARD]
+error: TS2339 [ERROR]: Property 'foo' does not exist on type '{ a: string; c: { d: number; }; }'.
+console.log(data.foo);
+ ~~~
+ at [WILDCARD]type_check.ts:3:18
diff --git a/cli/tests/testdata/import_assertions/type_check.ts b/cli/tests/testdata/import_assertions/type_check.ts
new file mode 100644
index 000000000..19adb3eae
--- /dev/null
+++ b/cli/tests/testdata/import_assertions/type_check.ts
@@ -0,0 +1,3 @@
+import data from "./data.json" assert { type: "json" };
+
+console.log(data.foo);