diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-08-29 13:02:54 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-29 13:02:54 -0600 |
commit | 64045ebc7a4e1c9f77204ffe35563134a453a7c6 (patch) | |
tree | c6710acf89e7019fd203d1667edc1a7798850c1d /test_util/src | |
parent | 441b860978afd0160a459aee7e42ccc97263dc23 (diff) |
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.
Diffstat (limited to 'test_util/src')
-rw-r--r-- | test_util/src/builders.rs | 16 | ||||
-rw-r--r-- | test_util/src/lib.rs | 5 |
2 files changed, 21 insertions, 0 deletions
diff --git a/test_util/src/builders.rs b/test_util/src/builders.rs index 8811efa02..769c054bf 100644 --- a/test_util/src/builders.rs +++ b/test_util/src/builders.rs @@ -19,6 +19,7 @@ use crate::env_vars_for_npm_tests_no_sync_download; use crate::fs::PathRef; use crate::http_server; use crate::lsp::LspClientBuilder; +use crate::npm_registry_unset_url; use crate::pty::Pty; use crate::strip_ansi_codes; use crate::testdata_path; @@ -266,6 +267,17 @@ impl TestCommandBuilder { 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 { self.env_clear = true; self @@ -391,6 +403,10 @@ impl TestCommandBuilder { command.env_clear(); } 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.current_dir(cwd); command.stdin(Stdio::piped()); diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs index cf66e3366..fa0cb8a84 100644 --- a/test_util/src/lib.rs +++ b/test_util/src/lib.rs @@ -160,6 +160,10 @@ pub fn npm_registry_url() -> 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 { 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()); let mut cmd = Command::new(exe_path); cmd.env("DENO_DIR", deno_dir.path()); + cmd.env("NPM_CONFIG_REGISTRY", npm_registry_unset_url()); DenoCmd { _deno_dir: deno_dir.clone(), cmd, |