diff options
Diffstat (limited to 'cli')
222 files changed, 1622 insertions, 444 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml index cf51781fa..b9a9c1456 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,11 +1,8 @@ # Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -[[bin]] -name = "deno" -path = "main.rs" [package] name = "deno_cli" -version = "0.18.3" +version = "0.18.4" license = "MIT" authors = ["the Deno authors"] edition = "2018" @@ -13,6 +10,14 @@ description = "Provides the deno executable" repository = "https://github.com/denoland/deno" default-run = "deno" +[lib] +name = "deno_cli" +path = "lib.rs" + +[[bin]] +name = "deno" +path = "main.rs" + [dependencies] deno = { path = "../core", version = "0.18.0" } deno_cli_snapshots = { path = "../js", version = "0.18.3" } diff --git a/cli/colors.rs b/cli/colors.rs index 7ca42e2f5..9c2c7a401 100644 --- a/cli/colors.rs +++ b/cli/colors.rs @@ -21,7 +21,6 @@ lazy_static! { } /// Helper function to strip ansi codes. -#[cfg(test)] pub fn strip_ansi_codes(s: &str) -> std::borrow::Cow<str> { STRIP_ANSI_RE.replace_all(s, "") } diff --git a/cli/compilers/ts.rs b/cli/compilers/ts.rs index 8330d86e9..fc280a898 100644 --- a/cli/compilers/ts.rs +++ b/cli/compilers/ts.rs @@ -670,7 +670,7 @@ mod tests { url: specifier.as_url().clone(), filename: PathBuf::from(p.to_str().unwrap().to_string()), media_type: msg::MediaType::TypeScript, - source_code: include_bytes!("../../tests/002_hello.ts").to_vec(), + source_code: include_bytes!("../tests/002_hello.ts").to_vec(), }; let mock_state = ThreadSafeState::mock(vec![ diff --git a/cli/lib.rs b/cli/lib.rs new file mode 100644 index 000000000..ff8f02239 --- /dev/null +++ b/cli/lib.rs @@ -0,0 +1,437 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +#[macro_use] +extern crate lazy_static; +#[macro_use] +extern crate log; +#[macro_use] +extern crate futures; +#[macro_use] +extern crate serde_json; +extern crate clap; +extern crate deno; +extern crate deno_cli_snapshots; +extern crate indexmap; +#[cfg(unix)] +extern crate nix; +extern crate rand; +extern crate serde; +extern crate serde_derive; +extern crate url; + +pub mod colors; +pub mod compilers; +pub mod deno_dir; +pub mod deno_error; +pub mod diagnostics; +mod disk_cache; +mod file_fetcher; +pub mod flags; +pub mod fmt_errors; +mod fs; +mod global_timer; +mod http_body; +mod http_util; +mod import_map; +pub mod msg; +pub mod ops; +pub mod permissions; +mod progress; +mod repl; +pub mod resolve_addr; +pub mod resources; +mod shell; +mod signal; +pub mod source_maps; +mod startup_data; +pub mod state; +mod tokio_read; +mod tokio_util; +mod tokio_write; +pub mod version; +pub mod worker; + +use crate::progress::Progress; +use crate::state::ThreadSafeState; +use crate::worker::Worker; +use deno::v8_set_flags; +use deno::ErrBox; +use deno::ModuleSpecifier; +use flags::DenoFlags; +use flags::DenoSubcommand; +use futures::lazy; +use futures::Future; +use log::Level; +use log::Metadata; +use log::Record; +use std::env; + +static LOGGER: Logger = Logger; + +struct Logger; + +impl log::Log for Logger { + fn enabled(&self, metadata: &Metadata) -> bool { + metadata.level() <= log::max_level() + } + + fn log(&self, record: &Record) { + if self.enabled(record.metadata()) { + let mut target = record.target().to_string(); + + if let Some(line_no) = record.line() { + target.push_str(":"); + target.push_str(&line_no.to_string()); + } + + println!("{} RS - {} - {}", record.level(), target, record.args()); + } + } + fn flush(&self) {} +} + +fn print_err_and_exit(err: ErrBox) { + eprintln!("{}", err.to_string()); + std::process::exit(1); +} + +fn js_check(r: Result<(), ErrBox>) { + if let Err(err) = r { + print_err_and_exit(err); + } +} + +fn create_worker_and_state( + flags: DenoFlags, + argv: Vec<String>, +) -> (Worker, ThreadSafeState) { + use crate::shell::Shell; + use std::sync::Arc; + use std::sync::Mutex; + let shell = Arc::new(Mutex::new(Shell::new())); + let progress = Progress::new(); + progress.set_callback(move |_done, _completed, _total, status, msg| { + if !status.is_empty() { + let mut s = shell.lock().unwrap(); + s.status(status, msg).expect("shell problem"); + } + }); + // TODO(kevinkassimo): maybe make include_deno_namespace also configurable? + let state = ThreadSafeState::new(flags, argv, progress, true) + .map_err(print_err_and_exit) + .unwrap(); + let worker = Worker::new( + "main".to_string(), + startup_data::deno_isolate_init(), + state.clone(), + ); + + (worker, state) +} + +fn types_command() { + let content = deno_cli_snapshots::get_asset("lib.deno_runtime.d.ts").unwrap(); + println!("{}", content); +} + +fn print_cache_info(worker: Worker) { + let state = worker.state; + + println!( + "{} {:?}", + colors::bold("DENO_DIR location:".to_string()), + state.dir.root + ); + println!( + "{} {:?}", + colors::bold("Remote modules cache:".to_string()), + state.dir.deps_cache.location + ); + println!( + "{} {:?}", + colors::bold("TypeScript compiler cache:".to_string()), + state.dir.gen_cache.location + ); +} + +pub fn print_file_info( + worker: Worker, + module_specifier: &ModuleSpecifier, +) -> impl Future<Item = Worker, Error = ()> { + let state_ = worker.state.clone(); + let module_specifier_ = module_specifier.clone(); + + state_ + .file_fetcher + .fetch_source_file_async(&module_specifier) + .map_err(|err| println!("{}", err)) + .and_then(|out| { + println!( + "{} {}", + colors::bold("local:".to_string()), + out.filename.to_str().unwrap() + ); + + println!( + "{} {}", + colors::bold("type:".to_string()), + msg::enum_name_media_type(out.media_type) + ); + + state_ + .clone() + .fetch_compiled_module(&module_specifier_) + .map_err(|e| { + debug!("compiler error exiting!"); + eprintln!("\n{}", e.to_string()); + std::process::exit(1); + }) + .and_then(move |compiled| { + if out.media_type == msg::MediaType::TypeScript + || (out.media_type == msg::MediaType::JavaScript + && state_.ts_compiler.compile_js) + { + let compiled_source_file = state_ + .ts_compiler + .get_compiled_source_file(&out.url) + .unwrap(); + + println!( + "{} {}", + colors::bold("compiled:".to_string()), + compiled_source_file.filename.to_str().unwrap(), + ); + } + + if let Ok(source_map) = state_ + .clone() + .ts_compiler + .get_source_map_file(&module_specifier_) + { + println!( + "{} {}", + colors::bold("map:".to_string()), + source_map.filename.to_str().unwrap() + ); + } + + if let Some(deps) = + worker.state.modules.lock().unwrap().deps(&compiled.name) + { + println!("{}{}", colors::bold("deps:\n".to_string()), deps.name); + if let Some(ref depsdeps) = deps.deps { + for d in depsdeps { + println!("{}", d); + } + } + } else { + println!( + "{} cannot retrieve full dependency graph", + colors::bold("deps:".to_string()), + ); + } + Ok(worker) + }) + }) +} + +fn info_command(flags: DenoFlags, argv: Vec<String>) { + let (mut worker, state) = create_worker_and_state(flags, argv.clone()); + + // If it was just "deno info" print location of caches and exit + if argv.len() == 1 { + return print_cache_info(worker); + } + + let main_module = state.main_module().unwrap(); + let main_future = lazy(move || { + // Setup runtime. + js_check(worker.execute("denoMain()")); + debug!("main_module {}", main_module); + + worker + .execute_mod_async(&main_module, true) + .map_err(print_err_and_exit) + .and_then(move |()| print_file_info(worker, &main_module)) + .and_then(|worker| { + worker.then(|result| { + js_check(result); + Ok(()) + }) + }) + }); + tokio_util::run(main_future); +} + +fn fetch_command(flags: DenoFlags, argv: Vec<String>) { + let (mut worker, state) = create_worker_and_state(flags, argv.clone()); + + let main_module = state.main_module().unwrap(); + let main_future = lazy(move || { + // Setup runtime. + js_check(worker.execute("denoMain()")); + debug!("main_module {}", main_module); + + worker.execute_mod_async(&main_module, true).then(|result| { + js_check(result); + Ok(()) + }) + }); + tokio_util::run(main_future); +} + +fn eval_command(flags: DenoFlags, argv: Vec<String>) { + let (mut worker, state) = create_worker_and_state(flags, argv); + // Wrap provided script in async function so asynchronous methods + // work. This is required until top-level await is not supported. + let js_source = format!( + "async function _topLevelWrapper(){{ + {} + }} + _topLevelWrapper(); + ", + &state.argv[1] + ); + + let main_future = lazy(move || { + js_check(worker.execute("denoMain()")); + // ATM imports in `deno eval` are not allowed + // TODO Support ES modules once Worker supports evaluating anonymous modules. + js_check(worker.execute(&js_source)); + worker.then(|result| { + js_check(result); + Ok(()) + }) + }); + tokio_util::run(main_future); +} + +fn xeval_command(flags: DenoFlags, argv: Vec<String>) { + let xeval_replvar = flags.xeval_replvar.clone().unwrap(); + let (mut worker, state) = create_worker_and_state(flags, argv); + let xeval_source = format!( + "window._xevalWrapper = async function ({}){{ + {} + }}", + &xeval_replvar, &state.argv[1] + ); + + let main_future = lazy(move || { + // Setup runtime. + js_check(worker.execute(&xeval_source)); + js_check(worker.execute("denoMain()")); + worker + .then(|result| { + js_check(result); + Ok(()) + }) + .map_err(print_err_and_exit) + }); + tokio_util::run(main_future); +} + +fn bundle_command(flags: DenoFlags, argv: Vec<String>) { + let (mut _worker, state) = create_worker_and_state(flags, argv); + + let main_module = state.main_module().unwrap(); + assert!(state.argv.len() >= 3); + let out_file = state.argv[2].clone(); + debug!(">>>>> bundle_async START"); + let bundle_future = state + .ts_compiler + .bundle_async(state.clone(), main_module.to_string(), out_file) + .map_err(|err| { + debug!("diagnostics returned, exiting!"); + eprintln!(""); + print_err_and_exit(err); + }) + .and_then(move |_| { + debug!(">>>>> bundle_async END"); + Ok(()) + }); + tokio_util::run(bundle_future); +} + +fn run_repl(flags: DenoFlags, argv: Vec<String>) { + let (mut worker, _state) = create_worker_and_state(flags, argv); + + // REPL situation. + let main_future = lazy(move || { + // Setup runtime. + js_check(worker.execute("denoMain()")); + worker + .then(|result| { + js_check(result); + Ok(()) + }) + .map_err(|(err, _worker): (ErrBox, Worker)| print_err_and_exit(err)) + }); + tokio_util::run(main_future); +} + +fn run_script(flags: DenoFlags, argv: Vec<String>) { + let use_current_thread = flags.current_thread; + let (mut worker, state) = create_worker_and_state(flags, argv); + + let main_module = state.main_module().unwrap(); + // Normal situation of executing a module. + let main_future = lazy(move || { + // Setup runtime. + js_check(worker.execute("denoMain()")); + debug!("main_module {}", main_module); + + worker + .execute_mod_async(&main_module, false) + .and_then(move |()| { + js_check(worker.execute("window.dispatchEvent(new Event('load'))")); + worker.then(|result| { + js_check(result); + Ok(()) + }) + }) + .map_err(print_err_and_exit) + }); + + if use_current_thread { + tokio_util::run_on_current_thread(main_future); + } else { + tokio_util::run(main_future); + } +} + +fn version_command() { + println!("deno: {}", version::DENO); + println!("v8: {}", version::v8()); + println!("typescript: {}", version::TYPESCRIPT); +} + +pub fn main() { + #[cfg(windows)] + ansi_term::enable_ansi_support().ok(); // For Windows 10 + + log::set_logger(&LOGGER).unwrap(); + let args: Vec<String> = env::args().collect(); + let (flags, subcommand, argv) = flags::flags_from_vec(args); + + if let Some(ref v8_flags) = flags.v8_flags { + v8_set_flags(v8_flags.clone()); + } + + let log_level = match flags.log_level { + Some(level) => level, + None => Level::Warn, + }; + log::set_max_level(log_level.to_level_filter()); + + match subcommand { + DenoSubcommand::Bundle => bundle_command(flags, argv), + DenoSubcommand::Completions => {} + DenoSubcommand::Eval => eval_command(flags, argv), + DenoSubcommand::Fetch => fetch_command(flags, argv), + DenoSubcommand::Info => info_command(flags, argv), + DenoSubcommand::Repl => run_repl(flags, argv), + DenoSubcommand::Run => run_script(flags, argv), + DenoSubcommand::Types => types_command(), + DenoSubcommand::Version => version_command(), + DenoSubcommand::Xeval => xeval_command(flags, argv), + } +} diff --git a/cli/main.rs b/cli/main.rs index e535b70bd..b24c61a9b 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -1,440 +1,5 @@ -// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -#[macro_use] -extern crate lazy_static; -#[macro_use] -extern crate log; -#[macro_use] -extern crate futures; -#[macro_use] -extern crate serde_json; -extern crate clap; -extern crate deno; -extern crate deno_cli_snapshots; -extern crate indexmap; -#[cfg(unix)] -extern crate nix; -extern crate rand; -extern crate serde; -extern crate serde_derive; -extern crate url; - -#[cfg(test)] -mod integration_tests; - -mod colors; -pub mod compilers; -pub mod deno_dir; -pub mod deno_error; -pub mod diagnostics; -mod disk_cache; -mod file_fetcher; -pub mod flags; -pub mod fmt_errors; -mod fs; -mod global_timer; -mod http_body; -mod http_util; -mod import_map; -pub mod msg; -pub mod ops; -pub mod permissions; -mod progress; -mod repl; -pub mod resolve_addr; -pub mod resources; -mod shell; -mod signal; -pub mod source_maps; -mod startup_data; -pub mod state; -mod tokio_read; -mod tokio_util; -mod tokio_write; -pub mod version; -pub mod worker; - -use crate::progress::Progress; -use crate::state::ThreadSafeState; -use crate::worker::Worker; -use deno::v8_set_flags; -use deno::ErrBox; -use deno::ModuleSpecifier; -use flags::DenoFlags; -use flags::DenoSubcommand; -use futures::lazy; -use futures::Future; -use log::Level; -use log::Metadata; -use log::Record; -use std::env; - -static LOGGER: Logger = Logger; - -struct Logger; - -impl log::Log for Logger { - fn enabled(&self, metadata: &Metadata) -> bool { - metadata.level() <= log::max_level() - } - - fn log(&self, record: &Record) { - if self.enabled(record.metadata()) { - let mut target = record.target().to_string(); - - if let Some(line_no) = record.line() { - target.push_str(":"); - target.push_str(&line_no.to_string()); - } - - println!("{} RS - {} - {}", record.level(), target, record.args()); - } - } - fn flush(&self) {} -} - -fn print_err_and_exit(err: ErrBox) { - eprintln!("{}", err.to_string()); - std::process::exit(1); -} - -fn js_check(r: Result<(), ErrBox>) { - if let Err(err) = r { - print_err_and_exit(err); - } -} - -fn create_worker_and_state( - flags: DenoFlags, - argv: Vec<String>, -) -> (Worker, ThreadSafeState) { - use crate::shell::Shell; - use std::sync::Arc; - use std::sync::Mutex; - let shell = Arc::new(Mutex::new(Shell::new())); - let progress = Progress::new(); - progress.set_callback(move |_done, _completed, _total, status, msg| { - if !status.is_empty() { - let mut s = shell.lock().unwrap(); - s.status(status, msg).expect("shell problem"); - } - }); - // TODO(kevinkassimo): maybe make include_deno_namespace also configurable? - let state = ThreadSafeState::new(flags, argv, progress, true) - .map_err(print_err_and_exit) - .unwrap(); - let worker = Worker::new( - "main".to_string(), - startup_data::deno_isolate_init(), - state.clone(), - ); - - (worker, state) -} - -fn types_command() { - let content = deno_cli_snapshots::get_asset("lib.deno_runtime.d.ts").unwrap(); - println!("{}", content); -} - -fn print_cache_info(worker: Worker) { - let state = worker.state; - - println!( - "{} {:?}", - colors::bold("DENO_DIR location:".to_string()), - state.dir.root - ); - println!( - "{} {:?}", - colors::bold("Remote modules cache:".to_string()), - state.dir.deps_cache.location - ); - println!( - "{} {:?}", - colors::bold("TypeScript compiler cache:".to_string()), - state.dir.gen_cache.location - ); -} - -pub fn print_file_info( - worker: Worker, - module_specifier: &ModuleSpecifier, -) -> impl Future<Item = Worker, Error = ()> { - let state_ = worker.state.clone(); - let module_specifier_ = module_specifier.clone(); - - state_ - .file_fetcher - .fetch_source_file_async(&module_specifier) - .map_err(|err| println!("{}", err)) - .and_then(|out| { - println!( - "{} {}", - colors::bold("local:".to_string()), - out.filename.to_str().unwrap() - ); - - println!( - "{} {}", - colors::bold("type:".to_string()), - msg::enum_name_media_type(out.media_type) - ); - - state_ - .clone() - .fetch_compiled_module(&module_specifier_) - .map_err(|e| { - debug!("compiler error exiting!"); - eprintln!("\n{}", e.to_string()); - std::process::exit(1); - }) - .and_then(move |compiled| { - if out.media_type == msg::MediaType::TypeScript - || (out.media_type == msg::MediaType::JavaScript - && state_.ts_compiler.compile_js) - { - let compiled_source_file = state_ - .ts_compiler - .get_compiled_source_file(&out.url) - .unwrap(); - - println!( - "{} {}", - colors::bold("compiled:".to_string()), - compiled_source_file.filename.to_str().unwrap(), - ); - } - - if let Ok(source_map) = state_ - .clone() - .ts_compiler - .get_source_map_file(&module_specifier_) - { - println!( - "{} {}", - colors::bold("map:".to_string()), - source_map.filename.to_str().unwrap() - ); - } - - if let Some(deps) = - worker.state.modules.lock().unwrap().deps(&compiled.name) - { - println!("{}{}", colors::bold("deps:\n".to_string()), deps.name); - if let Some(ref depsdeps) = deps.deps { - for d in depsdeps { - println!("{}", d); - } - } - } else { - println!( - "{} cannot retrieve full dependency graph", - colors::bold("deps:".to_string()), - ); - } - Ok(worker) - }) - }) -} - -fn info_command(flags: DenoFlags, argv: Vec<String>) { - let (mut worker, state) = create_worker_and_state(flags, argv.clone()); - - // If it was just "deno info" print location of caches and exit - if argv.len() == 1 { - return print_cache_info(worker); - } - - let main_module = state.main_module().unwrap(); - let main_future = lazy(move || { - // Setup runtime. - js_check(worker.execute("denoMain()")); - debug!("main_module {}", main_module); - - worker - .execute_mod_async(&main_module, true) - .map_err(print_err_and_exit) - .and_then(move |()| print_file_info(worker, &main_module)) - .and_then(|worker| { - worker.then(|result| { - js_check(result); - Ok(()) - }) - }) - }); - tokio_util::run(main_future); -} - -fn fetch_command(flags: DenoFlags, argv: Vec<String>) { - let (mut worker, state) = create_worker_and_state(flags, argv.clone()); - - let main_module = state.main_module().unwrap(); - let main_future = lazy(move || { - // Setup runtime. - js_check(worker.execute("denoMain()")); - debug!("main_module {}", main_module); - - worker.execute_mod_async(&main_module, true).then(|result| { - js_check(result); - Ok(()) - }) - }); - tokio_util::run(main_future); -} - -fn eval_command(flags: DenoFlags, argv: Vec<String>) { - let (mut worker, state) = create_worker_and_state(flags, argv); - // Wrap provided script in async function so asynchronous methods - // work. This is required until top-level await is not supported. - let js_source = format!( - "async function _topLevelWrapper(){{ - {} - }} - _topLevelWrapper(); - ", - &state.argv[1] - ); - - let main_future = lazy(move || { - js_check(worker.execute("denoMain()")); - // ATM imports in `deno eval` are not allowed - // TODO Support ES modules once Worker supports evaluating anonymous modules. - js_check(worker.execute(&js_source)); - worker.then(|result| { - js_check(result); - Ok(()) - }) - }); - tokio_util::run(main_future); -} - -fn xeval_command(flags: DenoFlags, argv: Vec<String>) { - let xeval_replvar = flags.xeval_replvar.clone().unwrap(); - let (mut worker, state) = create_worker_and_state(flags, argv); - let xeval_source = format!( - "window._xevalWrapper = async function ({}){{ - {} - }}", - &xeval_replvar, &state.argv[1] - ); - - let main_future = lazy(move || { - // Setup runtime. - js_check(worker.execute(&xeval_source)); - js_check(worker.execute("denoMain()")); - worker - .then(|result| { - js_check(result); - Ok(()) - }) - .map_err(print_err_and_exit) - }); - tokio_util::run(main_future); -} - -fn bundle_command(flags: DenoFlags, argv: Vec<String>) { - let (mut _worker, state) = create_worker_and_state(flags, argv); - - let main_module = state.main_module().unwrap(); - assert!(state.argv.len() >= 3); - let out_file = state.argv[2].clone(); - debug!(">>>>> bundle_async START"); - let bundle_future = state - .ts_compiler - .bundle_async(state.clone(), main_module.to_string(), out_file) - .map_err(|err| { - debug!("diagnostics returned, exiting!"); - eprintln!(""); - print_err_and_exit(err); - }) - .and_then(move |_| { - debug!(">>>>> bundle_async END"); - Ok(()) - }); - tokio_util::run(bundle_future); -} - -fn run_repl(flags: DenoFlags, argv: Vec<String>) { - let (mut worker, _state) = create_worker_and_state(flags, argv); - - // REPL situation. - let main_future = lazy(move || { - // Setup runtime. - js_check(worker.execute("denoMain()")); - worker - .then(|result| { - js_check(result); - Ok(()) - }) - .map_err(|(err, _worker): (ErrBox, Worker)| print_err_and_exit(err)) - }); - tokio_util::run(main_future); -} - -fn run_script(flags: DenoFlags, argv: Vec<String>) { - let use_current_thread = flags.current_thread; - let (mut worker, state) = create_worker_and_state(flags, argv); - - let main_module = state.main_module().unwrap(); - // Normal situation of executing a module. - let main_future = lazy(move || { - // Setup runtime. - js_check(worker.execute("denoMain()")); - debug!("main_module {}", main_module); - - worker - .execute_mod_async(&main_module, false) - .and_then(move |()| { - js_check(worker.execute("window.dispatchEvent(new Event('load'))")); - worker.then(|result| { - js_check(result); - Ok(()) - }) - }) - .map_err(print_err_and_exit) - }); - - if use_current_thread { - tokio_util::run_on_current_thread(main_future); - } else { - tokio_util::run(main_future); - } -} - -fn version_command() { - println!("deno: {}", version::DENO); - println!("v8: {}", version::v8()); - println!("typescript: {}", version::TYPESCRIPT); -} +extern crate deno_cli; fn main() { - #[cfg(windows)] - ansi_term::enable_ansi_support().ok(); // For Windows 10 - - log::set_logger(&LOGGER).unwrap(); - let args: Vec<String> = env::args().collect(); - let (flags, subcommand, argv) = flags::flags_from_vec(args); - - if let Some(ref v8_flags) = flags.v8_flags { - v8_set_flags(v8_flags.clone()); - } - - let log_level = match flags.log_level { - Some(level) => level, - None => Level::Warn, - }; - log::set_max_level(log_level.to_level_filter()); - - match subcommand { - DenoSubcommand::Bundle => bundle_command(flags, argv), - DenoSubcommand::Completions => {} - DenoSubcommand::Eval => eval_command(flags, argv), - DenoSubcommand::Fetch => fetch_command(flags, argv), - DenoSubcommand::Info => info_command(flags, argv), - DenoSubcommand::Repl => run_repl(flags, argv), - DenoSubcommand::Run => run_script(flags, argv), - DenoSubcommand::Types => types_command(), - DenoSubcommand::Version => version_command(), - DenoSubcommand::Xeval => xeval_command(flags, argv), - } + deno_cli::main(); } diff --git a/cli/tests/001_hello.js b/cli/tests/001_hello.js new file mode 100644 index 000000000..accefceba --- /dev/null +++ b/cli/tests/001_hello.js @@ -0,0 +1 @@ +console.log("Hello World"); diff --git a/cli/tests/001_hello.js.out b/cli/tests/001_hello.js.out new file mode 100644 index 000000000..557db03de --- /dev/null +++ b/cli/tests/001_hello.js.out @@ -0,0 +1 @@ +Hello World diff --git a/cli/tests/002_hello.ts b/cli/tests/002_hello.ts new file mode 100644 index 000000000..accefceba --- /dev/null +++ b/cli/tests/002_hello.ts @@ -0,0 +1 @@ +console.log("Hello World"); diff --git a/cli/tests/002_hello.ts.out b/cli/tests/002_hello.ts.out new file mode 100644 index 000000000..557db03de --- /dev/null +++ b/cli/tests/002_hello.ts.out @@ -0,0 +1 @@ +Hello World diff --git a/cli/tests/003_relative_import.ts b/cli/tests/003_relative_import.ts new file mode 100644 index 000000000..01d5d7faa --- /dev/null +++ b/cli/tests/003_relative_import.ts @@ -0,0 +1,3 @@ +import { printHello } from "./subdir/print_hello.ts"; + +printHello(); diff --git a/cli/tests/003_relative_import.ts.out b/cli/tests/003_relative_import.ts.out new file mode 100644 index 000000000..e965047ad --- /dev/null +++ b/cli/tests/003_relative_import.ts.out @@ -0,0 +1 @@ +Hello diff --git a/cli/tests/004_set_timeout.ts b/cli/tests/004_set_timeout.ts new file mode 100644 index 000000000..58f899ee3 --- /dev/null +++ b/cli/tests/004_set_timeout.ts @@ -0,0 +1,11 @@ +setTimeout((): void => { + console.log("World"); +}, 10); + +console.log("Hello"); + +const id = setTimeout((): void => { + console.log("Not printed"); +}, 10000); + +clearTimeout(id); diff --git a/cli/tests/004_set_timeout.ts.out b/cli/tests/004_set_timeout.ts.out new file mode 100644 index 000000000..f9264f7fb --- /dev/null +++ b/cli/tests/004_set_timeout.ts.out @@ -0,0 +1,2 @@ +Hello +World diff --git a/cli/tests/005_more_imports.ts b/cli/tests/005_more_imports.ts new file mode 100644 index 000000000..52dd1df7b --- /dev/null +++ b/cli/tests/005_more_imports.ts @@ -0,0 +1,11 @@ +import { returnsHi, returnsFoo2, printHello3 } from "./subdir/mod1.ts"; + +printHello3(); + +if (returnsHi() !== "Hi") { + throw Error("Unexpected"); +} + +if (returnsFoo2() !== "Foo") { + throw Error("Unexpected"); +} diff --git a/cli/tests/005_more_imports.ts.out b/cli/tests/005_more_imports.ts.out new file mode 100644 index 000000000..e965047ad --- /dev/null +++ b/cli/tests/005_more_imports.ts.out @@ -0,0 +1 @@ +Hello diff --git a/cli/tests/006_url_imports.ts b/cli/tests/006_url_imports.ts new file mode 100644 index 000000000..b2c7db270 --- /dev/null +++ b/cli/tests/006_url_imports.ts @@ -0,0 +1,3 @@ +import { printHello } from "http://localhost:4545/tests/subdir/mod2.ts"; +printHello(); +console.log("success"); diff --git a/cli/tests/006_url_imports.ts.out b/cli/tests/006_url_imports.ts.out new file mode 100644 index 000000000..989ce33e9 --- /dev/null +++ b/cli/tests/006_url_imports.ts.out @@ -0,0 +1,2 @@ +Hello +success diff --git a/cli/tests/012_async.ts b/cli/tests/012_async.ts new file mode 100644 index 000000000..1f1822c04 --- /dev/null +++ b/cli/tests/012_async.ts @@ -0,0 +1,13 @@ +// Check that we can use the async keyword. +async function main(): Promise<void> { + await new Promise( + (resolve): void => { + console.log("2"); + setTimeout(resolve, 100); + } + ); + console.log("3"); +} + +console.log("1"); +main(); diff --git a/cli/tests/012_async.ts.out b/cli/tests/012_async.ts.out new file mode 100644 index 000000000..01e79c32a --- /dev/null +++ b/cli/tests/012_async.ts.out @@ -0,0 +1,3 @@ +1 +2 +3 diff --git a/cli/tests/013_dynamic_import.ts b/cli/tests/013_dynamic_import.ts new file mode 100644 index 000000000..6bbce3132 --- /dev/null +++ b/cli/tests/013_dynamic_import.ts @@ -0,0 +1,15 @@ +(async (): Promise<void> => { + const { returnsHi, returnsFoo2, printHello3 } = await import( + "./subdir/mod1.ts" + ); + + printHello3(); + + if (returnsHi() !== "Hi") { + throw Error("Unexpected"); + } + + if (returnsFoo2() !== "Foo") { + throw Error("Unexpected"); + } +})(); diff --git a/cli/tests/013_dynamic_import.ts.out b/cli/tests/013_dynamic_import.ts.out new file mode 100644 index 000000000..e965047ad --- /dev/null +++ b/cli/tests/013_dynamic_import.ts.out @@ -0,0 +1 @@ +Hello diff --git a/cli/tests/014_duplicate_import.ts b/cli/tests/014_duplicate_import.ts new file mode 100644 index 000000000..97864fea7 --- /dev/null +++ b/cli/tests/014_duplicate_import.ts @@ -0,0 +1,9 @@ +// with all the imports of the same module, the module should only be +// instantiated once +import "./subdir/auto_print_hello.ts"; + +import "./subdir/auto_print_hello.ts"; + +(async (): Promise<void> => { + await import("./subdir/auto_print_hello.ts"); +})(); diff --git a/cli/tests/014_duplicate_import.ts.out b/cli/tests/014_duplicate_import.ts.out new file mode 100644 index 000000000..4effa19f4 --- /dev/null +++ b/cli/tests/014_duplicate_import.ts.out @@ -0,0 +1 @@ +hello! diff --git a/cli/tests/015_duplicate_parallel_import.js b/cli/tests/015_duplicate_parallel_import.js new file mode 100644 index 000000000..37033cfa2 --- /dev/null +++ b/cli/tests/015_duplicate_parallel_import.js @@ -0,0 +1,20 @@ +// Importing the same module in parallel, the module should only be +// instantiated once. + +const promises = new Array(100) + .fill(null) + .map(() => import("./subdir/mod1.ts")); + +Promise.all(promises).then(imports => { + const mod = imports.reduce((first, cur) => { + if (typeof first !== "object") { + throw new Error("Expected an object."); + } + if (first !== cur) { + throw new Error("More than one instance of the same module."); + } + return first; + }); + + mod.printHello3(); +}); diff --git a/cli/tests/015_duplicate_parallel_import.js.out b/cli/tests/015_duplicate_parallel_import.js.out new file mode 100644 index 000000000..e965047ad --- /dev/null +++ b/cli/tests/015_duplicate_parallel_import.js.out @@ -0,0 +1 @@ +Hello diff --git a/cli/tests/016_double_await.ts b/cli/tests/016_double_await.ts new file mode 100644 index 000000000..9b4801567 --- /dev/null +++ b/cli/tests/016_double_await.ts @@ -0,0 +1,8 @@ +// This is to test if Deno would die at 2nd await +// See https://github.com/denoland/deno/issues/919 +(async (): Promise<void> => { + const currDirInfo = await Deno.stat("."); + const parentDirInfo = await Deno.stat(".."); + console.log(currDirInfo.isDirectory()); + console.log(parentDirInfo.isFile()); +})(); diff --git a/cli/tests/016_double_await.ts.out b/cli/tests/016_double_await.ts.out new file mode 100644 index 000000000..da29283aa --- /dev/null +++ b/cli/tests/016_double_await.ts.out @@ -0,0 +1,2 @@ +true +false diff --git a/cli/tests/017_import_redirect.ts b/cli/tests/017_import_redirect.ts new file mode 100644 index 000000000..1265dd4ed --- /dev/null +++ b/cli/tests/017_import_redirect.ts @@ -0,0 +1,4 @@ +// http -> https redirect would happen: +import { printHello } from "http://gist.githubusercontent.com/ry/f12b2aa3409e6b52645bc346a9e22929/raw/79318f239f51d764384a8bded8d7c6a833610dde/print_hello.ts"; + +printHello(); diff --git a/cli/tests/017_import_redirect.ts.out b/cli/tests/017_import_redirect.ts.out new file mode 100644 index 000000000..e965047ad --- /dev/null +++ b/cli/tests/017_import_redirect.ts.out @@ -0,0 +1 @@ +Hello diff --git a/cli/tests/018_async_catch.ts b/cli/tests/018_async_catch.ts new file mode 100644 index 000000000..0d034d798 --- /dev/null +++ b/cli/tests/018_async_catch.ts @@ -0,0 +1,14 @@ +async function fn(): Promise<never> { + throw new Error("message"); +} +async function call(): Promise<void> { + try { + console.log("before await fn()"); + await fn(); + console.log("after await fn()"); + } catch (error) { + console.log("catch"); + } + console.log("after try-catch"); +} +call().catch((): void => console.log("outer catch")); diff --git a/cli/tests/018_async_catch.ts.out b/cli/tests/018_async_catch.ts.out new file mode 100644 index 000000000..4fc219973 --- /dev/null +++ b/cli/tests/018_async_catch.ts.out @@ -0,0 +1,3 @@ +before await fn() +catch +after try-catch diff --git a/cli/tests/019_media_types.ts b/cli/tests/019_media_types.ts new file mode 100644 index 000000000..5f1f862a0 --- /dev/null +++ b/cli/tests/019_media_types.ts @@ -0,0 +1,24 @@ +// When run against the test HTTP server, it will serve different media types +// based on the URL containing `.t#.` strings, which exercises the different +// mapping of media types end to end. + +import { loaded as loadedTs1 } from "http://localhost:4545/tests/subdir/mt_text_typescript.t1.ts"; +import { loaded as loadedTs2 } from "http://localhost:4545/tests/subdir/mt_video_vdn.t2.ts"; +import { loaded as loadedTs3 } from "http://localhost:4545/tests/subdir/mt_video_mp2t.t3.ts"; +import { loaded as loadedTs4 } from "http://localhost:4545/tests/subdir/mt_application_x_typescript.t4.ts"; +import { loaded as loadedJs1 } from "http://localhost:4545/tests/subdir/mt_text_javascript.j1.js"; +import { loaded as loadedJs2 } from "http://localhost:4545/tests/subdir/mt_application_ecmascript.j2.js"; +import { loaded as loadedJs3 } from "http://localhost:4545/tests/subdir/mt_text_ecmascript.j3.js"; +import { loaded as loadedJs4 } from "http://localhost:4545/tests/subdir/mt_application_x_javascript.j4.js"; + +console.log( + "success", + loadedTs1, + loadedTs2, + loadedTs3, + loadedTs4, + loadedJs1, + loadedJs2, + loadedJs3, + loadedJs4 +); diff --git a/cli/tests/019_media_types.ts.out b/cli/tests/019_media_types.ts.out new file mode 100644 index 000000000..7b5fdd44f --- /dev/null +++ b/cli/tests/019_media_types.ts.out @@ -0,0 +1 @@ +success true true true true true true true true diff --git a/cli/tests/020_json_modules.ts b/cli/tests/020_json_modules.ts new file mode 100644 index 000000000..fdc85c440 --- /dev/null +++ b/cli/tests/020_json_modules.ts @@ -0,0 +1,2 @@ +import config from "./subdir/config.json"; +console.log(JSON.stringify(config)); diff --git a/cli/tests/020_json_modules.ts.out b/cli/tests/020_json_modules.ts.out new file mode 100644 index 000000000..5d1623e6b --- /dev/null +++ b/cli/tests/020_json_modules.ts.out @@ -0,0 +1 @@ +{"foo":{"bar":true,"baz":["qat",1]}} diff --git a/cli/tests/021_mjs_modules.ts b/cli/tests/021_mjs_modules.ts new file mode 100644 index 000000000..6052b9081 --- /dev/null +++ b/cli/tests/021_mjs_modules.ts @@ -0,0 +1,2 @@ +import { isMod5 } from "./subdir/mod5.mjs"; +console.log(isMod5); diff --git a/cli/tests/021_mjs_modules.ts.out b/cli/tests/021_mjs_modules.ts.out new file mode 100644 index 000000000..27ba77dda --- /dev/null +++ b/cli/tests/021_mjs_modules.ts.out @@ -0,0 +1 @@ +true diff --git a/cli/tests/022_info_flag_script.out b/cli/tests/022_info_flag_script.out new file mode 100644 index 000000000..519e7cf6b --- /dev/null +++ b/cli/tests/022_info_flag_script.out @@ -0,0 +1,14 @@ +local: [WILDCARD]019_media_types.ts +type: TypeScript +compiled: [WILDCARD].js +map: [WILDCARD].js.map +deps: +http://127.0.0.1:4545/tests/019_media_types.ts + ├── http://localhost:4545/tests/subdir/mt_text_typescript.t1.ts + ├── http://localhost:4545/tests/subdir/mt_video_vdn.t2.ts + ├── http://localhost:4545/tests/subdir/mt_video_mp2t.t3.ts + ├── http://localhost:4545/tests/subdir/mt_application_x_typescript.t4.ts + ├── http://localhost:4545/tests/subdir/mt_text_javascript.j1.js + ├── http://localhost:4545/tests/subdir/mt_application_ecmascript.j2.js + ├── http://localhost:4545/tests/subdir/mt_text_ecmascript.j3.js + └── http://localhost:4545/tests/subdir/mt_application_x_javascript.j4.js diff --git a/cli/tests/023_no_ext_with_headers b/cli/tests/023_no_ext_with_headers new file mode 100644 index 000000000..87951d835 --- /dev/null +++ b/cli/tests/023_no_ext_with_headers @@ -0,0 +1 @@ +console.log("HELLO"); diff --git a/cli/tests/023_no_ext_with_headers.headers.json b/cli/tests/023_no_ext_with_headers.headers.json new file mode 100644 index 000000000..5b6f09aeb --- /dev/null +++ b/cli/tests/023_no_ext_with_headers.headers.json @@ -0,0 +1 @@ +{ "mime_type": "application/javascript" } diff --git a/cli/tests/023_no_ext_with_headers.out b/cli/tests/023_no_ext_with_headers.out new file mode 100644 index 000000000..e427984d4 --- /dev/null +++ b/cli/tests/023_no_ext_with_headers.out @@ -0,0 +1 @@ +HELLO diff --git a/cli/tests/024_import_no_ext_with_headers.ts b/cli/tests/024_import_no_ext_with_headers.ts new file mode 100644 index 000000000..c8621d0e6 --- /dev/null +++ b/cli/tests/024_import_no_ext_with_headers.ts @@ -0,0 +1 @@ +import "./023_no_ext_with_headers"; diff --git a/cli/tests/024_import_no_ext_with_headers.ts.out b/cli/tests/024_import_no_ext_with_headers.ts.out new file mode 100644 index 000000000..e427984d4 --- /dev/null +++ b/cli/tests/024_import_no_ext_with_headers.ts.out @@ -0,0 +1 @@ +HELLO diff --git a/cli/tests/025_hrtime.ts b/cli/tests/025_hrtime.ts new file mode 100644 index 000000000..417ca6982 --- /dev/null +++ b/cli/tests/025_hrtime.ts @@ -0,0 +1,3 @@ +console.log(performance.now() % 2 !== 0); +Deno.revokePermission("hrtime"); +console.log(performance.now() % 2 === 0); diff --git a/cli/tests/025_hrtime.ts.out b/cli/tests/025_hrtime.ts.out new file mode 100644 index 000000000..bb101b641 --- /dev/null +++ b/cli/tests/025_hrtime.ts.out @@ -0,0 +1,2 @@ +true +true diff --git a/cli/tests/025_reload_js_type_error.js b/cli/tests/025_reload_js_type_error.js new file mode 100644 index 000000000..8d6e4b415 --- /dev/null +++ b/cli/tests/025_reload_js_type_error.js @@ -0,0 +1,5 @@ +// There was a bug where if this was executed with --reload it would throw a +// type error. +window.test = null; +test = console; +test.log("hello"); diff --git a/cli/tests/025_reload_js_type_error.js.out b/cli/tests/025_reload_js_type_error.js.out new file mode 100644 index 000000000..ce0136250 --- /dev/null +++ b/cli/tests/025_reload_js_type_error.js.out @@ -0,0 +1 @@ +hello diff --git a/cli/tests/026_redirect_javascript.js b/cli/tests/026_redirect_javascript.js new file mode 100644 index 000000000..226a6b622 --- /dev/null +++ b/cli/tests/026_redirect_javascript.js @@ -0,0 +1,2 @@ +import { value } from "http://localhost:4547/redirects/redirect3.js"; +console.log(value); diff --git a/cli/tests/026_redirect_javascript.js.out b/cli/tests/026_redirect_javascript.js.out new file mode 100644 index 000000000..290864299 --- /dev/null +++ b/cli/tests/026_redirect_javascript.js.out @@ -0,0 +1 @@ +3 imports 1 diff --git a/cli/tests/026_workers.ts b/cli/tests/026_workers.ts new file mode 100644 index 000000000..f45fc4b77 --- /dev/null +++ b/cli/tests/026_workers.ts @@ -0,0 +1,14 @@ +const jsWorker = new Worker("./subdir/test_worker.js"); +const tsWorker = new Worker("./subdir/test_worker.ts"); + +tsWorker.onmessage = (e): void => { + console.log("Received ts: " + e.data); +}; + +jsWorker.onmessage = (e): void => { + console.log("Received js: " + e.data); + + tsWorker.postMessage("Hello World"); +}; + +jsWorker.postMessage("Hello World"); diff --git a/cli/tests/026_workers.ts.out b/cli/tests/026_workers.ts.out new file mode 100644 index 000000000..7538cc867 --- /dev/null +++ b/cli/tests/026_workers.ts.out @@ -0,0 +1,4 @@ +Hello World +Received js: Hello World +Hello World +Received ts: Hello World diff --git a/cli/tests/027_redirect_typescript.ts b/cli/tests/027_redirect_typescript.ts new file mode 100644 index 000000000..584341975 --- /dev/null +++ b/cli/tests/027_redirect_typescript.ts @@ -0,0 +1,2 @@ +import { value } from "http://localhost:4547/redirects/redirect4.ts"; +console.log(value); diff --git a/cli/tests/027_redirect_typescript.ts.out b/cli/tests/027_redirect_typescript.ts.out new file mode 100644 index 000000000..480d4e8ca --- /dev/null +++ b/cli/tests/027_redirect_typescript.ts.out @@ -0,0 +1 @@ +4 imports 1 diff --git a/cli/tests/028_args.ts b/cli/tests/028_args.ts new file mode 100644 index 000000000..51c5cb14b --- /dev/null +++ b/cli/tests/028_args.ts @@ -0,0 +1,5 @@ +Deno.args.forEach( + (arg): void => { + console.log(arg); + } +); diff --git a/cli/tests/028_args.ts.out b/cli/tests/028_args.ts.out new file mode 100644 index 000000000..fa36f6e4c --- /dev/null +++ b/cli/tests/028_args.ts.out @@ -0,0 +1,7 @@ +028_args.ts +--arg1 +val1 +--arg2=val2 +-- +arg3 +arg4 diff --git a/cli/tests/029_eval.out b/cli/tests/029_eval.out new file mode 100644 index 000000000..ce0136250 --- /dev/null +++ b/cli/tests/029_eval.out @@ -0,0 +1 @@ +hello diff --git a/cli/tests/030_xeval.out b/cli/tests/030_xeval.out new file mode 100644 index 000000000..b1e67221a --- /dev/null +++ b/cli/tests/030_xeval.out @@ -0,0 +1,3 @@ +A +B +C diff --git a/cli/tests/031_xeval_replvar.out b/cli/tests/031_xeval_replvar.out new file mode 100644 index 000000000..b1e67221a --- /dev/null +++ b/cli/tests/031_xeval_replvar.out @@ -0,0 +1,3 @@ +A +B +C diff --git a/cli/tests/032_xeval_delim.out b/cli/tests/032_xeval_delim.out new file mode 100644 index 000000000..b1e67221a --- /dev/null +++ b/cli/tests/032_xeval_delim.out @@ -0,0 +1,3 @@ +A +B +C diff --git a/cli/tests/033_import_map.out b/cli/tests/033_import_map.out new file mode 100644 index 000000000..e9b9160e9 --- /dev/null +++ b/cli/tests/033_import_map.out @@ -0,0 +1,7 @@ +Hello from remapped moment! +Hello from remapped moment dir! +Hello from remapped lodash! +Hello from remapped lodash dir! +Hello from remapped Vue! +Hello from scoped moment! +Hello from scoped! diff --git a/cli/tests/034_onload.out b/cli/tests/034_onload.out new file mode 100644 index 000000000..0939be8cd --- /dev/null +++ b/cli/tests/034_onload.out @@ -0,0 +1,7 @@ +log from nest_imported script +log from imported script +log from main +got load event in onload function +got load event in event handler (nest_imported) +got load event in event handler (imported) +got load event in event handler (main) diff --git a/cli/tests/034_onload/imported.ts b/cli/tests/034_onload/imported.ts new file mode 100644 index 000000000..5cf2d7b4c --- /dev/null +++ b/cli/tests/034_onload/imported.ts @@ -0,0 +1,8 @@ +import "./nest_imported.ts"; +window.addEventListener( + "load", + (e: Event): void => { + console.log(`got ${e.type} event in event handler (imported)`); + } +); +console.log("log from imported script"); diff --git a/cli/tests/034_onload/main.ts b/cli/tests/034_onload/main.ts new file mode 100644 index 000000000..68851950a --- /dev/null +++ b/cli/tests/034_onload/main.ts @@ -0,0 +1,14 @@ +import "./imported.ts"; + +window.addEventListener( + "load", + (e: Event): void => { + console.log(`got ${e.type} event in event handler (main)`); + } +); + +window.onload = (e: Event): void => { + console.log(`got ${e.type} event in onload function`); +}; + +console.log("log from main"); diff --git a/cli/tests/034_onload/nest_imported.ts b/cli/tests/034_onload/nest_imported.ts new file mode 100644 index 000000000..2e2bee1d5 --- /dev/null +++ b/cli/tests/034_onload/nest_imported.ts @@ -0,0 +1,7 @@ +window.addEventListener( + "load", + (e: Event): void => { + console.log(`got ${e.type} event in event handler (nest_imported)`); + } +); +console.log("log from nest_imported script"); diff --git a/cli/tests/034_onload_imported.ts b/cli/tests/034_onload_imported.ts new file mode 100644 index 000000000..d97aabeca --- /dev/null +++ b/cli/tests/034_onload_imported.ts @@ -0,0 +1 @@ +console.log("from imported script"); diff --git a/cli/tests/035_no_fetch_flag.out b/cli/tests/035_no_fetch_flag.out new file mode 100644 index 000000000..0c835830c --- /dev/null +++ b/cli/tests/035_no_fetch_flag.out @@ -0,0 +1 @@ +Cannot resolve module "http://127.0.0.1:4545/tests/019_media_types.ts" diff --git a/cli/tests/036_import_map_fetch.out b/cli/tests/036_import_map_fetch.out new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/cli/tests/036_import_map_fetch.out diff --git a/cli/tests/038_checkjs.js b/cli/tests/038_checkjs.js new file mode 100644 index 000000000..628d3e376 --- /dev/null +++ b/cli/tests/038_checkjs.js @@ -0,0 +1,6 @@ +// console.log intentionally misspelled to trigger a type error +consol.log("hello world!"); + +// the following error should be ignored and not output to the console +// eslint-disable-next-line +const foo = new Foo(); diff --git a/cli/tests/038_checkjs.js.out b/cli/tests/038_checkjs.js.out new file mode 100644 index 000000000..deaf77211 --- /dev/null +++ b/cli/tests/038_checkjs.js.out @@ -0,0 +1,15 @@ +[WILDCARD] +error TS2552: Cannot find name 'consol'. Did you mean 'console'? + +[WILDCARD]tests/038_checkjs.js:2:1 + +2 consol.log("hello world!"); +[WILDCARD] +error TS2552: Cannot find name 'Foo'. Did you mean 'foo'? + +[WILDCARD]tests/038_checkjs.js:6:17 + +6 const foo = new Foo(); +[WILDCARD] +Found 2 errors. +[WILDCARD]
\ No newline at end of file diff --git a/cli/tests/038_checkjs.tsconfig.json b/cli/tests/038_checkjs.tsconfig.json new file mode 100644 index 000000000..08ac60b6c --- /dev/null +++ b/cli/tests/038_checkjs.tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "checkJs": true + } +} diff --git a/cli/tests/039_worker_deno_ns.ts b/cli/tests/039_worker_deno_ns.ts new file mode 100644 index 000000000..80ada4343 --- /dev/null +++ b/cli/tests/039_worker_deno_ns.ts @@ -0,0 +1,25 @@ +const w1 = new Worker("./039_worker_deno_ns/has_ns.ts"); +const w2 = new Worker("./039_worker_deno_ns/no_ns.ts", { + noDenoNamespace: true +}); +let w1MsgCount = 0; +let w2MsgCount = 0; +w1.onmessage = (msg): void => { + console.log(msg.data); + w1MsgCount++; + if (w1MsgCount === 1) { + w1.postMessage("CONTINUE"); + } else { + w2.postMessage("START"); + } +}; +w2.onmessage = (msg): void => { + console.log(msg.data); + w2MsgCount++; + if (w2MsgCount === 1) { + w2.postMessage("CONTINUE"); + } else { + Deno.exit(0); + } +}; +w1.postMessage("START"); diff --git a/cli/tests/039_worker_deno_ns.ts.out b/cli/tests/039_worker_deno_ns.ts.out new file mode 100644 index 000000000..9b2f90099 --- /dev/null +++ b/cli/tests/039_worker_deno_ns.ts.out @@ -0,0 +1,4 @@ +has_ns.ts: is window.Deno available: true +[SPAWNED BY has_ns.ts] maybe_ns.ts: is window.Deno available: true +no_ns.ts: is window.Deno available: false +[SPAWNED BY no_ns.ts] maybe_ns.ts: is window.Deno available: false diff --git a/cli/tests/039_worker_deno_ns/has_ns.ts b/cli/tests/039_worker_deno_ns/has_ns.ts new file mode 100644 index 000000000..8d2507122 --- /dev/null +++ b/cli/tests/039_worker_deno_ns/has_ns.ts @@ -0,0 +1,10 @@ +onmessage = (msg): void => { + if (msg.data === "START") { + postMessage("has_ns.ts: is window.Deno available: " + !!window.Deno); + } else { + const worker = new Worker("./maybe_ns.ts"); + worker.onmessage = (msg): void => { + postMessage("[SPAWNED BY has_ns.ts] " + msg.data); + }; + } +}; diff --git a/cli/tests/039_worker_deno_ns/maybe_ns.ts b/cli/tests/039_worker_deno_ns/maybe_ns.ts new file mode 100644 index 000000000..0bcbd1f97 --- /dev/null +++ b/cli/tests/039_worker_deno_ns/maybe_ns.ts @@ -0,0 +1 @@ +postMessage("maybe_ns.ts: is window.Deno available: " + !!window.Deno); diff --git a/cli/tests/039_worker_deno_ns/no_ns.ts b/cli/tests/039_worker_deno_ns/no_ns.ts new file mode 100644 index 000000000..0489a00a3 --- /dev/null +++ b/cli/tests/039_worker_deno_ns/no_ns.ts @@ -0,0 +1,10 @@ +onmessage = (msg): void => { + if (msg.data === "START") { + postMessage("no_ns.ts: is window.Deno available: " + !!window.Deno); + } else { + const worker = new Worker("./maybe_ns.ts"); + worker.onmessage = (msg): void => { + postMessage("[SPAWNED BY no_ns.ts] " + msg.data); + }; + } +}; diff --git a/cli/tests/040_worker_blob.ts b/cli/tests/040_worker_blob.ts new file mode 100644 index 000000000..1ba4528cf --- /dev/null +++ b/cli/tests/040_worker_blob.ts @@ -0,0 +1,6 @@ +const b = new Blob(["console.log('code from Blob'); postMessage('DONE')"]); +const blobURL = URL.createObjectURL(b); +const worker = new Worker(blobURL); +worker.onmessage = (): void => { + Deno.exit(0); +}; diff --git a/cli/tests/040_worker_blob.ts.out b/cli/tests/040_worker_blob.ts.out new file mode 100644 index 000000000..f49b8f3d6 --- /dev/null +++ b/cli/tests/040_worker_blob.ts.out @@ -0,0 +1 @@ +code from Blob diff --git a/cli/tests/041_dyn_import_eval.out b/cli/tests/041_dyn_import_eval.out new file mode 100644 index 000000000..1dfef2e98 --- /dev/null +++ b/cli/tests/041_dyn_import_eval.out @@ -0,0 +1 @@ +{ isMod4: true } diff --git a/cli/tests/041_info_flag.out b/cli/tests/041_info_flag.out new file mode 100644 index 000000000..c384fa892 --- /dev/null +++ b/cli/tests/041_info_flag.out @@ -0,0 +1,3 @@ +DENO_DIR location: "[WILDCARD]" +Remote modules cache: "[WILDCARD]deps" +TypeScript compiler cache: "[WILDCARD]gen" diff --git a/cli/tests/042_dyn_import_evalcontext.ts b/cli/tests/042_dyn_import_evalcontext.ts new file mode 100644 index 000000000..124a406d2 --- /dev/null +++ b/cli/tests/042_dyn_import_evalcontext.ts @@ -0,0 +1,4 @@ +// @ts-ignore +Deno.core.evalContext( + "(async () => console.log(await import('./subdir/mod4.js')))()" +); diff --git a/cli/tests/042_dyn_import_evalcontext.ts.out b/cli/tests/042_dyn_import_evalcontext.ts.out new file mode 100644 index 000000000..1dfef2e98 --- /dev/null +++ b/cli/tests/042_dyn_import_evalcontext.ts.out @@ -0,0 +1 @@ +{ isMod4: true } diff --git a/cli/tests/043_xeval_delim2.out b/cli/tests/043_xeval_delim2.out new file mode 100644 index 000000000..312bdb964 --- /dev/null +++ b/cli/tests/043_xeval_delim2.out @@ -0,0 +1,2 @@ +!MAD +ADAM! diff --git a/cli/tests/043_xeval_delim2.test b/cli/tests/043_xeval_delim2.test new file mode 100644 index 000000000..1f009b3a7 --- /dev/null +++ b/cli/tests/043_xeval_delim2.test @@ -0,0 +1,3 @@ +args: xeval -d MADAM console.log($); +input: !MADMADAMADAM! +output: tests/043_xeval_delim2.out diff --git a/cli/tests/044_bad_resource.test b/cli/tests/044_bad_resource.test new file mode 100644 index 000000000..8804fde1b --- /dev/null +++ b/cli/tests/044_bad_resource.test @@ -0,0 +1,4 @@ +args: run --reload --allow-read tests/044_bad_resource.ts +output: tests/044_bad_resource.ts.out +check_stderr: true +exit_code: 1 diff --git a/cli/tests/044_bad_resource.ts b/cli/tests/044_bad_resource.ts new file mode 100644 index 000000000..d2fc828f0 --- /dev/null +++ b/cli/tests/044_bad_resource.ts @@ -0,0 +1,7 @@ +async function main(): Promise<void> { + const file = await Deno.open("Cargo.toml", "r"); + file.close(); + await file.seek(10, 0); +} + +main(); diff --git a/cli/tests/044_bad_resource.ts.out b/cli/tests/044_bad_resource.ts.out new file mode 100644 index 000000000..155e4396f --- /dev/null +++ b/cli/tests/044_bad_resource.ts.out @@ -0,0 +1,6 @@ +[WILDCARD] +error: Uncaught BadResource: bad resource id +[WILDCARD]dispatch_json.ts:[WILDCARD] + at DenoError ([WILDCARD]errors.ts:[WILDCARD]) + at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD]) + at sendAsync ([WILDCARD]dispatch_json.ts:[WILDCARD]) diff --git a/cli/tests/README.md b/cli/tests/README.md new file mode 100644 index 000000000..dc199196d --- /dev/null +++ b/cli/tests/README.md @@ -0,0 +1,7 @@ +# Integration Tests + +This path contains integration tests. See integration_tests.rs for the index. + +TODO(ry) Currently //tests is a symlink to //cli/tests, to simplify transition. +In the future //tests should be removed when all references to //tests are +updated. diff --git a/cli/tests/async_error.ts b/cli/tests/async_error.ts new file mode 100644 index 000000000..81c983a50 --- /dev/null +++ b/cli/tests/async_error.ts @@ -0,0 +1,8 @@ +console.log("hello"); +const foo = async (): Promise<never> => { + console.log("before error"); + throw Error("error"); +}; + +foo(); +console.log("world"); diff --git a/cli/tests/async_error.ts.out b/cli/tests/async_error.ts.out new file mode 100644 index 000000000..d07ba8cfe --- /dev/null +++ b/cli/tests/async_error.ts.out @@ -0,0 +1,11 @@ +[WILDCARD]hello +before error +world +error: Uncaught Error: error +[WILDCARD]tests/async_error.ts:4:9 + +4 throw Error("error"); + ^ + + at foo ([WILDCARD]tests/async_error.ts:4:9) + at [WILDCARD]tests/async_error.ts:7:1 diff --git a/cli/tests/badly_formatted.js b/cli/tests/badly_formatted.js new file mode 100644 index 000000000..17e3e6be0 --- /dev/null +++ b/cli/tests/badly_formatted.js @@ -0,0 +1,4 @@ + +console.log( + "Hello World" +) diff --git a/cli/tests/badly_formatted_fixed.js b/cli/tests/badly_formatted_fixed.js new file mode 100644 index 000000000..accefceba --- /dev/null +++ b/cli/tests/badly_formatted_fixed.js @@ -0,0 +1 @@ +console.log("Hello World"); diff --git a/cli/tests/cat.ts b/cli/tests/cat.ts new file mode 100644 index 000000000..756238be6 --- /dev/null +++ b/cli/tests/cat.ts @@ -0,0 +1,11 @@ +const { stdout, open, copy, args } = Deno; + +async function main(): Promise<void> { + for (let i = 1; i < args.length; i++) { + const filename = args[i]; + const file = await open(filename); + await copy(stdout, file); + } +} + +main(); diff --git a/cli/tests/circular1.js b/cli/tests/circular1.js new file mode 100644 index 000000000..8b2cc4960 --- /dev/null +++ b/cli/tests/circular1.js @@ -0,0 +1,2 @@ +import "./circular2.js"; +console.log("circular1"); diff --git a/cli/tests/circular1.js.out b/cli/tests/circular1.js.out new file mode 100644 index 000000000..21f7fd585 --- /dev/null +++ b/cli/tests/circular1.js.out @@ -0,0 +1,2 @@ +circular2 +circular1 diff --git a/cli/tests/circular2.js b/cli/tests/circular2.js new file mode 100644 index 000000000..62127e04d --- /dev/null +++ b/cli/tests/circular2.js @@ -0,0 +1,2 @@ +import "./circular1.js"; +console.log("circular2"); diff --git a/cli/tests/config.ts b/cli/tests/config.ts new file mode 100644 index 000000000..e08061e77 --- /dev/null +++ b/cli/tests/config.ts @@ -0,0 +1,5 @@ +const map = new Map<string, { foo: string }>(); + +if (map.get("bar").foo) { + console.log("here"); +} diff --git a/cli/tests/config.ts.out b/cli/tests/config.ts.out new file mode 100644 index 000000000..db5a8340e --- /dev/null +++ b/cli/tests/config.ts.out @@ -0,0 +1,10 @@ +[WILDCARD]Unsupported compiler options in "[WILDCARD]config.tsconfig.json" + The following options were ignored: + module, target +[WILDCARD]error TS2532: Object is possibly 'undefined'. + +[WILDCARD]tests/config.ts:3:5 + +3 if (map.get("bar").foo) { + ~~~~~~~~~~~~~~ + diff --git a/cli/tests/config.tsconfig.json b/cli/tests/config.tsconfig.json new file mode 100644 index 000000000..074d7ac0b --- /dev/null +++ b/cli/tests/config.tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "module": "amd", + "strict": true, + "target": "es5" + } +} diff --git a/cli/tests/echo_server.ts b/cli/tests/echo_server.ts new file mode 100644 index 000000000..73995eab5 --- /dev/null +++ b/cli/tests/echo_server.ts @@ -0,0 +1,11 @@ +const { args, listen, copy } = Deno; +const addr = args[1] || "127.0.0.1:4544"; +const listener = listen("tcp", addr); +console.log("listening on", addr); +listener.accept().then( + async (conn): Promise<void> => { + await copy(conn, conn); + conn.close(); + listener.close(); + } +); diff --git a/cli/tests/error_001.ts b/cli/tests/error_001.ts new file mode 100644 index 000000000..f06f80cb4 --- /dev/null +++ b/cli/tests/error_001.ts @@ -0,0 +1,9 @@ +function foo(): never { + throw Error("bad"); +} + +function bar(): void { + foo(); +} + +bar(); diff --git a/cli/tests/error_001.ts.out b/cli/tests/error_001.ts.out new file mode 100644 index 000000000..3c7e2828e --- /dev/null +++ b/cli/tests/error_001.ts.out @@ -0,0 +1,9 @@ +[WILDCARD]error: Uncaught Error: bad +[WILDCARD]tests/error_001.ts:2:9 + +2 throw Error("bad"); + ^ + + at foo ([WILDCARD]tests/error_001.ts:2:9) + at bar ([WILDCARD]tests/error_001.ts:6:3) + at [WILDCARD]tests/error_001.ts:9:1 diff --git a/cli/tests/error_002.ts b/cli/tests/error_002.ts new file mode 100644 index 000000000..eb66764b7 --- /dev/null +++ b/cli/tests/error_002.ts @@ -0,0 +1,7 @@ +import { throwsError } from "./subdir/mod1.ts"; + +function foo(): void { + throwsError(); +} + +foo(); diff --git a/cli/tests/error_002.ts.out b/cli/tests/error_002.ts.out new file mode 100644 index 000000000..292544a33 --- /dev/null +++ b/cli/tests/error_002.ts.out @@ -0,0 +1,9 @@ +[WILDCARD]error: Uncaught Error: exception from mod1 +[WILDCARD]tests/subdir/mod1.ts:16:9 + +16 throw Error("exception from mod1"); + ^ + + at throwsError ([WILDCARD]tests/subdir/mod1.ts:16:9) + at foo ([WILDCARD]tests/error_002.ts:4:3) + at [WILDCARD]tests/error_002.ts:7:1 diff --git a/cli/tests/error_003_typescript.ts b/cli/tests/error_003_typescript.ts new file mode 100644 index 000000000..6fb077ea0 --- /dev/null +++ b/cli/tests/error_003_typescript.ts @@ -0,0 +1,26 @@ +/* eslint-disable */ +interface Value<T> { + f?: (r: T) => any; + v?: string; +} + +interface C<T> { + values?: (r: T) => Array<Value<T>>; +} + +class A<T> { + constructor(private e?: T, public s?: C<T>) {} +} + +class B { + t = "foo"; +} + +var a = new A(new B(), { + values: o => [ + { + v: o.t, + f: x => "bar" + } + ] +}); diff --git a/cli/tests/error_003_typescript.ts.out b/cli/tests/error_003_typescript.ts.out new file mode 100644 index 000000000..f00a935e4 --- /dev/null +++ b/cli/tests/error_003_typescript.ts.out @@ -0,0 +1,28 @@ +[WILDCARD]error TS2322: Type '(o: T) => { v: any; f: (x: B) => string; }[]' is not assignable to type '(r: B) => Value<B>[]'. + Types of parameters 'o' and 'r' are incompatible. + Type 'B' is not assignable to type 'T'. + 'B' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{}'. + +[WILDCARD]tests/error_003_typescript.ts:20:3 + +20 values: o => [ + ~~~~~~ + + The expected type comes from property 'values' which is declared here on type 'C<B>' + + [WILDCARD]tests/error_003_typescript.ts:8:3 + + 8 values?: (r: T) => Array<Value<T>>; + ~~~~~~ + + +error TS2339: Property 't' does not exist on type 'T'. + +[WILDCARD]tests/error_003_typescript.ts:22:12 + +22 v: o.t, + ^ + + +Found 2 errors. + diff --git a/cli/tests/error_004_missing_module.ts b/cli/tests/error_004_missing_module.ts new file mode 100644 index 000000000..24ae52cf7 --- /dev/null +++ b/cli/tests/error_004_missing_module.ts @@ -0,0 +1,2 @@ +// eslint-disable-next-line +import * as badModule from "./bad-module.ts"; diff --git a/cli/tests/error_004_missing_module.ts.out b/cli/tests/error_004_missing_module.ts.out new file mode 100644 index 000000000..c2a0d0208 --- /dev/null +++ b/cli/tests/error_004_missing_module.ts.out @@ -0,0 +1,12 @@ +[WILDCARD]error: Uncaught NotFound: Cannot resolve module "[WILDCARD]/bad-module.ts" +[WILDCARD]dispatch_json.ts:[WILDCARD] + at DenoError ([WILDCARD]errors.ts:[WILDCARD]) + at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD]) + at sendSync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD]) + at fetchSourceFiles ([WILDCARD]compiler.ts:[WILDCARD]) + at _resolveModules ([WILDCARD]compiler.ts:[WILDCARD]) + at resolveModuleNames ([WILDCARD]compiler.ts:[WILDCARD]) + at resolveModuleNamesWorker ([WILDCARD]typescript.js:[WILDCARD]) + at resolveModuleNamesReusingOldState ([WILDCARD]typescript.js:[WILDCARD]) + at processImportedModules ([WILDCARD]typescript.js:[WILDCARD]) + at findSourceFile ([WILDCARD]typescript.js:[WILDCARD]) diff --git a/cli/tests/error_005_missing_dynamic_import.ts b/cli/tests/error_005_missing_dynamic_import.ts new file mode 100644 index 000000000..4c09feb5f --- /dev/null +++ b/cli/tests/error_005_missing_dynamic_import.ts @@ -0,0 +1,4 @@ +(async (): Promise<void> => { + // eslint-disable-next-line + const badModule = await import("./bad-module.ts"); +})(); diff --git a/cli/tests/error_005_missing_dynamic_import.ts.out b/cli/tests/error_005_missing_dynamic_import.ts.out new file mode 100644 index 000000000..ec1468b09 --- /dev/null +++ b/cli/tests/error_005_missing_dynamic_import.ts.out @@ -0,0 +1,12 @@ +[WILDCARD]error: Uncaught NotFound: Cannot resolve module "[WILDCARD]/bad-module.ts" +[WILDCARD]dispatch_json.ts:[WILDCARD] + at DenoError ([WILDCARD]errors.ts:[WILDCARD]) + at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD]) + at sendSync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD]) + at fetchSourceFiles ([WILDCARD]compiler.ts:[WILDCARD]) + at _resolveModules ([WILDCARD]compiler.ts:[WILDCARD]) + at [WILDCARD]compiler.ts:[WILDCARD] + at resolveModuleNamesWorker ([WILDCARD]) + at resolveModuleNamesReusingOldState ([WILDCARD]typescript.js:[WILDCARD]) + at processImportedModules ([WILDCARD]typescript.js:[WILDCARD]) + at findSourceFile ([WILDCARD]typescript.js:[WILDCARD]) diff --git a/cli/tests/error_006_import_ext_failure.ts b/cli/tests/error_006_import_ext_failure.ts new file mode 100644 index 000000000..3c32303a3 --- /dev/null +++ b/cli/tests/error_006_import_ext_failure.ts @@ -0,0 +1 @@ +import "./non-existent"; diff --git a/cli/tests/error_006_import_ext_failure.ts.out b/cli/tests/error_006_import_ext_failure.ts.out new file mode 100644 index 000000000..aa82c10aa --- /dev/null +++ b/cli/tests/error_006_import_ext_failure.ts.out @@ -0,0 +1,12 @@ +[WILDCARD]error: Uncaught NotFound: Cannot resolve module "[WILDCARD]/non-existent" +[WILDCARD]dispatch_json.ts:[WILDCARD] + at DenoError ([WILDCARD]errors.ts:[WILDCARD]) + at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD]) + at sendSync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD]) + at fetchSourceFiles ([WILDCARD]compiler.ts:[WILDCARD]) + at _resolveModules ([WILDCARD]compiler.ts:[WILDCARD]) + at [WILDCARD]compiler.ts:[WILDCARD] + at resolveModuleNamesWorker ([WILDCARD]) + at resolveModuleNamesReusingOldState ([WILDCARD]typescript.js:[WILDCARD]) + at processImportedModules ([WILDCARD]typescript.js:[WILDCARD]) + at findSourceFile ([WILDCARD]typescript.js:[WILDCARD]) diff --git a/cli/tests/error_007_any.ts b/cli/tests/error_007_any.ts new file mode 100644 index 000000000..778886fcb --- /dev/null +++ b/cli/tests/error_007_any.ts @@ -0,0 +1 @@ +throw {}; diff --git a/cli/tests/error_007_any.ts.out b/cli/tests/error_007_any.ts.out new file mode 100644 index 000000000..45dbffd04 --- /dev/null +++ b/cli/tests/error_007_any.ts.out @@ -0,0 +1 @@ +[WILDCARD]error: Uncaught #<Object> diff --git a/cli/tests/error_008_checkjs.js b/cli/tests/error_008_checkjs.js new file mode 100644 index 000000000..628d3e376 --- /dev/null +++ b/cli/tests/error_008_checkjs.js @@ -0,0 +1,6 @@ +// console.log intentionally misspelled to trigger a type error +consol.log("hello world!"); + +// the following error should be ignored and not output to the console +// eslint-disable-next-line +const foo = new Foo(); diff --git a/cli/tests/error_008_checkjs.js.out b/cli/tests/error_008_checkjs.js.out new file mode 100644 index 000000000..5c50e8513 --- /dev/null +++ b/cli/tests/error_008_checkjs.js.out @@ -0,0 +1,7 @@ +[WILDCARD]error: Uncaught ReferenceError: consol is not defined +[WILDCARD]tests/error_008_checkjs.js:2:1 + +2 consol.log("hello world!"); + ^ + + at [WILDCARD]tests/error_008_checkjs.js:2:1 diff --git a/cli/tests/error_009_missing_js_module.disabled b/cli/tests/error_009_missing_js_module.disabled new file mode 100644 index 000000000..b16bb232b --- /dev/null +++ b/cli/tests/error_009_missing_js_module.disabled @@ -0,0 +1,4 @@ +args: tests/error_009_missing_js_module.js +check_stderr: true +exit_code: 1 +output: tests/error_009_missing_js_module.js.out
\ No newline at end of file diff --git a/cli/tests/error_009_missing_js_module.js b/cli/tests/error_009_missing_js_module.js new file mode 100644 index 000000000..e6ca88934 --- /dev/null +++ b/cli/tests/error_009_missing_js_module.js @@ -0,0 +1 @@ +import "./bad-module.js"; diff --git a/cli/tests/error_009_missing_js_module.js.out b/cli/tests/error_009_missing_js_module.js.out new file mode 100644 index 000000000..edb08da1c --- /dev/null +++ b/cli/tests/error_009_missing_js_module.js.out @@ -0,0 +1 @@ +Cannot resolve module "./bad-module.js" from "[WILDCARD]error_009_missing_js_module.js" diff --git a/cli/tests/error_010_nonexistent_arg.disabled b/cli/tests/error_010_nonexistent_arg.disabled new file mode 100644 index 000000000..9d183107c --- /dev/null +++ b/cli/tests/error_010_nonexistent_arg.disabled @@ -0,0 +1,4 @@ +args: not-a-valid-filename.ts +output: tests/error_010_nonexistent_arg.out +exit_code: 1 +check_stderr: true diff --git a/cli/tests/error_010_nonexistent_arg.out b/cli/tests/error_010_nonexistent_arg.out new file mode 100644 index 000000000..ef4f7b041 --- /dev/null +++ b/cli/tests/error_010_nonexistent_arg.out @@ -0,0 +1 @@ +[WILDCARD]Cannot resolve module "file:[WILDCARD]not-a-valid-filename.ts" from "." diff --git a/cli/tests/error_011_bad_module_specifier.ts b/cli/tests/error_011_bad_module_specifier.ts new file mode 100644 index 000000000..e74d6b821 --- /dev/null +++ b/cli/tests/error_011_bad_module_specifier.ts @@ -0,0 +1,2 @@ +// eslint-disable-next-line +import * as badModule from "bad-module.ts"; diff --git a/cli/tests/error_011_bad_module_specifier.ts.out b/cli/tests/error_011_bad_module_specifier.ts.out new file mode 100644 index 000000000..97f59f2ca --- /dev/null +++ b/cli/tests/error_011_bad_module_specifier.ts.out @@ -0,0 +1,12 @@ +[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "bad-module.ts" not prefixed with / or ./ or ../ +[WILDCARD]dispatch_json.ts:[WILDCARD] + at DenoError ([WILDCARD]errors.ts:[WILDCARD]) + at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD]) + at sendSync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD]) + at fetchSourceFiles ([WILDCARD]compiler.ts:[WILDCARD]) + at _resolveModules ([WILDCARD]compiler.ts:[WILDCARD]) + at [WILDCARD]compiler.ts:[WILDCARD] + at resolveModuleNamesWorker ([WILDCARD]) + at resolveModuleNamesReusingOldState ([WILDCARD]typescript.js:[WILDCARD]) + at processImportedModules ([WILDCARD]typescript.js:[WILDCARD]) + at findSourceFile ([WILDCARD]typescript.js:[WILDCARD]) diff --git a/cli/tests/error_012_bad_dynamic_import_specifier.ts b/cli/tests/error_012_bad_dynamic_import_specifier.ts new file mode 100644 index 000000000..0420a80bf --- /dev/null +++ b/cli/tests/error_012_bad_dynamic_import_specifier.ts @@ -0,0 +1,4 @@ +(async (): Promise<void> => { + // eslint-disable-next-line + const badModule = await import("bad-module.ts"); +})(); diff --git a/cli/tests/error_012_bad_dynamic_import_specifier.ts.out b/cli/tests/error_012_bad_dynamic_import_specifier.ts.out new file mode 100644 index 000000000..97f59f2ca --- /dev/null +++ b/cli/tests/error_012_bad_dynamic_import_specifier.ts.out @@ -0,0 +1,12 @@ +[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "bad-module.ts" not prefixed with / or ./ or ../ +[WILDCARD]dispatch_json.ts:[WILDCARD] + at DenoError ([WILDCARD]errors.ts:[WILDCARD]) + at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD]) + at sendSync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD]) + at fetchSourceFiles ([WILDCARD]compiler.ts:[WILDCARD]) + at _resolveModules ([WILDCARD]compiler.ts:[WILDCARD]) + at [WILDCARD]compiler.ts:[WILDCARD] + at resolveModuleNamesWorker ([WILDCARD]) + at resolveModuleNamesReusingOldState ([WILDCARD]typescript.js:[WILDCARD]) + at processImportedModules ([WILDCARD]typescript.js:[WILDCARD]) + at findSourceFile ([WILDCARD]typescript.js:[WILDCARD]) diff --git a/cli/tests/error_013_missing_script.out b/cli/tests/error_013_missing_script.out new file mode 100644 index 000000000..9836c361f --- /dev/null +++ b/cli/tests/error_013_missing_script.out @@ -0,0 +1 @@ +Cannot resolve module "[WILDCARD]missing_file_name" diff --git a/cli/tests/error_014_catch_dynamic_import_error.js b/cli/tests/error_014_catch_dynamic_import_error.js new file mode 100644 index 000000000..ad3735fc3 --- /dev/null +++ b/cli/tests/error_014_catch_dynamic_import_error.js @@ -0,0 +1,31 @@ +(async () => { + try { + await import("does not exist"); + } catch (err) { + console.log("Caught direct dynamic import error."); + console.log(err); + } + + try { + await import("./subdir/indirect_import_error.js"); + } catch (err) { + console.log("Caught indirect direct dynamic import error."); + console.log(err); + } + + try { + await import("./subdir/throws.js"); + } catch (err) { + console.log("Caught error thrown by dynamically imported module."); + console.log(err); + } + + try { + await import("./subdir/indirect_throws.js"); + } catch (err) { + console.log( + "Caught error thrown indirectly by dynamically imported module." + ); + console.log(err); + } +})(); diff --git a/cli/tests/error_014_catch_dynamic_import_error.js.out b/cli/tests/error_014_catch_dynamic_import_error.js.out new file mode 100644 index 000000000..c18b680a1 --- /dev/null +++ b/cli/tests/error_014_catch_dynamic_import_error.js.out @@ -0,0 +1,12 @@ +Caught direct dynamic import error. +TypeError: relative import path "does not exist" not prefixed with / or ./ or ../ + +Caught indirect direct dynamic import error. +TypeError: relative import path "does not exist either" not prefixed with / or ./ or ../ + +Caught error thrown by dynamically imported module. +Error: An error + at file:///[WILDCARD]tests/subdir/throws.js:5:7 +Caught error thrown indirectly by dynamically imported module. +Error: An error + at file:///[WILDCARD]tests/subdir/throws.js:5:7 diff --git a/cli/tests/error_015_dynamic_import_permissions.js b/cli/tests/error_015_dynamic_import_permissions.js new file mode 100644 index 000000000..3460ca787 --- /dev/null +++ b/cli/tests/error_015_dynamic_import_permissions.js @@ -0,0 +1,3 @@ +(async () => { + await import("http://localhost:4545/tests/subdir/mod4.js"); +})(); diff --git a/cli/tests/error_015_dynamic_import_permissions.out b/cli/tests/error_015_dynamic_import_permissions.out new file mode 100644 index 000000000..90ccd0d1a --- /dev/null +++ b/cli/tests/error_015_dynamic_import_permissions.out @@ -0,0 +1 @@ +error: Uncaught TypeError: permission denied diff --git a/cli/tests/error_016_dynamic_import_permissions2.js b/cli/tests/error_016_dynamic_import_permissions2.js new file mode 100644 index 000000000..71c70815c --- /dev/null +++ b/cli/tests/error_016_dynamic_import_permissions2.js @@ -0,0 +1,5 @@ +// If this is executed with --allow-net but not --allow-read the following +// import should cause a permission denied error. +(async () => { + await import("http://localhost:4545/tests/subdir/evil_remote_import.js"); +})(); diff --git a/cli/tests/error_016_dynamic_import_permissions2.out b/cli/tests/error_016_dynamic_import_permissions2.out new file mode 100644 index 000000000..f52186481 --- /dev/null +++ b/cli/tests/error_016_dynamic_import_permissions2.out @@ -0,0 +1,2 @@ +[WILDCARD] +error: Uncaught TypeError: permission denied diff --git a/cli/tests/error_stack.ts b/cli/tests/error_stack.ts new file mode 100644 index 000000000..f2125d662 --- /dev/null +++ b/cli/tests/error_stack.ts @@ -0,0 +1,10 @@ +function foo(): never { + throw new Error("foo"); +} + +try { + foo(); +} catch (e) { + console.log(e); + throw e; +} diff --git a/cli/tests/error_stack.ts.out b/cli/tests/error_stack.ts.out new file mode 100644 index 000000000..2bb629e2d --- /dev/null +++ b/cli/tests/error_stack.ts.out @@ -0,0 +1,6 @@ +[WILDCARD]Error: foo + at foo ([WILDCARD]tests/error_stack.ts:2:9) + at [WILDCARD]tests/error_stack.ts:6:3 +error: Uncaught Error: foo + at foo ([WILDCARD]tests/error_stack.ts:2:9) + at [WILDCARD]tests/error_stack.ts:6:3 diff --git a/cli/tests/error_syntax.js b/cli/tests/error_syntax.js new file mode 100644 index 000000000..0c0c09855 --- /dev/null +++ b/cli/tests/error_syntax.js @@ -0,0 +1,3 @@ + +// prettier-ignore +(the following is a syntax error ^^ ! ) diff --git a/cli/tests/error_syntax.js.out b/cli/tests/error_syntax.js.out new file mode 100644 index 000000000..6253f3dd5 --- /dev/null +++ b/cli/tests/error_syntax.js.out @@ -0,0 +1,6 @@ +error: Uncaught SyntaxError: Unexpected identifier +[WILDCARD]tests/error_syntax.js:3:6 + +3 (the following is a syntax error ^^ ! ) + ~~~~~~~~~ + diff --git a/cli/tests/error_type_definitions.ts b/cli/tests/error_type_definitions.ts new file mode 100644 index 000000000..ceb11787e --- /dev/null +++ b/cli/tests/error_type_definitions.ts @@ -0,0 +1,5 @@ +// @deno-types="./type_definitions/bar.d.ts" +import { Bar } from "./type_definitions/bar.js"; + +const bar = new Bar(); +console.log(bar); diff --git a/cli/tests/error_type_definitions.ts.out b/cli/tests/error_type_definitions.ts.out new file mode 100644 index 000000000..cc09c149d --- /dev/null +++ b/cli/tests/error_type_definitions.ts.out @@ -0,0 +1,4 @@ +[WILDCARD]error: Uncaught TypeError: Automatic type resolution not supported +[WILDCARD]compiler.ts:[WILDCARD] + at fileExists ([WILDCARD]compiler.ts:[WILDCARD]) +[WILDCARD]
\ No newline at end of file diff --git a/cli/tests/esm_imports_a.js b/cli/tests/esm_imports_a.js new file mode 100644 index 000000000..673cd9aa3 --- /dev/null +++ b/cli/tests/esm_imports_a.js @@ -0,0 +1,3 @@ +import { retb } from "./esm_imports_b.js"; + +if (retb() != "b") throw Error(); diff --git a/cli/tests/esm_imports_b.js b/cli/tests/esm_imports_b.js new file mode 100644 index 000000000..321dfc05a --- /dev/null +++ b/cli/tests/esm_imports_b.js @@ -0,0 +1,3 @@ +export function retb() { + return "b"; +} diff --git a/cli/tests/exec_path.ts b/cli/tests/exec_path.ts new file mode 100644 index 000000000..b70b23237 --- /dev/null +++ b/cli/tests/exec_path.ts @@ -0,0 +1 @@ +console.log(Deno.execPath()); diff --git a/cli/tests/exit_error42.ts b/cli/tests/exit_error42.ts new file mode 100644 index 000000000..e4db41f3a --- /dev/null +++ b/cli/tests/exit_error42.ts @@ -0,0 +1,3 @@ +console.log("before"); +Deno.exit(42); +console.log("after"); diff --git a/cli/tests/exit_error42.ts.out b/cli/tests/exit_error42.ts.out new file mode 100644 index 000000000..90be1f305 --- /dev/null +++ b/cli/tests/exit_error42.ts.out @@ -0,0 +1 @@ +before diff --git a/cli/tests/fetch_deps.ts b/cli/tests/fetch_deps.ts new file mode 100644 index 000000000..370a8c561 --- /dev/null +++ b/cli/tests/fetch_deps.ts @@ -0,0 +1,14 @@ +// Run ./tools/http_server.py too in order for this test to run. +import { assert } from "../js/deps/https/deno.land/std/testing/asserts.ts"; + +// TODO Top level await https://github.com/denoland/deno/issues/471 +async function main(): Promise<void> { + const response = await fetch("http://localhost:4545/package.json"); + const json = await response.json(); + const deps = Object.keys(json.devDependencies); + console.log("Deno JS Deps"); + console.log(deps.map((d): string => `* ${d}`).join("\n")); + assert(deps.includes("typescript")); +} + +main(); diff --git a/cli/tests/hello.txt b/cli/tests/hello.txt new file mode 100644 index 000000000..6769dd60b --- /dev/null +++ b/cli/tests/hello.txt @@ -0,0 +1 @@ +Hello world!
\ No newline at end of file diff --git a/cli/tests/https_import.ts b/cli/tests/https_import.ts new file mode 100644 index 000000000..faaf2175f --- /dev/null +++ b/cli/tests/https_import.ts @@ -0,0 +1,5 @@ +// TODO Use https://localhost:4555/ but we need more infrastructure to +// support verifying self-signed certificates. +import { printHello } from "https://gist.githubusercontent.com/ry/f12b2aa3409e6b52645bc346a9e22929/raw/79318f239f51d764384a8bded8d7c6a833610dde/print_hello.ts"; + +printHello(); diff --git a/cli/tests/https_import.ts.out b/cli/tests/https_import.ts.out new file mode 100644 index 000000000..e965047ad --- /dev/null +++ b/cli/tests/https_import.ts.out @@ -0,0 +1 @@ +Hello diff --git a/cli/tests/if_main.ts b/cli/tests/if_main.ts new file mode 100644 index 000000000..b47066b2d --- /dev/null +++ b/cli/tests/if_main.ts @@ -0,0 +1,7 @@ +if (window.location.toString() == import.meta.url) { + console.log("main"); +} else { + console.log("import.meta.url", import.meta.url); + console.log("window.location", window.location.toString()); + throw Error("not main"); +} diff --git a/cli/tests/if_main.ts.out b/cli/tests/if_main.ts.out new file mode 100644 index 000000000..ba2906d06 --- /dev/null +++ b/cli/tests/if_main.ts.out @@ -0,0 +1 @@ +main diff --git a/cli/tests/import_meta.ts b/cli/tests/import_meta.ts new file mode 100644 index 000000000..d111059ea --- /dev/null +++ b/cli/tests/import_meta.ts @@ -0,0 +1,3 @@ +console.log("import_meta", import.meta.url, import.meta.main); + +import "./import_meta2.ts"; diff --git a/cli/tests/import_meta.ts.out b/cli/tests/import_meta.ts.out new file mode 100644 index 000000000..f38aa98ea --- /dev/null +++ b/cli/tests/import_meta.ts.out @@ -0,0 +1,2 @@ +import_meta2 [WILDCARD]import_meta2.ts false +import_meta [WILDCARD]import_meta.ts true diff --git a/cli/tests/import_meta2.ts b/cli/tests/import_meta2.ts new file mode 100644 index 000000000..7f59a5a46 --- /dev/null +++ b/cli/tests/import_meta2.ts @@ -0,0 +1 @@ +console.log("import_meta2", import.meta.url, import.meta.main); diff --git a/cli/tests/importmaps/import_map.json b/cli/tests/importmaps/import_map.json new file mode 100644 index 000000000..601874aab --- /dev/null +++ b/cli/tests/importmaps/import_map.json @@ -0,0 +1,14 @@ +{ + "imports": { + "moment": "./moment/moment.ts", + "moment/": "./moment/", + "lodash": "./lodash/lodash.ts", + "lodash/": "./lodash/", + "https://www.unpkg.com/vue/dist/vue.runtime.esm.js": "./vue.ts" + }, + "scopes": { + "scope/": { + "moment": "./scoped_moment.ts" + } + } +} diff --git a/cli/tests/importmaps/lodash/lodash.ts b/cli/tests/importmaps/lodash/lodash.ts new file mode 100644 index 000000000..2ec04ed3c --- /dev/null +++ b/cli/tests/importmaps/lodash/lodash.ts @@ -0,0 +1 @@ +console.log("Hello from remapped lodash!"); diff --git a/cli/tests/importmaps/lodash/other_file.ts b/cli/tests/importmaps/lodash/other_file.ts new file mode 100644 index 000000000..714adae3f --- /dev/null +++ b/cli/tests/importmaps/lodash/other_file.ts @@ -0,0 +1 @@ +console.log("Hello from remapped lodash dir!"); diff --git a/cli/tests/importmaps/moment/moment.ts b/cli/tests/importmaps/moment/moment.ts new file mode 100644 index 000000000..2b54a431e --- /dev/null +++ b/cli/tests/importmaps/moment/moment.ts @@ -0,0 +1 @@ +console.log("Hello from remapped moment!"); diff --git a/cli/tests/importmaps/moment/other_file.ts b/cli/tests/importmaps/moment/other_file.ts new file mode 100644 index 000000000..24f3a0226 --- /dev/null +++ b/cli/tests/importmaps/moment/other_file.ts @@ -0,0 +1 @@ +console.log("Hello from remapped moment dir!"); diff --git a/cli/tests/importmaps/scope/scoped.ts b/cli/tests/importmaps/scope/scoped.ts new file mode 100644 index 000000000..9a0b5d8e3 --- /dev/null +++ b/cli/tests/importmaps/scope/scoped.ts @@ -0,0 +1,2 @@ +import "moment"; +console.log("Hello from scoped!"); diff --git a/cli/tests/importmaps/scoped_moment.ts b/cli/tests/importmaps/scoped_moment.ts new file mode 100644 index 000000000..9f67f88d4 --- /dev/null +++ b/cli/tests/importmaps/scoped_moment.ts @@ -0,0 +1 @@ +console.log("Hello from scoped moment!"); diff --git a/cli/tests/importmaps/test.ts b/cli/tests/importmaps/test.ts new file mode 100644 index 000000000..9b09e9953 --- /dev/null +++ b/cli/tests/importmaps/test.ts @@ -0,0 +1,6 @@ +import "moment"; +import "moment/other_file.ts"; +import "lodash"; +import "lodash/other_file.ts"; +import "https://www.unpkg.com/vue/dist/vue.runtime.esm.js"; +import "./scope/scoped.ts"; diff --git a/cli/tests/importmaps/vue.ts b/cli/tests/importmaps/vue.ts new file mode 100644 index 000000000..76dbe1917 --- /dev/null +++ b/cli/tests/importmaps/vue.ts @@ -0,0 +1 @@ +console.log("Hello from remapped Vue!"); diff --git a/cli/integration_tests.rs b/cli/tests/integration_tests.rs index b03f69596..86de4fa6a 100644 --- a/cli/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -1,5 +1,8 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. -use crate::colors::strip_ansi_codes; +#[macro_use] +extern crate log; + +use deno_cli::colors::strip_ansi_codes; use os_pipe::pipe; use std::env; use std::io::Read; diff --git a/cli/tests/is_tty.ts b/cli/tests/is_tty.ts new file mode 100644 index 000000000..2e3fdb49f --- /dev/null +++ b/cli/tests/is_tty.ts @@ -0,0 +1 @@ +console.log(Deno.isTTY().stdin); diff --git a/cli/tests/no_color.js b/cli/tests/no_color.js new file mode 100644 index 000000000..cea11a52f --- /dev/null +++ b/cli/tests/no_color.js @@ -0,0 +1 @@ +console.log("noColor", Deno.noColor); diff --git a/cli/tests/seed_random.js b/cli/tests/seed_random.js new file mode 100644 index 000000000..7f6e336df --- /dev/null +++ b/cli/tests/seed_random.js @@ -0,0 +1,11 @@ +for (let i = 0; i < 10; ++i) { + console.log(Math.random()); +} + +const arr = new Uint8Array(32); + +crypto.getRandomValues(arr); +console.log(arr); + +crypto.getRandomValues(arr); +console.log(arr); diff --git a/cli/tests/seed_random.js.out b/cli/tests/seed_random.js.out new file mode 100644 index 000000000..c65e40f97 --- /dev/null +++ b/cli/tests/seed_random.js.out @@ -0,0 +1,12 @@ +0.858562739044346 +0.8973397944553141 +0.15335012655691727 +0.36867387434349963 +0.3591039342838782 +0.7044499748617652 +0.7461423057751548 +0.3824611207183364 +0.5950178237266042 +0.22440633214343908 +Uint8Array [ 116, 125, 169, 69, 106, 231, 99, 39, 148, 188, 211, 41, 46, 211, 236, 141, 55, 10, 214, 63, 118, 230, 218, 249, 125, 161, 137, 110, 214, 36, 159, 154 ] +Uint8Array [ 248, 21, 21, 9, 41, 0, 71, 124, 244, 209, 252, 151, 7, 10, 168, 250, 84, 170, 243, 140, 53, 47, 99, 212, 18, 146, 68, 48, 66, 222, 67, 112 ] diff --git a/cli/tests/subdir/auto_print_hello.ts b/cli/tests/subdir/auto_print_hello.ts new file mode 100644 index 000000000..5efa72e03 --- /dev/null +++ b/cli/tests/subdir/auto_print_hello.ts @@ -0,0 +1,2 @@ +console.log("hello!"); +export default {}; diff --git a/cli/tests/subdir/bench_worker.ts b/cli/tests/subdir/bench_worker.ts new file mode 100644 index 000000000..094cefb80 --- /dev/null +++ b/cli/tests/subdir/bench_worker.ts @@ -0,0 +1,20 @@ +onmessage = function(e): void { + const { cmdId, action, data } = e.data; + switch (action) { + case 0: // Static response + postMessage({ + cmdId, + data: "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n" + }); + break; + case 1: // Respond with request data + postMessage({ cmdId, data }); + break; + case 2: // Ping + postMessage({ cmdId }); + break; + case 3: // Close + workerClose(); + break; + } +}; diff --git a/cli/tests/subdir/config.json b/cli/tests/subdir/config.json new file mode 100644 index 000000000..01c3b5e79 --- /dev/null +++ b/cli/tests/subdir/config.json @@ -0,0 +1,6 @@ +{ + "foo": { + "bar": true, + "baz": ["qat", 1] + } +} diff --git a/cli/tests/subdir/evil_remote_import.js b/cli/tests/subdir/evil_remote_import.js new file mode 100644 index 000000000..4ff7d1b97 --- /dev/null +++ b/cli/tests/subdir/evil_remote_import.js @@ -0,0 +1,4 @@ +// We expect to get a permission denied error if we dynamically +// import this module without --allow-read. +export * from "file:///c:/etc/passwd"; +console.log("Hello from evil_remote_import.js"); diff --git a/cli/tests/subdir/form_urlencoded.txt b/cli/tests/subdir/form_urlencoded.txt new file mode 100644 index 000000000..70e087c20 --- /dev/null +++ b/cli/tests/subdir/form_urlencoded.txt @@ -0,0 +1 @@ +field_1=Hi&field_2=%3CDeno%3E
\ No newline at end of file diff --git a/cli/tests/subdir/indirect_import_error.js b/cli/tests/subdir/indirect_import_error.js new file mode 100644 index 000000000..84011d291 --- /dev/null +++ b/cli/tests/subdir/indirect_import_error.js @@ -0,0 +1 @@ +export * from "does not exist either"; diff --git a/cli/tests/subdir/indirect_throws.js b/cli/tests/subdir/indirect_throws.js new file mode 100644 index 000000000..e1810a66c --- /dev/null +++ b/cli/tests/subdir/indirect_throws.js @@ -0,0 +1 @@ +export * from "./throws.js"; diff --git a/cli/tests/subdir/mismatch_ext.ts b/cli/tests/subdir/mismatch_ext.ts new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/subdir/mismatch_ext.ts @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/subdir/mod1.ts b/cli/tests/subdir/mod1.ts new file mode 100644 index 000000000..393535588 --- /dev/null +++ b/cli/tests/subdir/mod1.ts @@ -0,0 +1,17 @@ +import { returnsFoo, printHello2 } from "./subdir2/mod2.ts"; + +export function returnsHi(): string { + return "Hi"; +} + +export function returnsFoo2(): string { + return returnsFoo(); +} + +export function printHello3(): void { + printHello2(); +} + +export function throwsError(): void { + throw Error("exception from mod1"); +} diff --git a/cli/tests/subdir/mod2.ts b/cli/tests/subdir/mod2.ts new file mode 100644 index 000000000..ce1adc0e8 --- /dev/null +++ b/cli/tests/subdir/mod2.ts @@ -0,0 +1 @@ +export { printHello } from "./print_hello.ts"; diff --git a/cli/tests/subdir/mod3.js b/cli/tests/subdir/mod3.js new file mode 100644 index 000000000..ce534f570 --- /dev/null +++ b/cli/tests/subdir/mod3.js @@ -0,0 +1 @@ +export const isTSFile = false; diff --git a/cli/tests/subdir/mod4.js b/cli/tests/subdir/mod4.js new file mode 100644 index 000000000..71332dbc4 --- /dev/null +++ b/cli/tests/subdir/mod4.js @@ -0,0 +1 @@ +export const isMod4 = true; diff --git a/cli/tests/subdir/mod5.mjs b/cli/tests/subdir/mod5.mjs new file mode 100644 index 000000000..f21d8862b --- /dev/null +++ b/cli/tests/subdir/mod5.mjs @@ -0,0 +1 @@ +export const isMod5 = true; diff --git a/cli/tests/subdir/mt_application_ecmascript.j2.js b/cli/tests/subdir/mt_application_ecmascript.j2.js new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/subdir/mt_application_ecmascript.j2.js @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/subdir/mt_application_x_javascript.j4.js b/cli/tests/subdir/mt_application_x_javascript.j4.js new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/subdir/mt_application_x_javascript.j4.js @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/subdir/mt_application_x_typescript.t4.ts b/cli/tests/subdir/mt_application_x_typescript.t4.ts new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/subdir/mt_application_x_typescript.t4.ts @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/subdir/mt_javascript.js b/cli/tests/subdir/mt_javascript.js new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/subdir/mt_javascript.js @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/subdir/mt_text_ecmascript.j3.js b/cli/tests/subdir/mt_text_ecmascript.j3.js new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/subdir/mt_text_ecmascript.j3.js @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/subdir/mt_text_javascript.j1.js b/cli/tests/subdir/mt_text_javascript.j1.js new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/subdir/mt_text_javascript.j1.js @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/subdir/mt_text_typescript.t1.ts b/cli/tests/subdir/mt_text_typescript.t1.ts new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/subdir/mt_text_typescript.t1.ts @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/subdir/mt_video_mp2t.t3.ts b/cli/tests/subdir/mt_video_mp2t.t3.ts new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/subdir/mt_video_mp2t.t3.ts @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/subdir/mt_video_vdn.t2.ts b/cli/tests/subdir/mt_video_vdn.t2.ts new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/subdir/mt_video_vdn.t2.ts @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/subdir/no_ext b/cli/tests/subdir/no_ext new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/subdir/no_ext @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/subdir/print_hello.ts b/cli/tests/subdir/print_hello.ts new file mode 100644 index 000000000..7ecce5040 --- /dev/null +++ b/cli/tests/subdir/print_hello.ts @@ -0,0 +1,3 @@ +export function printHello(): void { + console.log("Hello"); +} diff --git a/cli/tests/subdir/redirects/redirect1.js b/cli/tests/subdir/redirects/redirect1.js new file mode 100644 index 000000000..d674be88c --- /dev/null +++ b/cli/tests/subdir/redirects/redirect1.js @@ -0,0 +1 @@ +export const redirect = 1; diff --git a/cli/tests/subdir/redirects/redirect1.ts b/cli/tests/subdir/redirects/redirect1.ts new file mode 100644 index 000000000..d674be88c --- /dev/null +++ b/cli/tests/subdir/redirects/redirect1.ts @@ -0,0 +1 @@ +export const redirect = 1; diff --git a/cli/tests/subdir/redirects/redirect2.js b/cli/tests/subdir/redirects/redirect2.js new file mode 100644 index 000000000..e4244f638 --- /dev/null +++ b/cli/tests/subdir/redirects/redirect2.js @@ -0,0 +1 @@ +import "./redirect1.js"; diff --git a/cli/tests/subdir/redirects/redirect3.js b/cli/tests/subdir/redirects/redirect3.js new file mode 100644 index 000000000..e24f2af32 --- /dev/null +++ b/cli/tests/subdir/redirects/redirect3.js @@ -0,0 +1,2 @@ +import { redirect } from "./redirect1.js"; +export const value = `3 imports ${redirect}`; diff --git a/cli/tests/subdir/redirects/redirect4.ts b/cli/tests/subdir/redirects/redirect4.ts new file mode 100644 index 000000000..45c65c5eb --- /dev/null +++ b/cli/tests/subdir/redirects/redirect4.ts @@ -0,0 +1,2 @@ +import { redirect } from "./redirect1.ts"; +export const value = `4 imports ${redirect}`; diff --git a/cli/tests/subdir/subdir2/mod2.ts b/cli/tests/subdir/subdir2/mod2.ts new file mode 100644 index 000000000..c88d4708c --- /dev/null +++ b/cli/tests/subdir/subdir2/mod2.ts @@ -0,0 +1,9 @@ +import { printHello } from "../print_hello.ts"; + +export function returnsFoo(): string { + return "Foo"; +} + +export function printHello2(): void { + printHello(); +} diff --git a/cli/tests/subdir/test_worker.js b/cli/tests/subdir/test_worker.js new file mode 100644 index 000000000..53d38ba96 --- /dev/null +++ b/cli/tests/subdir/test_worker.js @@ -0,0 +1,7 @@ +onmessage = function(e) { + console.log(e.data); + + postMessage(e.data); + + workerClose(); +}; diff --git a/cli/tests/subdir/test_worker.ts b/cli/tests/subdir/test_worker.ts new file mode 100644 index 000000000..c8109d131 --- /dev/null +++ b/cli/tests/subdir/test_worker.ts @@ -0,0 +1,7 @@ +onmessage = function(e): void { + console.log(e.data); + + postMessage(e.data); + + workerClose(); +}; diff --git a/cli/tests/subdir/throws.js b/cli/tests/subdir/throws.js new file mode 100644 index 000000000..b77e7104f --- /dev/null +++ b/cli/tests/subdir/throws.js @@ -0,0 +1,5 @@ +export function boo() { + console.log("Boo!"); +} + +throw new Error("An error"); diff --git a/cli/tests/subdir/unknown_ext.deno b/cli/tests/subdir/unknown_ext.deno new file mode 100644 index 000000000..e67d2a017 --- /dev/null +++ b/cli/tests/subdir/unknown_ext.deno @@ -0,0 +1 @@ +export const loaded = true; diff --git a/cli/tests/type_definitions.ts b/cli/tests/type_definitions.ts new file mode 100644 index 000000000..ecf3ae0b2 --- /dev/null +++ b/cli/tests/type_definitions.ts @@ -0,0 +1,10 @@ +// @deno-types="./type_definitions/foo.d.ts" +import { foo } from "./type_definitions/foo.js"; +// @deno-types="./type_definitions/fizz.d.ts" +import "./type_definitions/fizz.js"; + +import * as qat from "./type_definitions/qat.ts"; + +console.log(foo); +console.log(fizz); +console.log(qat.qat); diff --git a/cli/tests/type_definitions.ts.out b/cli/tests/type_definitions.ts.out new file mode 100644 index 000000000..b4fa88c50 --- /dev/null +++ b/cli/tests/type_definitions.ts.out @@ -0,0 +1,3 @@ +[WILDCARD]foo +fizz +qat diff --git a/cli/tests/type_definitions/bar.d.ts b/cli/tests/type_definitions/bar.d.ts new file mode 100644 index 000000000..d43335dbb --- /dev/null +++ b/cli/tests/type_definitions/bar.d.ts @@ -0,0 +1,7 @@ +/// <reference types="baz" /> + +declare namespace bar { + export class Bar { + baz: string; + } +} diff --git a/cli/tests/type_definitions/fizz.d.ts b/cli/tests/type_definitions/fizz.d.ts new file mode 100644 index 000000000..34eb41b96 --- /dev/null +++ b/cli/tests/type_definitions/fizz.d.ts @@ -0,0 +1,2 @@ +/** A global value. */ +declare const fizz: string; diff --git a/cli/tests/type_definitions/fizz.js b/cli/tests/type_definitions/fizz.js new file mode 100644 index 000000000..852162c94 --- /dev/null +++ b/cli/tests/type_definitions/fizz.js @@ -0,0 +1 @@ +globalThis.fizz = "fizz"; diff --git a/cli/tests/type_definitions/foo.d.ts b/cli/tests/type_definitions/foo.d.ts new file mode 100644 index 000000000..ce39201e1 --- /dev/null +++ b/cli/tests/type_definitions/foo.d.ts @@ -0,0 +1,2 @@ +/** An exported value. */ +export const foo: string; diff --git a/cli/tests/type_definitions/foo.js b/cli/tests/type_definitions/foo.js new file mode 100644 index 000000000..61d366eb2 --- /dev/null +++ b/cli/tests/type_definitions/foo.js @@ -0,0 +1 @@ +export const foo = "foo"; diff --git a/cli/tests/type_definitions/qat.ts b/cli/tests/type_definitions/qat.ts new file mode 100644 index 000000000..6196c9d38 --- /dev/null +++ b/cli/tests/type_definitions/qat.ts @@ -0,0 +1 @@ +export const qat = "qat"; diff --git a/cli/tests/types.out b/cli/tests/types.out new file mode 100644 index 000000000..2d5a39e64 --- /dev/null +++ b/cli/tests/types.out @@ -0,0 +1,14 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +[WILDCARD] + +declare namespace Deno { +[WILDCARD] +} +[WILDCARD] +declare interface Window { +[WILDCARD] + Deno: typeof Deno; +} + +declare const window: Window; +[WILDCARD] diff --git a/cli/tests/unbuffered_stderr.ts b/cli/tests/unbuffered_stderr.ts new file mode 100644 index 000000000..f4bceb1fc --- /dev/null +++ b/cli/tests/unbuffered_stderr.ts @@ -0,0 +1,3 @@ +const { stderr } = Deno; + +stderr.write(new TextEncoder().encode("x")); diff --git a/cli/tests/unbuffered_stderr.ts.out b/cli/tests/unbuffered_stderr.ts.out new file mode 100644 index 000000000..500019738 --- /dev/null +++ b/cli/tests/unbuffered_stderr.ts.out @@ -0,0 +1,2 @@ +[WILDCARD] +x
\ No newline at end of file diff --git a/cli/tests/unbuffered_stdout.ts b/cli/tests/unbuffered_stdout.ts new file mode 100644 index 000000000..fdb1a0e23 --- /dev/null +++ b/cli/tests/unbuffered_stdout.ts @@ -0,0 +1,3 @@ +const { stdout } = Deno; + +stdout.write(new TextEncoder().encode("a")); diff --git a/cli/tests/unbuffered_stdout.ts.out b/cli/tests/unbuffered_stdout.ts.out new file mode 100644 index 000000000..2e65efe2a --- /dev/null +++ b/cli/tests/unbuffered_stdout.ts.out @@ -0,0 +1 @@ +a
\ No newline at end of file diff --git a/cli/tests/v8_flags.js b/cli/tests/v8_flags.js new file mode 100644 index 000000000..f7999c4af --- /dev/null +++ b/cli/tests/v8_flags.js @@ -0,0 +1 @@ +console.log(typeof gc); diff --git a/cli/tests/v8_flags.js.out b/cli/tests/v8_flags.js.out new file mode 100644 index 000000000..e2dbde096 --- /dev/null +++ b/cli/tests/v8_flags.js.out @@ -0,0 +1 @@ +function diff --git a/cli/tests/v8_help.out b/cli/tests/v8_help.out new file mode 100644 index 000000000..3d7aac28d --- /dev/null +++ b/cli/tests/v8_help.out @@ -0,0 +1,3 @@ +[WILDCARD] +Synopsis: +[WILDCARD]d8[WILDCARD]
\ No newline at end of file diff --git a/cli/tests/version.out b/cli/tests/version.out new file mode 100644 index 000000000..de13d769f --- /dev/null +++ b/cli/tests/version.out @@ -0,0 +1,3 @@ +deno:[WILDCARD] +v8:[WILDCARD] +typescript:[WILDCARD]
\ No newline at end of file diff --git a/cli/tests/wasm.ts b/cli/tests/wasm.ts new file mode 100644 index 000000000..26ad7ba28 --- /dev/null +++ b/cli/tests/wasm.ts @@ -0,0 +1,15 @@ +// prettier-ignore +const wasmCode = new Uint8Array([ + 0, 97, 115, 109, 1, 0, 0, 0, 1, 133, 128, 128, 128, 0, 1, 96, 0, 1, 127, + 3, 130, 128, 128, 128, 0, 1, 0, 4, 132, 128, 128, 128, 0, 1, 112, 0, 0, + 5, 131, 128, 128, 128, 0, 1, 0, 1, 6, 129, 128, 128, 128, 0, 0, 7, 145, + 128, 128, 128, 0, 2, 6, 109, 101, 109, 111, 114, 121, 2, 0, 4, 109, 97, + 105, 110, 0, 0, 10, 138, 128, 128, 128, 0, 1, 132, 128, 128, 128, 0, 0, + 65, 42, 11 + ]); + +const wasmModule = new WebAssembly.Module(wasmCode); + +const wasmInstance = new WebAssembly.Instance(wasmModule); + +console.log(wasmInstance.exports.main().toString()); diff --git a/cli/tests/wasm.ts.out b/cli/tests/wasm.ts.out new file mode 100644 index 000000000..d81cc0710 --- /dev/null +++ b/cli/tests/wasm.ts.out @@ -0,0 +1 @@ +42 diff --git a/cli/tests/wasm_async.js b/cli/tests/wasm_async.js new file mode 100644 index 000000000..98a178aad --- /dev/null +++ b/cli/tests/wasm_async.js @@ -0,0 +1,27 @@ +// The following blob can be created by taking the following s-expr and pass +// it through wat2wasm. +// (module +// (func $add (param $a i32) (param $b i32) (result i32) +// local.get $a +// local.get $b +// i32.add) +// (export "add" (func $add)) +// ) +// prettier-ignore +const bytes = new Uint8Array([ + 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01, 0x60, + 0x02, 0x7f, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07, 0x07, 0x01, + 0x03, 0x61, 0x64, 0x64, 0x00, 0x00, 0x0a, 0x09, 0x01, 0x07, 0x00, 0x20, + 0x00, 0x20, 0x01, 0x6a, 0x0b +]); + +async function main() { + const wasm = await WebAssembly.instantiate(bytes); + const result = wasm.instance.exports.add(1, 3); + console.log("1 + 3 =", result); + if (result != 4) { + throw Error("bad"); + } +} + +main(); diff --git a/cli/tests/wasm_async.out b/cli/tests/wasm_async.out new file mode 100644 index 000000000..5cdf17de7 --- /dev/null +++ b/cli/tests/wasm_async.out @@ -0,0 +1 @@ +1 + 3 = 4 diff --git a/cli/tests/workers_round_robin_bench.ts b/cli/tests/workers_round_robin_bench.ts new file mode 100644 index 000000000..7c34e75e5 --- /dev/null +++ b/cli/tests/workers_round_robin_bench.ts @@ -0,0 +1,79 @@ +// Benchmark measures time it takes to send a message to a group of workers one +// at a time and wait for a response from all of them. Just a general +// throughput and consistency benchmark. +const data = "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n"; +const workerCount = 4; +const cmdsPerWorker = 400; + +export interface ResolvableMethods<T> { + resolve: (value?: T | PromiseLike<T>) => void; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + reject: (reason?: any) => void; +} + +export type Resolvable<T> = Promise<T> & ResolvableMethods<T>; + +export function createResolvable<T>(): Resolvable<T> { + let methods: ResolvableMethods<T>; + const promise = new Promise<T>( + (resolve, reject): void => { + methods = { resolve, reject }; + } + ); + // TypeScript doesn't know that the Promise callback occurs synchronously + // therefore use of not null assertion (`!`) + return Object.assign(promise, methods!) as Resolvable<T>; +} + +function handleAsyncMsgFromWorker( + promiseTable: Map<number, Resolvable<string>>, + msg: { cmdId: number; data: string } +): void { + const promise = promiseTable.get(msg.cmdId); + if (promise === null) { + throw new Error(`Failed to find promise: cmdId: ${msg.cmdId}, msg: ${msg}`); + } + promise.resolve(data); +} + +async function main(): Promise<void> { + const workers: Array<[Map<number, Resolvable<string>>, Worker]> = []; + for (let i = 1; i <= workerCount; ++i) { + const worker = new Worker("./subdir/bench_worker.ts"); + const promise = new Promise( + (resolve): void => { + worker.onmessage = (e): void => { + if (e.data.cmdId === 0) resolve(); + }; + } + ); + worker.postMessage({ cmdId: 0, action: 2 }); + await promise; + workers.push([new Map(), worker]); + } + // assign callback function + for (const [promiseTable, worker] of workers) { + worker.onmessage = (e): void => { + handleAsyncMsgFromWorker(promiseTable, e.data); + }; + } + for (const cmdId of Array(cmdsPerWorker).keys()) { + const promises: Array<Promise<string>> = []; + for (const [promiseTable, worker] of workers) { + const promise = createResolvable<string>(); + promiseTable.set(cmdId, promise); + worker.postMessage({ cmdId: cmdId, action: 1, data }); + promises.push(promise); + } + for (const promise of promises) { + await promise; + } + } + for (const [, worker] of workers) { + worker.postMessage({ action: 3 }); + await worker.closed; // Required to avoid a cmdId not in table error. + } + console.log("Finished!"); +} + +main(); diff --git a/cli/tests/workers_startup_bench.ts b/cli/tests/workers_startup_bench.ts new file mode 100644 index 000000000..fbea4dc40 --- /dev/null +++ b/cli/tests/workers_startup_bench.ts @@ -0,0 +1,27 @@ +// Benchmark measures time it takes to start and stop a number of workers. +const workerCount = 50; + +async function bench(): Promise<void> { + const workers: Worker[] = []; + for (let i = 1; i <= workerCount; ++i) { + const worker = new Worker("./subdir/bench_worker.ts"); + const promise = new Promise( + (resolve): void => { + worker.onmessage = (e): void => { + if (e.data.cmdId === 0) resolve(); + }; + } + ); + worker.postMessage({ cmdId: 0, action: 2 }); + await promise; + workers.push(worker); + } + console.log("Done creating workers closing workers!"); + for (const worker of workers) { + worker.postMessage({ action: 3 }); + await worker.closed; // Required to avoid a cmdId not in table error. + } + console.log("Finished!"); +} + +bench(); |