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/builders.rs | |
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/builders.rs')
-rw-r--r-- | test_util/src/builders.rs | 16 |
1 files changed, 16 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()); |