summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/npm_tests.rs87
-rw-r--r--cli/tests/testdata/npm/cached_only/main.out4
-rw-r--r--cli/tests/testdata/npm/cached_only/main.ts3
-rw-r--r--cli/tests/testdata/npm/cached_only_after_first_run/main1.ts3
-rw-r--r--cli/tests/testdata/npm/cached_only_after_first_run/main2.ts3
-rw-r--r--cli/tests/testdata/npm/cjs_sub_path/main.out15
-rw-r--r--cli/tests/testdata/npm/cjs_with_deps/main.out14
-rw-r--r--cli/tests/testdata/npm/dynamic_import/main.out1
-rw-r--r--cli/tests/testdata/npm/esm/main.out1
-rw-r--r--cli/tests/testdata/npm/esm/test.out1
-rw-r--r--cli/tests/testdata/npm/import_map/main.out1
11 files changed, 133 insertions, 0 deletions
diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs
index fa5f3979a..7a2b249a1 100644
--- a/cli/tests/integration/npm_tests.rs
+++ b/cli/tests/integration/npm_tests.rs
@@ -1,7 +1,10 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
use deno_core::url::Url;
+use std::process::Stdio;
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.
@@ -51,6 +54,13 @@ itest!(dynamic_import {
http_server: true,
});
+itest!(cached_only {
+ args: "run --cached-only --unstable npm/cached_only/main.ts",
+ output: "npm/cached_only/main.out",
+ envs: env_vars(),
+ exit_code: 1,
+});
+
itest!(import_map {
args: "run --allow-read --unstable --import-map npm/import_map/import_map.json npm/import_map/main.js",
output: "npm/import_map/main.out",
@@ -77,6 +87,83 @@ fn parallel_downloading() {
}
#[test]
+fn cached_only_after_first_run() {
+ let _server = http_server();
+
+ let deno_dir = util::new_deno_dir();
+
+ let deno = util::deno_cmd_with_deno_dir(&deno_dir)
+ .current_dir(util::testdata_path())
+ .arg("run")
+ .arg("--unstable")
+ .arg("--allow-read")
+ .arg("--allow-env")
+ .arg("npm/cached_only_after_first_run/main1.ts")
+ .env("NO_COLOR", "1")
+ .envs(env_vars())
+ .stdout(Stdio::piped())
+ .stderr(Stdio::piped())
+ .spawn()
+ .unwrap();
+ let output = deno.wait_with_output().unwrap();
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ let stdout = String::from_utf8_lossy(&output.stdout);
+ assert_contains!(stderr, "Download");
+ assert_contains!(stdout, "createChalk: chalk");
+ assert!(output.status.success());
+
+ let deno = util::deno_cmd_with_deno_dir(&deno_dir)
+ .current_dir(util::testdata_path())
+ .arg("run")
+ .arg("--unstable")
+ .arg("--allow-read")
+ .arg("--allow-env")
+ .arg("--cached-only")
+ .arg("npm/cached_only_after_first_run/main2.ts")
+ .env("NO_COLOR", "1")
+ .envs(env_vars())
+ .stdout(Stdio::piped())
+ .stderr(Stdio::piped())
+ .spawn()
+ .unwrap();
+ let output = deno.wait_with_output().unwrap();
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ let stdout = String::from_utf8_lossy(&output.stdout);
+ assert_contains!(
+ stderr,
+ "An npm specifier not found in cache: \"ansi-styles\", --cached-only is specified."
+ );
+ assert!(stdout.is_empty());
+ assert!(!output.status.success());
+
+ let deno = util::deno_cmd_with_deno_dir(&deno_dir)
+ .current_dir(util::testdata_path())
+ .arg("run")
+ .arg("--unstable")
+ .arg("--allow-read")
+ .arg("--allow-env")
+ .arg("--cached-only")
+ .arg("npm/cached_only_after_first_run/main1.ts")
+ .env("NO_COLOR", "1")
+ .envs(env_vars())
+ .stdout(Stdio::piped())
+ .stderr(Stdio::piped())
+ .spawn()
+ .unwrap();
+
+ eprintln!("DENO DIR: {}", deno_dir.path().display());
+ std::mem::forget(deno_dir);
+ let output = deno.wait_with_output().unwrap();
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ let stdout = String::from_utf8_lossy(&output.stdout);
+ eprintln!("stderr {}", stderr);
+ eprintln!("stdout {}", stdout);
+ assert!(output.status.success());
+ assert!(stderr.is_empty());
+ assert_contains!(stdout, "createChalk: chalk");
+}
+
+#[test]
fn ensure_registry_files_local() {
// ensures the registry files all point at local tarballs
let registry_dir_path = util::testdata_path().join("npm").join("registry");
diff --git a/cli/tests/testdata/npm/cached_only/main.out b/cli/tests/testdata/npm/cached_only/main.out
new file mode 100644
index 000000000..e902bff49
--- /dev/null
+++ b/cli/tests/testdata/npm/cached_only/main.out
@@ -0,0 +1,4 @@
+error: Error getting response at http://localhost:4545/npm/registry/chalk
+
+Caused by:
+ An npm specifier not found in cache: "chalk", --cached-only is specified.
diff --git a/cli/tests/testdata/npm/cached_only/main.ts b/cli/tests/testdata/npm/cached_only/main.ts
new file mode 100644
index 000000000..1ccc441a1
--- /dev/null
+++ b/cli/tests/testdata/npm/cached_only/main.ts
@@ -0,0 +1,3 @@
+import chalk from "npm:chalk@5";
+
+console.log(chalk);
diff --git a/cli/tests/testdata/npm/cached_only_after_first_run/main1.ts b/cli/tests/testdata/npm/cached_only_after_first_run/main1.ts
new file mode 100644
index 000000000..1ccc441a1
--- /dev/null
+++ b/cli/tests/testdata/npm/cached_only_after_first_run/main1.ts
@@ -0,0 +1,3 @@
+import chalk from "npm:chalk@5";
+
+console.log(chalk);
diff --git a/cli/tests/testdata/npm/cached_only_after_first_run/main2.ts b/cli/tests/testdata/npm/cached_only_after_first_run/main2.ts
new file mode 100644
index 000000000..1aba1bc2c
--- /dev/null
+++ b/cli/tests/testdata/npm/cached_only_after_first_run/main2.ts
@@ -0,0 +1,3 @@
+import chalk from "npm:chalk@4";
+
+console.log(chalk);
diff --git a/cli/tests/testdata/npm/cjs_sub_path/main.out b/cli/tests/testdata/npm/cjs_sub_path/main.out
index 593b557dd..e6e70f3aa 100644
--- a/cli/tests/testdata/npm/cjs_sub_path/main.out
+++ b/cli/tests/testdata/npm/cjs_sub_path/main.out
@@ -1,3 +1,18 @@
+Download http://localhost:4545/npm/registry/ajv
+Download http://localhost:4545/npm/registry/ajv-formats
+Download http://localhost:4545/npm/registry/chai
+Download http://localhost:4545/npm/registry/fast-deep-equal
+Download http://localhost:4545/npm/registry/json-schema-traverse
+Download http://localhost:4545/npm/registry/require-from-string
+Download http://localhost:4545/npm/registry/uri-js
+Download http://localhost:4545/npm/registry/assertion-error
+Download http://localhost:4545/npm/registry/check-error
+Download http://localhost:4545/npm/registry/deep-eql
+Download http://localhost:4545/npm/registry/get-func-name
+Download http://localhost:4545/npm/registry/loupe
+Download http://localhost:4545/npm/registry/pathval
+Download http://localhost:4545/npm/registry/type-detect
+Download http://localhost:4545/npm/registry/punycode
Download http://localhost:4545/npm/registry/ajv/ajv-8.11.0.tgz
Download http://localhost:4545/npm/registry/ajv-formats/ajv-formats-2.1.1.tgz
Download http://localhost:4545/npm/registry/assertion-error/assertion-error-1.1.0.tgz
diff --git a/cli/tests/testdata/npm/cjs_with_deps/main.out b/cli/tests/testdata/npm/cjs_with_deps/main.out
index ad31742d9..23c217f7a 100644
--- a/cli/tests/testdata/npm/cjs_with_deps/main.out
+++ b/cli/tests/testdata/npm/cjs_with_deps/main.out
@@ -1,3 +1,17 @@
+Download http://localhost:4545/npm/registry/chai
+Download http://localhost:4545/npm/registry/chalk
+Download http://localhost:4545/npm/registry/assertion-error
+Download http://localhost:4545/npm/registry/check-error
+Download http://localhost:4545/npm/registry/deep-eql
+Download http://localhost:4545/npm/registry/get-func-name
+Download http://localhost:4545/npm/registry/loupe
+Download http://localhost:4545/npm/registry/pathval
+Download http://localhost:4545/npm/registry/type-detect
+Download http://localhost:4545/npm/registry/ansi-styles
+Download http://localhost:4545/npm/registry/supports-color
+Download http://localhost:4545/npm/registry/color-convert
+Download http://localhost:4545/npm/registry/has-flag
+Download http://localhost:4545/npm/registry/color-name
Download http://localhost:4545/npm/registry/ansi-styles/ansi-styles-4.3.0.tgz
Download http://localhost:4545/npm/registry/assertion-error/assertion-error-1.1.0.tgz
Download http://localhost:4545/npm/registry/chai/chai-4.3.6.tgz
diff --git a/cli/tests/testdata/npm/dynamic_import/main.out b/cli/tests/testdata/npm/dynamic_import/main.out
index 3ba847c7e..7e2fb7a0f 100644
--- a/cli/tests/testdata/npm/dynamic_import/main.out
+++ b/cli/tests/testdata/npm/dynamic_import/main.out
@@ -1,4 +1,5 @@
A
+Download http://localhost:4545/npm/registry/chalk
Download http://localhost:4545/npm/registry/chalk/chalk-5.0.1.tgz
B
C
diff --git a/cli/tests/testdata/npm/esm/main.out b/cli/tests/testdata/npm/esm/main.out
index b6c6dbb59..2010a5b73 100644
--- a/cli/tests/testdata/npm/esm/main.out
+++ b/cli/tests/testdata/npm/esm/main.out
@@ -1,2 +1,3 @@
+Download http://localhost:4545/npm/registry/chalk
Download http://localhost:4545/npm/registry/chalk/chalk-5.0.1.tgz
chalk esm loads
diff --git a/cli/tests/testdata/npm/esm/test.out b/cli/tests/testdata/npm/esm/test.out
index 0f8ef2009..2c1179bd1 100644
--- a/cli/tests/testdata/npm/esm/test.out
+++ b/cli/tests/testdata/npm/esm/test.out
@@ -1,3 +1,4 @@
+Download http://localhost:4545/npm/registry/chalk
Download http://localhost:4545/npm/registry/chalk/chalk-5.0.1.tgz
Check [WILDCARD]/std/node/module_all.ts
chalk esm loads
diff --git a/cli/tests/testdata/npm/import_map/main.out b/cli/tests/testdata/npm/import_map/main.out
index 755eb7338..ef3f4e22b 100644
--- a/cli/tests/testdata/npm/import_map/main.out
+++ b/cli/tests/testdata/npm/import_map/main.out
@@ -1,2 +1,3 @@
+Download http://localhost:4545/npm/registry/chalk
Download http://localhost:4545/npm/registry/chalk/chalk-5.0.1.tgz
chalk import map loads