summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarvin Hagemeister <marvin@deno.com>2024-10-24 20:03:56 +0200
committerGitHub <noreply@github.com>2024-10-24 20:03:56 +0200
commit5f0bb3c6f4328003012e98ba70ce18e4e2e842de (patch)
tree5d99b6f2868c70b105ca4ff83f2a7380f4da9ac5 /tests
parentc71e020668b40666aecfdffb1dbf979abcb41958 (diff)
fix: `.npmrc` settings not being passed to install/add command (#26473)
We weren't passing the resolved npmrc settings to the install commands. This lead us to always fall back to the default registry url instead of using the one from npmrc. Fixes https://github.com/denoland/deno/issues/26139 Fixes https://github.com/denoland/deno/issues/26033 Fixes https://github.com/denoland/deno/issues/25924 Fixes https://github.com/denoland/deno/issues/25822 Fixes https://github.com/denoland/deno/issues/26152 --------- Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/registry/npm-private3/@denotest3/basic/1.0.0/main.d.mts3
-rw-r--r--tests/registry/npm-private3/@denotest3/basic/1.0.0/main.mjs11
-rw-r--r--tests/registry/npm-private3/@denotest3/basic/1.0.0/other.mjs3
-rw-r--r--tests/registry/npm-private3/@denotest3/basic/1.0.0/package.json7
-rw-r--r--tests/specs/npm/npmrc_install_arg/.npmrc2
-rw-r--r--tests/specs/npm/npmrc_install_arg/__test__.jsonc23
-rw-r--r--tests/specs/npm/npmrc_install_arg/add.out4
-rw-r--r--tests/specs/npm/npmrc_install_arg/install.out4
-rw-r--r--tests/specs/npm/npmrc_install_arg/main.js5
-rw-r--r--tests/specs/npm/npmrc_install_arg/main.out2
-rw-r--r--tests/specs/npm/npmrc_install_arg/package.json5
-rw-r--r--tests/specs/npm/npmrc_no_auth/.npmrc1
-rw-r--r--tests/specs/npm/npmrc_no_auth/__test__.jsonc23
-rw-r--r--tests/specs/npm/npmrc_no_auth/add.out4
-rw-r--r--tests/specs/npm/npmrc_no_auth/install.out4
-rw-r--r--tests/specs/npm/npmrc_no_auth/main.js5
-rw-r--r--tests/specs/npm/npmrc_no_auth/main.out2
-rw-r--r--tests/specs/npm/npmrc_no_auth/package.json6
-rw-r--r--tests/specs/npm/npmrc_no_auth_install/.npmrc1
-rw-r--r--tests/specs/npm/npmrc_no_auth_install/__test__.jsonc14
-rw-r--r--tests/specs/npm/npmrc_no_auth_install/install.out3
-rw-r--r--tests/specs/npm/npmrc_no_auth_install/main.js5
-rw-r--r--tests/specs/npm/npmrc_no_auth_install/main.out2
-rw-r--r--tests/specs/npm/npmrc_no_auth_install/package.json7
-rw-r--r--tests/util/server/src/lib.rs3
-rw-r--r--tests/util/server/src/npm.rs32
-rw-r--r--tests/util/server/src/servers/mod.rs4
-rw-r--r--tests/util/server/src/servers/npm_registry.rs15
28 files changed, 199 insertions, 1 deletions
diff --git a/tests/registry/npm-private3/@denotest3/basic/1.0.0/main.d.mts b/tests/registry/npm-private3/@denotest3/basic/1.0.0/main.d.mts
new file mode 100644
index 000000000..29da1e6d7
--- /dev/null
+++ b/tests/registry/npm-private3/@denotest3/basic/1.0.0/main.d.mts
@@ -0,0 +1,3 @@
+export declare function setValue(val: number): void;
+export declare function getValue(): number;
+export declare const url: string;
diff --git a/tests/registry/npm-private3/@denotest3/basic/1.0.0/main.mjs b/tests/registry/npm-private3/@denotest3/basic/1.0.0/main.mjs
new file mode 100644
index 000000000..0a44f7585
--- /dev/null
+++ b/tests/registry/npm-private3/@denotest3/basic/1.0.0/main.mjs
@@ -0,0 +1,11 @@
+let value = 0;
+
+export function setValue(newValue) {
+ value = newValue;
+}
+
+export function getValue() {
+ return value;
+}
+
+export const url = import.meta.url;
diff --git a/tests/registry/npm-private3/@denotest3/basic/1.0.0/other.mjs b/tests/registry/npm-private3/@denotest3/basic/1.0.0/other.mjs
new file mode 100644
index 000000000..00ed99da4
--- /dev/null
+++ b/tests/registry/npm-private3/@denotest3/basic/1.0.0/other.mjs
@@ -0,0 +1,3 @@
+export function hello() {
+ return "hello, world!";
+} \ No newline at end of file
diff --git a/tests/registry/npm-private3/@denotest3/basic/1.0.0/package.json b/tests/registry/npm-private3/@denotest3/basic/1.0.0/package.json
new file mode 100644
index 000000000..ce6ea3383
--- /dev/null
+++ b/tests/registry/npm-private3/@denotest3/basic/1.0.0/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "@denotest3/basic",
+ "version": "1.0.0",
+ "type": "module",
+ "main": "main.mjs",
+ "types": "main.d.mts"
+}
diff --git a/tests/specs/npm/npmrc_install_arg/.npmrc b/tests/specs/npm/npmrc_install_arg/.npmrc
new file mode 100644
index 000000000..de3704b92
--- /dev/null
+++ b/tests/specs/npm/npmrc_install_arg/.npmrc
@@ -0,0 +1,2 @@
+@denotest:registry=http://localhost:4261/
+//localhost:4261/:_authToken=private-reg-token
diff --git a/tests/specs/npm/npmrc_install_arg/__test__.jsonc b/tests/specs/npm/npmrc_install_arg/__test__.jsonc
new file mode 100644
index 000000000..f34cfe116
--- /dev/null
+++ b/tests/specs/npm/npmrc_install_arg/__test__.jsonc
@@ -0,0 +1,23 @@
+{
+ "tempDir": true,
+ "tests": {
+ "deno_install_add": {
+ "steps": [{
+ "args": "install npm:@denotest/basic",
+ "output": "install.out"
+ }, {
+ "args": "run -A main.js",
+ "output": "main.out"
+ }]
+ },
+ "deno_add": {
+ "steps": [{
+ "args": "add npm:@denotest/basic",
+ "output": "add.out"
+ }, {
+ "args": "run -A main.js",
+ "output": "main.out"
+ }]
+ }
+ }
+}
diff --git a/tests/specs/npm/npmrc_install_arg/add.out b/tests/specs/npm/npmrc_install_arg/add.out
new file mode 100644
index 000000000..11948e54d
--- /dev/null
+++ b/tests/specs/npm/npmrc_install_arg/add.out
@@ -0,0 +1,4 @@
+Add npm:@denotest/basic@1.0.0
+Download http://localhost:4261/@denotest%2fbasic
+Download http://localhost:4261/@denotest/basic/1.0.0.tgz
+Initialize @denotest/basic@1.0.0
diff --git a/tests/specs/npm/npmrc_install_arg/install.out b/tests/specs/npm/npmrc_install_arg/install.out
new file mode 100644
index 000000000..11948e54d
--- /dev/null
+++ b/tests/specs/npm/npmrc_install_arg/install.out
@@ -0,0 +1,4 @@
+Add npm:@denotest/basic@1.0.0
+Download http://localhost:4261/@denotest%2fbasic
+Download http://localhost:4261/@denotest/basic/1.0.0.tgz
+Initialize @denotest/basic@1.0.0
diff --git a/tests/specs/npm/npmrc_install_arg/main.js b/tests/specs/npm/npmrc_install_arg/main.js
new file mode 100644
index 000000000..e8ccf7611
--- /dev/null
+++ b/tests/specs/npm/npmrc_install_arg/main.js
@@ -0,0 +1,5 @@
+import { getValue, setValue } from "@denotest/basic";
+
+console.log(getValue());
+setValue(42);
+console.log(getValue());
diff --git a/tests/specs/npm/npmrc_install_arg/main.out b/tests/specs/npm/npmrc_install_arg/main.out
new file mode 100644
index 000000000..dcd912c89
--- /dev/null
+++ b/tests/specs/npm/npmrc_install_arg/main.out
@@ -0,0 +1,2 @@
+0
+42
diff --git a/tests/specs/npm/npmrc_install_arg/package.json b/tests/specs/npm/npmrc_install_arg/package.json
new file mode 100644
index 000000000..c1318b361
--- /dev/null
+++ b/tests/specs/npm/npmrc_install_arg/package.json
@@ -0,0 +1,5 @@
+{
+ "name": "npmrc_test",
+ "version": "0.0.1",
+ "dependencies": {}
+}
diff --git a/tests/specs/npm/npmrc_no_auth/.npmrc b/tests/specs/npm/npmrc_no_auth/.npmrc
new file mode 100644
index 000000000..860a7c3d9
--- /dev/null
+++ b/tests/specs/npm/npmrc_no_auth/.npmrc
@@ -0,0 +1 @@
+@denotest3:registry=http://localhost:4263/
diff --git a/tests/specs/npm/npmrc_no_auth/__test__.jsonc b/tests/specs/npm/npmrc_no_auth/__test__.jsonc
new file mode 100644
index 000000000..efd04f0e4
--- /dev/null
+++ b/tests/specs/npm/npmrc_no_auth/__test__.jsonc
@@ -0,0 +1,23 @@
+{
+ "tempDir": true,
+ "tests": {
+ "deno_install_arg": {
+ "steps": [{
+ "args": "install npm:@denotest3/basic",
+ "output": "install.out"
+ }, {
+ "args": "run -A main.js",
+ "output": "main.out"
+ }]
+ },
+ "deno_add_arg": {
+ "steps": [{
+ "args": "add npm:@denotest3/basic",
+ "output": "add.out"
+ }, {
+ "args": "run -A main.js",
+ "output": "main.out"
+ }]
+ }
+ }
+}
diff --git a/tests/specs/npm/npmrc_no_auth/add.out b/tests/specs/npm/npmrc_no_auth/add.out
new file mode 100644
index 000000000..31b34da13
--- /dev/null
+++ b/tests/specs/npm/npmrc_no_auth/add.out
@@ -0,0 +1,4 @@
+Add npm:@denotest3/basic@1.0.0
+Download http://localhost:4263/@denotest3%2fbasic
+Download http://localhost:4263/@denotest3/basic/1.0.0.tgz
+Initialize @denotest3/basic@1.0.0
diff --git a/tests/specs/npm/npmrc_no_auth/install.out b/tests/specs/npm/npmrc_no_auth/install.out
new file mode 100644
index 000000000..31b34da13
--- /dev/null
+++ b/tests/specs/npm/npmrc_no_auth/install.out
@@ -0,0 +1,4 @@
+Add npm:@denotest3/basic@1.0.0
+Download http://localhost:4263/@denotest3%2fbasic
+Download http://localhost:4263/@denotest3/basic/1.0.0.tgz
+Initialize @denotest3/basic@1.0.0
diff --git a/tests/specs/npm/npmrc_no_auth/main.js b/tests/specs/npm/npmrc_no_auth/main.js
new file mode 100644
index 000000000..22713bb0d
--- /dev/null
+++ b/tests/specs/npm/npmrc_no_auth/main.js
@@ -0,0 +1,5 @@
+import { getValue, setValue } from "@denotest3/basic";
+
+console.log(getValue());
+setValue(42);
+console.log(getValue());
diff --git a/tests/specs/npm/npmrc_no_auth/main.out b/tests/specs/npm/npmrc_no_auth/main.out
new file mode 100644
index 000000000..dcd912c89
--- /dev/null
+++ b/tests/specs/npm/npmrc_no_auth/main.out
@@ -0,0 +1,2 @@
+0
+42
diff --git a/tests/specs/npm/npmrc_no_auth/package.json b/tests/specs/npm/npmrc_no_auth/package.json
new file mode 100644
index 000000000..dddaaac46
--- /dev/null
+++ b/tests/specs/npm/npmrc_no_auth/package.json
@@ -0,0 +1,6 @@
+{
+ "name": "npmrc_test",
+ "version": "0.0.1",
+ "dependencies": {
+ }
+}
diff --git a/tests/specs/npm/npmrc_no_auth_install/.npmrc b/tests/specs/npm/npmrc_no_auth_install/.npmrc
new file mode 100644
index 000000000..860a7c3d9
--- /dev/null
+++ b/tests/specs/npm/npmrc_no_auth_install/.npmrc
@@ -0,0 +1 @@
+@denotest3:registry=http://localhost:4263/
diff --git a/tests/specs/npm/npmrc_no_auth_install/__test__.jsonc b/tests/specs/npm/npmrc_no_auth_install/__test__.jsonc
new file mode 100644
index 000000000..56a598e3b
--- /dev/null
+++ b/tests/specs/npm/npmrc_no_auth_install/__test__.jsonc
@@ -0,0 +1,14 @@
+{
+ "tempDir": true,
+ "tests": {
+ "deno_install_arg": {
+ "steps": [{
+ "args": "install",
+ "output": "install.out"
+ }, {
+ "args": "run -A main.js",
+ "output": "main.out"
+ }]
+ }
+ }
+}
diff --git a/tests/specs/npm/npmrc_no_auth_install/install.out b/tests/specs/npm/npmrc_no_auth_install/install.out
new file mode 100644
index 000000000..b82747af7
--- /dev/null
+++ b/tests/specs/npm/npmrc_no_auth_install/install.out
@@ -0,0 +1,3 @@
+Download http://localhost:4263/@denotest3%2fbasic
+Download http://localhost:4263/@denotest3/basic/1.0.0.tgz
+Initialize @denotest3/basic@1.0.0
diff --git a/tests/specs/npm/npmrc_no_auth_install/main.js b/tests/specs/npm/npmrc_no_auth_install/main.js
new file mode 100644
index 000000000..22713bb0d
--- /dev/null
+++ b/tests/specs/npm/npmrc_no_auth_install/main.js
@@ -0,0 +1,5 @@
+import { getValue, setValue } from "@denotest3/basic";
+
+console.log(getValue());
+setValue(42);
+console.log(getValue());
diff --git a/tests/specs/npm/npmrc_no_auth_install/main.out b/tests/specs/npm/npmrc_no_auth_install/main.out
new file mode 100644
index 000000000..dcd912c89
--- /dev/null
+++ b/tests/specs/npm/npmrc_no_auth_install/main.out
@@ -0,0 +1,2 @@
+0
+42
diff --git a/tests/specs/npm/npmrc_no_auth_install/package.json b/tests/specs/npm/npmrc_no_auth_install/package.json
new file mode 100644
index 000000000..2d4fb15ba
--- /dev/null
+++ b/tests/specs/npm/npmrc_no_auth_install/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "npmrc_test",
+ "version": "0.0.1",
+ "dependencies": {
+ "@denotest3/basic": "1.0.0"
+ }
+}
diff --git a/tests/util/server/src/lib.rs b/tests/util/server/src/lib.rs
index 88e8287e0..e4a2cc02e 100644
--- a/tests/util/server/src/lib.rs
+++ b/tests/util/server/src/lib.rs
@@ -307,7 +307,7 @@ async fn get_tcp_listener_stream(
futures::stream::select_all(listeners)
}
-pub const TEST_SERVERS_COUNT: usize = 30;
+pub const TEST_SERVERS_COUNT: usize = 32;
#[derive(Default)]
struct HttpServerCount {
@@ -360,6 +360,7 @@ impl Default for HttpServerStarter {
let mut ready_count = 0;
for maybe_line in lines {
if let Ok(line) = maybe_line {
+ eprintln!("LINE: {}", line);
if line.starts_with("ready:") {
ready_count += 1;
}
diff --git a/tests/util/server/src/npm.rs b/tests/util/server/src/npm.rs
index f1c341738..4b17b95f7 100644
--- a/tests/util/server/src/npm.rs
+++ b/tests/util/server/src/npm.rs
@@ -18,6 +18,7 @@ use crate::PathRef;
pub const DENOTEST_SCOPE_NAME: &str = "@denotest";
pub const DENOTEST2_SCOPE_NAME: &str = "@denotest2";
+pub const DENOTEST3_SCOPE_NAME: &str = "@denotest3";
pub static PUBLIC_TEST_NPM_REGISTRY: Lazy<TestNpmRegistry> = Lazy::new(|| {
TestNpmRegistry::new(
@@ -54,6 +55,18 @@ pub static PRIVATE_TEST_NPM_REGISTRY_2: Lazy<TestNpmRegistry> =
)
});
+pub static PRIVATE_TEST_NPM_REGISTRY_3: Lazy<TestNpmRegistry> =
+ Lazy::new(|| {
+ TestNpmRegistry::new(
+ NpmRegistryKind::Private,
+ &format!(
+ "http://localhost:{}",
+ crate::servers::PRIVATE_NPM_REGISTRY_3_PORT
+ ),
+ "npm-private3",
+ )
+ });
+
pub enum NpmRegistryKind {
Public,
Private,
@@ -90,6 +103,7 @@ impl TestNpmRegistry {
}
pub fn root_dir(&self) -> PathRef {
+ eprintln!("root {}", self.local_path);
tests_path().join("registry").join(&self.local_path)
}
@@ -106,6 +120,7 @@ impl TestNpmRegistry {
}
pub fn registry_file(&self, name: &str) -> Result<Option<Vec<u8>>> {
+ eprintln!("registry file {}", name);
self.get_package_property(name, |p| p.registry_file.as_bytes().to_vec())
}
@@ -123,6 +138,7 @@ impl TestNpmRegistry {
package_name: &str,
func: impl FnOnce(&CustomNpmPackage) -> TResult,
) -> Result<Option<TResult>> {
+ eprintln!("get package property {}", package_name);
// it's ok if multiple threads race here as they will do the same work twice
if !self.cache.lock().contains_key(package_name) {
match get_npm_package(&self.hostname, &self.local_path, package_name)? {
@@ -139,6 +155,7 @@ impl TestNpmRegistry {
&self,
uri_path: &'s str,
) -> Option<(&'s str, &'s str)> {
+ eprintln!("GEETT {}", uri_path);
let prefix1 = format!("/{}/", DENOTEST_SCOPE_NAME);
let prefix2 = format!("/{}%2f", DENOTEST_SCOPE_NAME);
@@ -161,6 +178,17 @@ impl TestNpmRegistry {
return Some((DENOTEST2_SCOPE_NAME, package_name_with_path));
}
+ let prefix1 = format!("/{}/", DENOTEST3_SCOPE_NAME);
+ let prefix2 = format!("/{}%2f", DENOTEST3_SCOPE_NAME);
+
+ let maybe_package_name_with_path = uri_path
+ .strip_prefix(&prefix1)
+ .or_else(|| uri_path.strip_prefix(&prefix2));
+
+ if let Some(package_name_with_path) = maybe_package_name_with_path {
+ return Some((DENOTEST3_SCOPE_NAME, package_name_with_path));
+ }
+
None
}
}
@@ -170,6 +198,10 @@ fn get_npm_package(
local_path: &str,
package_name: &str,
) -> Result<Option<CustomNpmPackage>> {
+ eprintln!(
+ "get npm package {} {} {}",
+ registry_hostname, local_path, package_name
+ );
let registry_hostname = if package_name == "@denotest/tarballs-privateserver2"
{
"http://localhost:4262"
diff --git a/tests/util/server/src/servers/mod.rs b/tests/util/server/src/servers/mod.rs
index 3e18aafce..3a9c44010 100644
--- a/tests/util/server/src/servers/mod.rs
+++ b/tests/util/server/src/servers/mod.rs
@@ -91,6 +91,7 @@ const PROVENANCE_MOCK_SERVER_PORT: u16 = 4251;
pub(crate) const PUBLIC_NPM_REGISTRY_PORT: u16 = 4260;
pub(crate) const PRIVATE_NPM_REGISTRY_1_PORT: u16 = 4261;
pub(crate) const PRIVATE_NPM_REGISTRY_2_PORT: u16 = 4262;
+pub(crate) const PRIVATE_NPM_REGISTRY_3_PORT: u16 = 4263;
// Use the single-threaded scheduler. The hyper server is used as a point of
// comparison for the (single-threaded!) benchmarks in cli/bench. We're not
@@ -143,6 +144,8 @@ pub async fn run_all_servers() {
npm_registry::private_npm_registry1(PRIVATE_NPM_REGISTRY_1_PORT);
let private_npm_registry_2_server_futs =
npm_registry::private_npm_registry2(PRIVATE_NPM_REGISTRY_2_PORT);
+ let private_npm_registry_3_server_futs =
+ npm_registry::private_npm_registry3(PRIVATE_NPM_REGISTRY_3_PORT);
let mut futures = vec![
redirect_server_fut.boxed_local(),
@@ -173,6 +176,7 @@ pub async fn run_all_servers() {
futures.extend(npm_registry_server_futs);
futures.extend(private_npm_registry_1_server_futs);
futures.extend(private_npm_registry_2_server_futs);
+ futures.extend(private_npm_registry_3_server_futs);
assert_eq!(futures.len(), TEST_SERVERS_COUNT);
diff --git a/tests/util/server/src/servers/npm_registry.rs b/tests/util/server/src/servers/npm_registry.rs
index acbd9cab4..4ada468fa 100644
--- a/tests/util/server/src/servers/npm_registry.rs
+++ b/tests/util/server/src/servers/npm_registry.rs
@@ -56,6 +56,14 @@ pub fn private_npm_registry2(port: u16) -> Vec<LocalBoxFuture<'static, ()>> {
)
}
+pub fn private_npm_registry3(port: u16) -> Vec<LocalBoxFuture<'static, ()>> {
+ run_npm_server(
+ port,
+ "npm private registry server error",
+ private_npm_registry3_handler,
+ )
+}
+
fn run_npm_server<F, S>(
port: u16,
error_msg: &'static str,
@@ -141,6 +149,13 @@ async fn private_npm_registry2_handler(
handle_req_for_registry(req, &npm::PRIVATE_TEST_NPM_REGISTRY_2).await
}
+async fn private_npm_registry3_handler(
+ req: Request<hyper::body::Incoming>,
+) -> Result<Response<UnsyncBoxBody<Bytes, Infallible>>, anyhow::Error> {
+ // No auth for this registry
+ handle_req_for_registry(req, &npm::PRIVATE_TEST_NPM_REGISTRY_3).await
+}
+
async fn handle_req_for_registry(
req: Request<Incoming>,
test_npm_registry: &npm::TestNpmRegistry,