summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/npm/cache.rs11
-rw-r--r--cli/npm/registry.rs11
-rw-r--r--cli/tests/integration/npm_tests.rs24
-rw-r--r--cli/tests/testdata/npm/README.md18
-rw-r--r--cli/tests/testdata/npm/cjs_local_global_decls/main.out3
-rw-r--r--cli/tests/testdata/npm/cjs_local_global_decls/main.ts1
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/cjs-local-global-decls/1.0.0/index.js4
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/cjs-local-global-decls/1.0.0/package.json4
8 files changed, 66 insertions, 10 deletions
diff --git a/cli/npm/cache.rs b/cli/npm/cache.rs
index 5e6fb7ca8..f3436f7c0 100644
--- a/cli/npm/cache.rs
+++ b/cli/npm/cache.rs
@@ -210,7 +210,16 @@ impl NpmCache {
if response.status() == 404 {
bail!("Could not find npm package tarball at: {}", dist.tarball);
} else if !response.status().is_success() {
- bail!("Bad response: {:?}", response.status());
+ let status = response.status();
+ let maybe_response_text = response.text().await.ok();
+ bail!(
+ "Bad response: {:?}{}",
+ status,
+ match maybe_response_text {
+ Some(text) => format!("\n\n{}", text),
+ None => String::new(),
+ }
+ );
} else {
let bytes = response.bytes().await?;
diff --git a/cli/npm/registry.rs b/cli/npm/registry.rs
index 1604f4b11..ab7d81b75 100644
--- a/cli/npm/registry.rs
+++ b/cli/npm/registry.rs
@@ -302,7 +302,16 @@ impl NpmRegistryApi {
if response.status() == 404 {
Ok(None)
} else if !response.status().is_success() {
- bail!("Bad response: {:?}", response.status());
+ let status = response.status();
+ let maybe_response_text = response.text().await.ok();
+ bail!(
+ "Bad response: {:?}{}",
+ status,
+ match maybe_response_text {
+ Some(text) => format!("\n\n{}", text),
+ None => String::new(),
+ }
+ );
} else {
let bytes = response.bytes().await?;
let package_info = serde_json::from_slice(&bytes)?;
diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs
index 9c4b98241..c46f8e92b 100644
--- a/cli/tests/integration/npm_tests.rs
+++ b/cli/tests/integration/npm_tests.rs
@@ -6,8 +6,7 @@ use test_util as util;
use util::assert_contains;
use util::http_server;
-// NOTE: It's possible to automatically update the npm registry data in the test server
-// by setting the DENO_TEST_UTIL_UPDATE_NPM=1 environment variable.
+// NOTE: See how to make test npm packages at ../testdata/npm/README.md
itest!(esm_module {
args: "run --allow-read --unstable npm/esm/main.js",
@@ -48,6 +47,13 @@ itest!(cjs_sub_path {
http_server: true,
});
+itest!(cjs_local_global_decls {
+ args: "run --allow-read --unstable npm/cjs_local_global_decls/main.ts",
+ output: "npm/cjs_local_global_decls/main.out",
+ envs: env_vars(),
+ http_server: true,
+});
+
itest!(dynamic_import {
args: "run --allow-read --unstable npm/dynamic_import/main.ts",
output: "npm/dynamic_import/main.out",
@@ -238,12 +244,14 @@ fn ensure_registry_files_local() {
let registry_json_path = registry_dir_path
.join(entry.file_name())
.join("registry.json");
- let file_text = std::fs::read_to_string(&registry_json_path).unwrap();
- if file_text.contains("https://registry.npmjs.org/") {
- panic!(
- "file {} contained a reference to the npm registry",
- registry_json_path.display(),
- );
+ if registry_json_path.exists() {
+ let file_text = std::fs::read_to_string(&registry_json_path).unwrap();
+ if file_text.contains("https://registry.npmjs.org/") {
+ panic!(
+ "file {} contained a reference to the npm registry",
+ registry_json_path.display(),
+ );
+ }
}
}
}
diff --git a/cli/tests/testdata/npm/README.md b/cli/tests/testdata/npm/README.md
new file mode 100644
index 000000000..ba3f5f771
--- /dev/null
+++ b/cli/tests/testdata/npm/README.md
@@ -0,0 +1,18 @@
+# npm test data
+
+This folder contains test data for npm specifiers.
+
+## Registry
+
+The registry is served by the test server (server in test_util) at
+http://localhost:4545/npm/registry/ via the `./registry` folder.
+
+### Updating with real npm packages
+
+1. Set the `DENO_TEST_UTIL_UPDATE_NPM=1` environment variable
+2. Run the test and it should download the packages.
+
+### Using a custom npm package
+
+1. Add the custom package to `./registry/@denotest`
+2. Reference `npm:@denotest/<your-package-name>` in the tests.
diff --git a/cli/tests/testdata/npm/cjs_local_global_decls/main.out b/cli/tests/testdata/npm/cjs_local_global_decls/main.out
new file mode 100644
index 000000000..f9331e2e5
--- /dev/null
+++ b/cli/tests/testdata/npm/cjs_local_global_decls/main.out
@@ -0,0 +1,3 @@
+Download http://localhost:4545/npm/registry/@denotest/cjs-local-global-decls
+Download http://localhost:4545/npm/registry/@denotest/cjs-local-global-decls/1.0.0.tgz
+Loaded.
diff --git a/cli/tests/testdata/npm/cjs_local_global_decls/main.ts b/cli/tests/testdata/npm/cjs_local_global_decls/main.ts
new file mode 100644
index 000000000..04074057b
--- /dev/null
+++ b/cli/tests/testdata/npm/cjs_local_global_decls/main.ts
@@ -0,0 +1 @@
+import "npm:@denotest/cjs-local-global-decls@1.0.0";
diff --git a/cli/tests/testdata/npm/registry/@denotest/cjs-local-global-decls/1.0.0/index.js b/cli/tests/testdata/npm/registry/@denotest/cjs-local-global-decls/1.0.0/index.js
new file mode 100644
index 000000000..75fc15d83
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/cjs-local-global-decls/1.0.0/index.js
@@ -0,0 +1,4 @@
+// package that has all the locals defined
+const Buffer = 1, clearImmediate = 1, clearInterval = 1, clearTimeout = 1, global = 1, process = 1, setImmediate = 1, setInterval = 1, setTimeout = 1, globalThis = 1;
+const exports = 2;
+console.log("Loaded.");
diff --git a/cli/tests/testdata/npm/registry/@denotest/cjs-local-global-decls/1.0.0/package.json b/cli/tests/testdata/npm/registry/@denotest/cjs-local-global-decls/1.0.0/package.json
new file mode 100644
index 000000000..f3514e2ab
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/cjs-local-global-decls/1.0.0/package.json
@@ -0,0 +1,4 @@
+{
+ "name": "@deno/cjs-local-global-decls",
+ "version": "1.0.0"
+} \ No newline at end of file