Skip to content

Commit

Permalink
Add tests, address feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Jun 8, 2019
1 parent 0d6accb commit 28c2b5a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 17 deletions.
31 changes: 28 additions & 3 deletions cli/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,15 @@ mod tests {
maybe_source_map: None,
};

out = compile_sync(ThreadSafeState::mock(), specifier, &referrer, &out)
.unwrap();
out = compile_sync(
ThreadSafeState::mock(vec![
String::from("./deno"),
String::from("hello.js"),
]),
specifier,
&referrer,
&out,
).unwrap();
assert!(
out
.maybe_output_code
Expand All @@ -289,8 +296,26 @@ mod tests {
#[test]
fn test_get_compiler_config_no_flag() {
let compiler_type = "typescript";
let state = ThreadSafeState::mock();
let state = ThreadSafeState::mock(vec![
String::from("./deno"),
String::from("hello.js"),
]);
let out = get_compiler_config(&state, compiler_type);
assert_eq!(out, None);
}

#[test]
fn test_bundle_async() {
let state = ThreadSafeState::mock(vec![
String::from("./deno"),
String::from("source.ts"),
String::from("bundle.ts"),
]);
let out = bundle_async(
state,
String::from("file://foo/bar/source.ts"),
String::from("bundle.ts"),
);
assert_eq!(tokio_util::block_on(out), Ok(()));
}
}
15 changes: 15 additions & 0 deletions cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,4 +1052,19 @@ mod tests {
assert_eq!(subcommand, DenoSubcommand::Run);
assert_eq!(argv, svec!["deno", "script.ts"]);
}

#[test]
fn test_flags_from_vec_26() {
let (flags, subcommand, argv) =
flags_from_vec(svec!["deno", "bundle", "source.ts", "bundle.js"]);
assert_eq!(
flags,
DenoFlags {
allow_write: true,
..DenoFlags::default()
}
);
assert_eq!(subcommand, DenoSubcommand::Bundle);
assert_eq!(argv, svec!["deno", "source.ts", "bundle.js"])
}
}
3 changes: 2 additions & 1 deletion cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ fn bundle_command(flags: DenoFlags, argv: Vec<String>) {

let main_module = state.main_module().unwrap();
let main_url = root_specifier_to_url(&main_module).unwrap();
let out_file = state.out_file().unwrap();
assert!(state.argv.len() >= 3);
let out_file = state.argv[2].clone();
debug!(">>>>> bundle_async START");
let bundle_future = bundle_async(state, main_url.to_string(), out_file)
.map_err(|e| {
Expand Down
17 changes: 5 additions & 12 deletions cli/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,6 @@ impl ThreadSafeState {
}
}

/// Read the out file from argv
pub fn out_file(&self) -> Option<String> {
if self.argv.len() <= 2 {
None
} else {
Some(self.argv[2].clone())
}
}

pub fn mark_compiled(&self, module_id: &str) {
let mut c = self.compiled.lock().unwrap();
c.insert(module_id.to_string());
Expand Down Expand Up @@ -320,8 +311,7 @@ impl ThreadSafeState {
}

#[cfg(test)]
pub fn mock() -> ThreadSafeState {
let argv = vec![String::from("./deno"), String::from("hello.js")];
pub fn mock(argv: Vec<String>) -> ThreadSafeState {
ThreadSafeState::new(
flags::DenoFlags::default(),
argv,
Expand Down Expand Up @@ -358,5 +348,8 @@ impl ThreadSafeState {
#[test]
fn thread_safe() {
fn f<S: Send + Sync>(_: S) {}
f(ThreadSafeState::mock());
f(ThreadSafeState::mock(vec![
String::from("./deno"),
String::from("hello.js"),
]));
}
5 changes: 4 additions & 1 deletion cli/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ mod tests {
}

fn create_test_worker() -> Worker {
let state = ThreadSafeState::mock();
let state = ThreadSafeState::mock(vec![
String::from("./deno"),
String::from("hello.js"),
]);
let mut worker =
Worker::new("TEST".to_string(), startup_data::deno_isolate_init(), state);
js_check(worker.execute("denoMain()"));
Expand Down

0 comments on commit 28c2b5a

Please sign in to comment.