summaryrefslogtreecommitdiff
path: root/test_util/src
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-03-03 18:27:05 -0400
committerGitHub <noreply@github.com>2023-03-03 18:27:05 -0400
commit84bafd11d52609e74a52df8e57752d5e3c25f717 (patch)
treecdc282ab3a808bc29987cdb45c0b462ae1e080ec /test_util/src
parent5c43e2a665c9dae7aff3ba757e589f10ec3aa062 (diff)
fix: lazily surface errors in package.json deps parsing (#17974)
Closes #17941
Diffstat (limited to 'test_util/src')
-rw-r--r--test_util/src/builders.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/test_util/src/builders.rs b/test_util/src/builders.rs
index d48170bbf..6ccb45f50 100644
--- a/test_util/src/builders.rs
+++ b/test_util/src/builders.rs
@@ -16,6 +16,7 @@ use pretty_assertions::assert_eq;
use crate::copy_dir_recursive;
use crate::deno_exe_path;
+use crate::env_vars_for_npm_tests_no_sync_download;
use crate::http_server;
use crate::new_deno_dir;
use crate::strip_ansi_codes;
@@ -41,6 +42,12 @@ impl TestContextBuilder {
Self::default()
}
+ pub fn for_npm() -> Self {
+ let mut builder = Self::new();
+ builder.use_http_server().add_npm_env_vars();
+ builder
+ }
+
pub fn use_http_server(&mut self) -> &mut Self {
self.use_http_server = true;
self
@@ -54,11 +61,12 @@ impl TestContextBuilder {
/// Copies the files at the specified directory in the "testdata" directory
/// to the temp folder and runs the test from there. This is useful when
/// the test creates files in the testdata directory (ex. a node_modules folder)
- pub fn use_copy_temp_dir(&mut self, dir: impl AsRef<str>) {
+ pub fn use_copy_temp_dir(&mut self, dir: impl AsRef<str>) -> &mut Self {
self.copy_temp_dir = Some(dir.as_ref().to_string());
+ self
}
- pub fn set_cwd(&mut self, cwd: impl AsRef<str>) -> &mut Self {
+ pub fn cwd(&mut self, cwd: impl AsRef<str>) -> &mut Self {
self.cwd = Some(cwd.as_ref().to_string());
self
}
@@ -74,6 +82,22 @@ impl TestContextBuilder {
self
}
+ pub fn add_npm_env_vars(&mut self) -> &mut Self {
+ for (key, value) in env_vars_for_npm_tests_no_sync_download() {
+ self.env(key, value);
+ }
+ self
+ }
+
+ pub fn use_sync_npm_download(&mut self) -> &mut Self {
+ self.env(
+ // make downloads determinstic
+ "DENO_UNSTABLE_NPM_SYNC_DOWNLOAD",
+ "1",
+ );
+ self
+ }
+
pub fn build(&self) -> TestContext {
let deno_dir = new_deno_dir(); // keep this alive for the test
let testdata_dir = if let Some(temp_copy_dir) = &self.copy_temp_dir {