mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
chore(cli): use NPM_CONFIG_REGISTRY for all tests (#20320)
We never want tests to hit the real npm registry because this causes test flakes. In addition, we set a sentinal "unset" value for `NPM_CONFIG_REGISTRY` to ensure that all tests requiring npm go through the test server.
This commit is contained in:
parent
441b860978
commit
64045ebc7a
7 changed files with 36 additions and 1 deletions
|
@ -86,13 +86,17 @@ itest!(check_static_response_json {
|
||||||
itest!(check_node_builtin_modules_ts {
|
itest!(check_node_builtin_modules_ts {
|
||||||
args: "check --quiet check/node_builtin_modules/mod.ts",
|
args: "check --quiet check/node_builtin_modules/mod.ts",
|
||||||
output: "check/node_builtin_modules/mod.ts.out",
|
output: "check/node_builtin_modules/mod.ts.out",
|
||||||
|
envs: env_vars_for_npm_tests(),
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(check_node_builtin_modules_js {
|
itest!(check_node_builtin_modules_js {
|
||||||
args: "check --quiet check/node_builtin_modules/mod.js",
|
args: "check --quiet check/node_builtin_modules/mod.js",
|
||||||
output: "check/node_builtin_modules/mod.js.out",
|
output: "check/node_builtin_modules/mod.js.out",
|
||||||
|
envs: env_vars_for_npm_tests(),
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
itest!(check_no_error_truncation {
|
itest!(check_no_error_truncation {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use test_util as util;
|
use test_util as util;
|
||||||
use test_util::TempDir;
|
use test_util::TempDir;
|
||||||
|
use util::env_vars_for_npm_tests;
|
||||||
use util::TestContext;
|
use util::TestContext;
|
||||||
use util::TestContextBuilder;
|
use util::TestContextBuilder;
|
||||||
|
|
||||||
|
@ -326,7 +327,7 @@ fn no_tests_included(test_name: &str, extension: &str) {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_npm_cache_coverage() {
|
fn no_npm_cache_coverage() {
|
||||||
let context = TestContext::default();
|
let context = TestContext::with_http_server();
|
||||||
let tempdir = context.temp_dir();
|
let tempdir = context.temp_dir();
|
||||||
let tempdir = tempdir.path().join("cov");
|
let tempdir = tempdir.path().join("cov");
|
||||||
|
|
||||||
|
@ -339,6 +340,7 @@ fn no_npm_cache_coverage() {
|
||||||
format!("--coverage={}", tempdir),
|
format!("--coverage={}", tempdir),
|
||||||
format!("coverage/no_npm_coverage/no_npm_coverage_test.ts"),
|
format!("coverage/no_npm_coverage/no_npm_coverage_test.ts"),
|
||||||
])
|
])
|
||||||
|
.envs(env_vars_for_npm_tests())
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
output.assert_exit_code(0);
|
output.assert_exit_code(0);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use test_util as util;
|
use test_util as util;
|
||||||
|
use util::env_vars_for_npm_tests;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn node_compat_tests() {
|
fn node_compat_tests() {
|
||||||
|
@ -21,5 +22,7 @@ fn node_compat_tests() {
|
||||||
itest!(node_test_module {
|
itest!(node_test_module {
|
||||||
args: "test node/test.js",
|
args: "test node/test.js",
|
||||||
output: "node/test.out",
|
output: "node/test.out",
|
||||||
|
envs: env_vars_for_npm_tests(),
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
|
@ -109,6 +109,7 @@ fn node_unit_test(test: String) {
|
||||||
.join("unit_node")
|
.join("unit_node")
|
||||||
.join(format!("{test}.ts")),
|
.join(format!("{test}.ts")),
|
||||||
)
|
)
|
||||||
|
.envs(env_vars_for_npm_tests())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use test_util::deno_cmd;
|
use test_util::deno_cmd;
|
||||||
|
use test_util::env_vars_for_npm_tests;
|
||||||
|
use test_util::http_server;
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
const BUILD_VARIANT: &str = "debug";
|
const BUILD_VARIANT: &str = "debug";
|
||||||
|
@ -53,6 +55,7 @@ fn build() {
|
||||||
fn napi_tests() {
|
fn napi_tests() {
|
||||||
build();
|
build();
|
||||||
|
|
||||||
|
let _http_guard = http_server();
|
||||||
let output = deno_cmd()
|
let output = deno_cmd()
|
||||||
.current_dir(test_util::napi_tests_path())
|
.current_dir(test_util::napi_tests_path())
|
||||||
.env("RUST_BACKTRACE", "1")
|
.env("RUST_BACKTRACE", "1")
|
||||||
|
@ -61,6 +64,7 @@ fn napi_tests() {
|
||||||
.arg("--allow-env")
|
.arg("--allow-env")
|
||||||
.arg("--allow-ffi")
|
.arg("--allow-ffi")
|
||||||
.arg("--allow-run")
|
.arg("--allow-run")
|
||||||
|
.envs(env_vars_for_npm_tests())
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.wait_with_output()
|
.wait_with_output()
|
||||||
|
|
|
@ -19,6 +19,7 @@ use crate::env_vars_for_npm_tests_no_sync_download;
|
||||||
use crate::fs::PathRef;
|
use crate::fs::PathRef;
|
||||||
use crate::http_server;
|
use crate::http_server;
|
||||||
use crate::lsp::LspClientBuilder;
|
use crate::lsp::LspClientBuilder;
|
||||||
|
use crate::npm_registry_unset_url;
|
||||||
use crate::pty::Pty;
|
use crate::pty::Pty;
|
||||||
use crate::strip_ansi_codes;
|
use crate::strip_ansi_codes;
|
||||||
use crate::testdata_path;
|
use crate::testdata_path;
|
||||||
|
@ -266,6 +267,17 @@ impl TestCommandBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn envs<S: AsRef<OsStr>>(
|
||||||
|
self,
|
||||||
|
envs: impl IntoIterator<Item = (S, S)>,
|
||||||
|
) -> Self {
|
||||||
|
let mut this = self;
|
||||||
|
for (k, v) in envs {
|
||||||
|
this = this.env(k, v);
|
||||||
|
}
|
||||||
|
this
|
||||||
|
}
|
||||||
|
|
||||||
pub fn env_clear(mut self) -> Self {
|
pub fn env_clear(mut self) -> Self {
|
||||||
self.env_clear = true;
|
self.env_clear = true;
|
||||||
self
|
self
|
||||||
|
@ -391,6 +403,10 @@ impl TestCommandBuilder {
|
||||||
command.env_clear();
|
command.env_clear();
|
||||||
}
|
}
|
||||||
command.env("DENO_DIR", self.context.deno_dir.path());
|
command.env("DENO_DIR", self.context.deno_dir.path());
|
||||||
|
let envs = self.build_envs();
|
||||||
|
if !envs.contains_key("NPM_CONFIG_REGISTRY") {
|
||||||
|
command.env("NPM_CONFIG_REGISTRY", npm_registry_unset_url());
|
||||||
|
}
|
||||||
command.envs(self.build_envs());
|
command.envs(self.build_envs());
|
||||||
command.current_dir(cwd);
|
command.current_dir(cwd);
|
||||||
command.stdin(Stdio::piped());
|
command.stdin(Stdio::piped());
|
||||||
|
|
|
@ -160,6 +160,10 @@ pub fn npm_registry_url() -> String {
|
||||||
"http://localhost:4545/npm/registry/".to_string()
|
"http://localhost:4545/npm/registry/".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn npm_registry_unset_url() -> String {
|
||||||
|
"http://NPM_CONFIG_REGISTRY.is.unset".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn std_path() -> PathRef {
|
pub fn std_path() -> PathRef {
|
||||||
root_path().join("test_util").join("std")
|
root_path().join("test_util").join("std")
|
||||||
}
|
}
|
||||||
|
@ -2309,6 +2313,7 @@ pub fn deno_cmd_with_deno_dir(deno_dir: &TempDir) -> DenoCmd {
|
||||||
assert!(exe_path.exists());
|
assert!(exe_path.exists());
|
||||||
let mut cmd = Command::new(exe_path);
|
let mut cmd = Command::new(exe_path);
|
||||||
cmd.env("DENO_DIR", deno_dir.path());
|
cmd.env("DENO_DIR", deno_dir.path());
|
||||||
|
cmd.env("NPM_CONFIG_REGISTRY", npm_registry_unset_url());
|
||||||
DenoCmd {
|
DenoCmd {
|
||||||
_deno_dir: deno_dir.clone(),
|
_deno_dir: deno_dir.clone(),
|
||||||
cmd,
|
cmd,
|
||||||
|
|
Loading…
Reference in a new issue