summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/npm_tests.rs25
-rw-r--r--cli/tests/testdata/npm/imports_package_json/import_not_defined.js3
-rw-r--r--cli/tests/testdata/npm/imports_package_json/import_not_defined.out6
-rw-r--r--cli/tests/testdata/npm/imports_package_json/main.js4
-rw-r--r--cli/tests/testdata/npm/imports_package_json/main.out4
-rw-r--r--cli/tests/testdata/npm/imports_package_json/package.json6
-rw-r--r--cli/tests/testdata/npm/imports_package_json/sub_path_import_not_defined.js3
-rw-r--r--cli/tests/testdata/npm/imports_package_json/sub_path_import_not_defined.out6
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/hi.js1
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/import_not_defined.js3
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/main.js7
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/package.json16
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/sub_path/bye.js1
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/sub_path/import_not_defined.js4
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/sub_path/main.js3
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/sub_path/package.json6
16 files changed, 98 insertions, 0 deletions
diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs
index 5104036e3..927e83475 100644
--- a/cli/tests/integration/npm_tests.rs
+++ b/cli/tests/integration/npm_tests.rs
@@ -2505,3 +2505,28 @@ console.log(add(1, 2));
.run();
output.assert_matches_text("Check file:///[WILDCARD]/project-b/main.ts\n");
}
+
+itest!(imports_package_json {
+ args: "run --node-modules-dir=false npm/imports_package_json/main.js",
+ output: "npm/imports_package_json/main.out",
+ envs: env_vars_for_npm_tests(),
+ http_server: true,
+});
+
+itest!(imports_package_json_import_not_defined {
+ args:
+ "run --node-modules-dir=false npm/imports_package_json/import_not_defined.js",
+ output: "npm/imports_package_json/import_not_defined.out",
+ envs: env_vars_for_npm_tests(),
+ exit_code: 1,
+ http_server: true,
+});
+
+itest!(imports_package_json_sub_path_import_not_defined {
+ args:
+ "run --node-modules-dir=false npm/imports_package_json/sub_path_import_not_defined.js",
+ output: "npm/imports_package_json/sub_path_import_not_defined.out",
+ envs: env_vars_for_npm_tests(),
+ exit_code: 1,
+ http_server: true,
+});
diff --git a/cli/tests/testdata/npm/imports_package_json/import_not_defined.js b/cli/tests/testdata/npm/imports_package_json/import_not_defined.js
new file mode 100644
index 000000000..dc4d2df16
--- /dev/null
+++ b/cli/tests/testdata/npm/imports_package_json/import_not_defined.js
@@ -0,0 +1,3 @@
+import data from "@denotest/imports-package-json/import-not-defined";
+
+console.log(data);
diff --git a/cli/tests/testdata/npm/imports_package_json/import_not_defined.out b/cli/tests/testdata/npm/imports_package_json/import_not_defined.out
new file mode 100644
index 000000000..3580d9007
--- /dev/null
+++ b/cli/tests/testdata/npm/imports_package_json/import_not_defined.out
@@ -0,0 +1,6 @@
+Download http://localhost:4545/npm/registry/@denotest/imports-package-json
+Download http://localhost:4545/npm/registry/@denotest/imports-package-json/1.0.0.tgz
+error: Could not resolve '#not-defined' from 'file:///[WILDCARD]/@denotest/imports-package-json/1.0.0/import_not_defined.js'.
+
+Caused by:
+ [ERR_PACKAGE_IMPORT_NOT_DEFINED] Package import specifier "#not-defined" is not defined in package [WILDCARD]package.json imported from [WILDCARD]import_not_defined.js
diff --git a/cli/tests/testdata/npm/imports_package_json/main.js b/cli/tests/testdata/npm/imports_package_json/main.js
new file mode 100644
index 000000000..cd7bbf8e9
--- /dev/null
+++ b/cli/tests/testdata/npm/imports_package_json/main.js
@@ -0,0 +1,4 @@
+import data from "@denotest/imports-package-json";
+
+console.log(data.hi);
+console.log(data.bye);
diff --git a/cli/tests/testdata/npm/imports_package_json/main.out b/cli/tests/testdata/npm/imports_package_json/main.out
new file mode 100644
index 000000000..f006f18d5
--- /dev/null
+++ b/cli/tests/testdata/npm/imports_package_json/main.out
@@ -0,0 +1,4 @@
+Download http://localhost:4545/npm/registry/@denotest/imports-package-json
+Download http://localhost:4545/npm/registry/@denotest/imports-package-json/1.0.0.tgz
+hi
+bye
diff --git a/cli/tests/testdata/npm/imports_package_json/package.json b/cli/tests/testdata/npm/imports_package_json/package.json
new file mode 100644
index 000000000..cb6a08d1a
--- /dev/null
+++ b/cli/tests/testdata/npm/imports_package_json/package.json
@@ -0,0 +1,6 @@
+{
+ "name": "my-test",
+ "dependencies": {
+ "@denotest/imports-package-json": "1.0.0"
+ }
+}
diff --git a/cli/tests/testdata/npm/imports_package_json/sub_path_import_not_defined.js b/cli/tests/testdata/npm/imports_package_json/sub_path_import_not_defined.js
new file mode 100644
index 000000000..f1097aa06
--- /dev/null
+++ b/cli/tests/testdata/npm/imports_package_json/sub_path_import_not_defined.js
@@ -0,0 +1,3 @@
+import data from "@denotest/imports-package-json/sub-path-import-not-defined";
+
+console.log(data);
diff --git a/cli/tests/testdata/npm/imports_package_json/sub_path_import_not_defined.out b/cli/tests/testdata/npm/imports_package_json/sub_path_import_not_defined.out
new file mode 100644
index 000000000..04a21c99e
--- /dev/null
+++ b/cli/tests/testdata/npm/imports_package_json/sub_path_import_not_defined.out
@@ -0,0 +1,6 @@
+Download http://localhost:4545/npm/registry/@denotest/imports-package-json
+Download http://localhost:4545/npm/registry/@denotest/imports-package-json/1.0.0.tgz
+error: Could not resolve '#hi' from 'file:///[WILDCARD]/@denotest/imports-package-json/1.0.0/sub_path/import_not_defined.js'.
+
+Caused by:
+ [ERR_PACKAGE_IMPORT_NOT_DEFINED] Package import specifier "#hi" is not defined in package [WILDCARD]sub_path[WILDCARD]package.json imported from [WILDCARD]import_not_defined.js
diff --git a/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/hi.js b/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/hi.js
new file mode 100644
index 000000000..407090812
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/hi.js
@@ -0,0 +1 @@
+export default "hi";
diff --git a/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/import_not_defined.js b/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/import_not_defined.js
new file mode 100644
index 000000000..07864fd2c
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/import_not_defined.js
@@ -0,0 +1,3 @@
+import notDefined from "#not-defined";
+
+export default notDefined;
diff --git a/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/main.js b/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/main.js
new file mode 100644
index 000000000..46625479e
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/main.js
@@ -0,0 +1,7 @@
+import hi from "#hi";
+import bye from "./sub_path/main.js";
+
+export default {
+ hi,
+ bye,
+};
diff --git a/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/package.json b/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/package.json
new file mode 100644
index 000000000..a4fbc8889
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/package.json
@@ -0,0 +1,16 @@
+{
+ "name": "imports-package-json",
+ "type": "module",
+ "version": "1.0.0",
+ "description": "",
+ "license": "ISC",
+ "author": "",
+ "exports": {
+ ".": "./main.js",
+ "./import-not-defined": "./import_not_defined.js",
+ "./sub-path-import-not-defined": "./sub_path/import_not_defined.js"
+ },
+ "imports": {
+ "#hi": "./hi.js"
+ }
+}
diff --git a/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/sub_path/bye.js b/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/sub_path/bye.js
new file mode 100644
index 000000000..6fc719e48
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/sub_path/bye.js
@@ -0,0 +1 @@
+export default "bye";
diff --git a/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/sub_path/import_not_defined.js b/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/sub_path/import_not_defined.js
new file mode 100644
index 000000000..ffaa2b1ad
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/sub_path/import_not_defined.js
@@ -0,0 +1,4 @@
+// this won't be defined in the closest package.json and will fail
+import hi from "#hi";
+
+export default hi;
diff --git a/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/sub_path/main.js b/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/sub_path/main.js
new file mode 100644
index 000000000..260ca79ae
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/sub_path/main.js
@@ -0,0 +1,3 @@
+import bye from "#bye";
+
+export default bye;
diff --git a/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/sub_path/package.json b/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/sub_path/package.json
new file mode 100644
index 000000000..3f2c2bbd8
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/imports-package-json/1.0.0/sub_path/package.json
@@ -0,0 +1,6 @@
+{
+ "type": "module",
+ "imports": {
+ "#bye": "./bye.js"
+ }
+}