Skip to content

Commit eb2cc00

Browse files
committed
Add tests, address feedback.
1 parent 4cdc261 commit eb2cc00

File tree

5 files changed

+52
-16
lines changed

5 files changed

+52
-16
lines changed

cli/compiler.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,13 @@ mod tests {
257257
maybe_source_map: None,
258258
};
259259

260-
out = compile_sync(ThreadSafeState::mock(), &out).unwrap();
260+
out = compile_sync(
261+
ThreadSafeState::mock(vec![
262+
String::from("./deno"),
263+
String::from("hello.js"),
264+
]),
265+
&out,
266+
).unwrap();
261267
assert!(
262268
out
263269
.maybe_output_code
@@ -270,8 +276,26 @@ mod tests {
270276
#[test]
271277
fn test_get_compiler_config_no_flag() {
272278
let compiler_type = "typescript";
273-
let state = ThreadSafeState::mock();
279+
let state = ThreadSafeState::mock(vec![
280+
String::from("./deno"),
281+
String::from("hello.js"),
282+
]);
274283
let out = get_compiler_config(&state, compiler_type);
275284
assert_eq!(out, None);
276285
}
286+
287+
#[test]
288+
fn test_bundle_async() {
289+
let state = ThreadSafeState::mock(vec![
290+
String::from("./deno"),
291+
String::from("source.ts"),
292+
String::from("bundle.ts"),
293+
]);
294+
let out = bundle_async(
295+
state,
296+
String::from("file://foo/bar/source.ts"),
297+
String::from("bundle.ts"),
298+
);
299+
assert_eq!(tokio_util::block_on(out), Ok(()));
300+
}
277301
}

cli/flags.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,4 +1052,19 @@ mod tests {
10521052
assert_eq!(subcommand, DenoSubcommand::Run);
10531053
assert_eq!(argv, svec!["deno", "script.ts"]);
10541054
}
1055+
1056+
#[test]
1057+
fn test_flags_from_vec_26() {
1058+
let (flags, subcommand, argv) =
1059+
flags_from_vec(svec!["deno", "bundle", "source.ts", "bundle.js"]);
1060+
assert_eq!(
1061+
flags,
1062+
DenoFlags {
1063+
allow_write: true,
1064+
..DenoFlags::default()
1065+
}
1066+
);
1067+
assert_eq!(subcommand, DenoSubcommand::Bundle);
1068+
assert_eq!(argv, svec!["deno", "source.ts", "bundle.js"])
1069+
}
10551070
}

cli/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ fn bundle_command(flags: DenoFlags, argv: Vec<String>) {
263263

264264
let main_module = state.main_module().unwrap();
265265
let main_url = root_specifier_to_url(&main_module).unwrap();
266-
let out_file = state.out_file().unwrap();
266+
assert!(state.argv.len() >= 3);
267+
let out_file = state.argv[2].clone();
267268
debug!(">>>>> bundle_async START");
268269
let bundle_future = bundle_async(state, main_url.to_string(), out_file)
269270
.map_err(|e| {

cli/state.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,6 @@ impl ThreadSafeState {
270270
}
271271
}
272272

273-
/// Read the out file from argv
274-
pub fn out_file(&self) -> Option<String> {
275-
if self.argv.len() <= 2 {
276-
None
277-
} else {
278-
Some(self.argv[2].clone())
279-
}
280-
}
281-
282273
pub fn mark_compiled(&self, module_id: &str) {
283274
let mut c = self.compiled.lock().unwrap();
284275
c.insert(module_id.to_string());
@@ -320,8 +311,7 @@ impl ThreadSafeState {
320311
}
321312

322313
#[cfg(test)]
323-
pub fn mock() -> ThreadSafeState {
324-
let argv = vec![String::from("./deno"), String::from("hello.js")];
314+
pub fn mock(argv: Vec<String>) -> ThreadSafeState {
325315
ThreadSafeState::new(
326316
flags::DenoFlags::default(),
327317
argv,
@@ -358,5 +348,8 @@ impl ThreadSafeState {
358348
#[test]
359349
fn thread_safe() {
360350
fn f<S: Send + Sync>(_: S) {}
361-
f(ThreadSafeState::mock());
351+
f(ThreadSafeState::mock(vec![
352+
String::from("./deno"),
353+
String::from("hello.js"),
354+
]));
362355
}

cli/worker.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,10 @@ mod tests {
280280
}
281281

282282
fn create_test_worker() -> Worker {
283-
let state = ThreadSafeState::mock();
283+
let state = ThreadSafeState::mock(vec![
284+
String::from("./deno"),
285+
String::from("hello.js"),
286+
]);
284287
let mut worker =
285288
Worker::new("TEST".to_string(), startup_data::deno_isolate_init(), state);
286289
js_check(worker.execute("denoMain()"));

0 commit comments

Comments
 (0)