Skip to content

Commit 13d6282

Browse files
authored
chore: auto cleanup ts from test on drop (#628)
1 parent e29c9c0 commit 13d6282

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

crates/base/src/runtime/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,7 +2332,6 @@ extern "C" fn mem_check_gc_prologue_callback_fn(
23322332
#[cfg(test)]
23332333
mod test {
23342334
use std::collections::HashMap;
2335-
use std::fs::File;
23362335
use std::io::Write;
23372336
use std::marker::PhantomData;
23382337
use std::path::Path;
@@ -2364,6 +2363,7 @@ mod test {
23642363
use serde::de::DeserializeOwned;
23652364
use serde::Serialize;
23662365
use serial_test::serial;
2366+
use tempfile::Builder;
23672367
use tokio::sync::mpsc;
23682368
use tokio::time::timeout;
23692369

@@ -2598,11 +2598,18 @@ mod test {
25982598
#[allow(clippy::arc_with_non_send_sync)]
25992599
async fn test_eszip_with_source_file() {
26002600
let (worker_pool_tx, _) = mpsc::unbounded_channel::<UserWorkerMsgs>();
2601-
let mut file = File::create("./test_cases/eszip-source-test.ts").unwrap();
2602-
file.write_all(b"import isEven from \"npm:is-even\"; globalThis.isTenEven = isEven(9);")
2601+
let mut temp_file = Builder::new()
2602+
.prefix("eszip-source-test")
2603+
.suffix(".ts")
2604+
.tempfile_in("./test_cases")
2605+
.unwrap();
2606+
temp_file
2607+
.write_all(
2608+
b"import isEven from \"npm:is-even\"; globalThis.isTenEven = isEven(9);",
2609+
)
26032610
.unwrap();
26042611

2605-
let path_buf = PathBuf::from("./test_cases/eszip-source-test.ts");
2612+
let path_buf = temp_file.path().to_path_buf();
26062613
let mut emitter_factory = EmitterFactory::new();
26072614

26082615
emitter_factory.set_deno_options(
@@ -2623,7 +2630,8 @@ mod test {
26232630
.await
26242631
.unwrap();
26252632

2626-
std::fs::remove_file("./test_cases/eszip-source-test.ts").unwrap();
2633+
let temp_path = temp_file.into_temp_path();
2634+
temp_path.close().unwrap();
26272635

26282636
let eszip_code = bin_eszip.into_bytes();
26292637
let runtime = DenoRuntime::<()>::new(

0 commit comments

Comments
 (0)