summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-02-22 23:21:05 +0100
committerGitHub <noreply@github.com>2023-02-22 23:21:05 +0100
commit1c14127c4f54d815b3e1be48bddd5198dcb33a50 (patch)
tree56dbbea5e9a39fc95d3c722811b47bce08e21b59 /cli/tests
parentc18e0d1d37878bb4441f7f8d339cc23ac8e68448 (diff)
feat: support bare specifier resolution with package.json (#17864)
This commit enables resolution of "bare specifiers" (eg. "import express from 'express';") if a "package.json" file is discovered. It's a step towards being able to run projects authored for Node.js without any changes. With this commit we are able to successfully run Vite projects without any changes to the user code. --------- Co-authored-by: David Sherret <dsherret@gmail.com>
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/run_tests.rs3
-rw-r--r--cli/tests/testdata/run/with_package_json/no_deno_json/main.out6
-rw-r--r--cli/tests/testdata/run/with_package_json/no_deno_json/main.ts6
-rw-r--r--cli/tests/testdata/run/with_package_json/no_deno_json/package.json3
-rw-r--r--cli/tests/testdata/run/with_package_json/with_stop/main.out3
-rw-r--r--cli/tests/testdata/run/with_package_json/with_stop/some/nested/dir/main.ts8
6 files changed, 18 insertions, 11 deletions
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs
index 10ff6d2e0..f30e7ce69 100644
--- a/cli/tests/integration/run_tests.rs
+++ b/cli/tests/integration/run_tests.rs
@@ -2750,7 +2750,7 @@ itest!(config_not_auto_discovered_for_remote_script {
});
itest!(package_json_auto_discovered_for_local_script_log {
- args: "run -L debug no_deno_json/main.ts",
+ args: "run -L debug -A no_deno_json/main.ts",
output: "run/with_package_json/no_deno_json/main.out",
maybe_cwd: Some("run/with_package_json/"),
envs: env_vars_for_npm_tests_no_sync_download(),
@@ -2766,6 +2766,7 @@ itest!(
maybe_cwd: Some("run/with_package_json/"),
envs: env_vars_for_npm_tests_no_sync_download(),
http_server: true,
+ exit_code: 1,
}
);
diff --git a/cli/tests/testdata/run/with_package_json/no_deno_json/main.out b/cli/tests/testdata/run/with_package_json/no_deno_json/main.out
index c0dab77d0..a41c8787a 100644
--- a/cli/tests/testdata/run/with_package_json/no_deno_json/main.out
+++ b/cli/tests/testdata/run/with_package_json/no_deno_json/main.out
@@ -1,3 +1,9 @@
[WILDCARD]package.json file found at '[WILDCARD]with_package_json[WILDCARD]package.json'
[WILDCARD]
ok
+[Chalk] {
+ constructor: [Function],
+ Instance: [Class: ChalkClass],
+ supportsColor: false,
+ stderr: [Chalk] { constructor: [Function], Instance: [Class: ChalkClass], supportsColor: false }
+}
diff --git a/cli/tests/testdata/run/with_package_json/no_deno_json/main.ts b/cli/tests/testdata/run/with_package_json/no_deno_json/main.ts
index daefa8f60..1e6e50040 100644
--- a/cli/tests/testdata/run/with_package_json/no_deno_json/main.ts
+++ b/cli/tests/testdata/run/with_package_json/no_deno_json/main.ts
@@ -1,6 +1,4 @@
-// TODO(bartlomieju): currently we don't support actual bare specifier
-// imports; this will be done in a follow up PR.
-// import express from "express";
+import chalk from "chalk";
-// console.log(express);
console.log("ok");
+console.log(chalk);
diff --git a/cli/tests/testdata/run/with_package_json/no_deno_json/package.json b/cli/tests/testdata/run/with_package_json/no_deno_json/package.json
index 9ee3f39a8..a85b890a8 100644
--- a/cli/tests/testdata/run/with_package_json/no_deno_json/package.json
+++ b/cli/tests/testdata/run/with_package_json/no_deno_json/package.json
@@ -1,6 +1,7 @@
{
"dependencies": {
- "@denotest/check-error": "1.0.0"
+ "@denotest/check-error": "1.0.0",
+ "chalk": "4"
},
"devDependencies": {
"@denotest/cjs-default-export": "1.0.0"
diff --git a/cli/tests/testdata/run/with_package_json/with_stop/main.out b/cli/tests/testdata/run/with_package_json/with_stop/main.out
index e7ef053e4..b199faf8d 100644
--- a/cli/tests/testdata/run/with_package_json/with_stop/main.out
+++ b/cli/tests/testdata/run/with_package_json/with_stop/main.out
@@ -1,4 +1,5 @@
[WILDCARD]Config file found at '[WILDCARD]with_package_json[WILDCARD]with_stop[WILDCARD]some[WILDCARD]nested[WILDCARD]deno.json'
[WILDCARD]No package.json file found
[WILDCARD]
-ok
+error: Relative import path "chalk" not prefixed with / or ./ or ../
+ at file:///[WILDCARD]with_package_json/with_stop/some/nested/dir/main.ts:3:19
diff --git a/cli/tests/testdata/run/with_package_json/with_stop/some/nested/dir/main.ts b/cli/tests/testdata/run/with_package_json/with_stop/some/nested/dir/main.ts
index daefa8f60..6016470a1 100644
--- a/cli/tests/testdata/run/with_package_json/with_stop/some/nested/dir/main.ts
+++ b/cli/tests/testdata/run/with_package_json/with_stop/some/nested/dir/main.ts
@@ -1,6 +1,6 @@
-// TODO(bartlomieju): currently we don't support actual bare specifier
-// imports; this will be done in a follow up PR.
-// import express from "express";
+// This import should fail, because `package.json` is not discovered, as we're
+// stopping the discovery when encountering `deno.json`.
+import chalk from "chalk";
-// console.log(express);
console.log("ok");
+console.log(chalk);