From 716005a0d4afd1042fa75d8bdc32fd13e9ebe95f Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 22 Sep 2022 11:17:02 -0400 Subject: feat(npm): add flag for creating and resolving npm packages to a local node_modules folder (#15971) --- test_util/src/lib.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'test_util') diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs index 5a357ee7d..73fe3ff9b 100644 --- a/test_util/src/lib.rs +++ b/test_util/src/lib.rs @@ -1861,6 +1861,7 @@ pub struct CheckOutputIntegrationTest<'a> { pub http_server: bool, pub envs: Vec<(String, String)>, pub env_clear: bool, + pub temp_cwd: bool, } impl<'a> CheckOutputIntegrationTest<'a> { @@ -1874,6 +1875,11 @@ impl<'a> CheckOutputIntegrationTest<'a> { ); std::borrow::Cow::Borrowed(&self.args_vec) }; + let testdata_dir = testdata_path(); + let args = args + .iter() + .map(|arg| arg.replace("$TESTDATA", &testdata_dir.to_string_lossy())) + .collect::>(); let deno_exe = deno_exe_path(); println!("deno_exe path {}", deno_exe.display()); @@ -1884,17 +1890,21 @@ impl<'a> CheckOutputIntegrationTest<'a> { }; let (mut reader, writer) = pipe().unwrap(); - let testdata_dir = testdata_path(); let deno_dir = new_deno_dir(); // keep this alive for the test let mut command = deno_cmd_with_deno_dir(&deno_dir); - println!("deno_exe args {}", self.args); - println!("deno_exe testdata path {:?}", &testdata_dir); + let cwd = if self.temp_cwd { + deno_dir.path() + } else { + testdata_dir.as_path() + }; + println!("deno_exe args {}", args.join(" ")); + println!("deno_exe cwd {:?}", &testdata_dir); command.args(args.iter()); if self.env_clear { command.env_clear(); } command.envs(self.envs.clone()); - command.current_dir(&testdata_dir); + command.current_dir(&cwd); command.stdin(Stdio::piped()); let writer_clone = writer.try_clone().unwrap(); command.stderr(writer_clone); @@ -1949,7 +1959,7 @@ impl<'a> CheckOutputIntegrationTest<'a> { // deno test's output capturing flushes with a zero-width space in order to // synchronize the output pipes. Occassionally this zero width space // might end up in the output so strip it from the output comparison here. - if args.first() == Some(&"test") { + if args.first().map(|s| s.as_str()) == Some("test") { actual = actual.replace('\u{200B}', ""); } -- cgit v1.2.3