2020-01-02 15:13:47 -05:00
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
2020-02-26 01:01:24 -05:00
#[ cfg(unix) ]
extern crate nix ;
2019-09-19 14:48:05 -04:00
extern crate tempfile ;
2019-10-29 17:52:57 -04:00
2020-06-18 11:54:55 -04:00
use test_util as util ;
2020-04-03 13:40:11 -04:00
use futures ::prelude ::* ;
2020-06-11 10:58:09 -04:00
use std ::io ::{ BufRead , Write } ;
2020-03-19 17:20:46 -04:00
use std ::process ::Command ;
use tempfile ::TempDir ;
2020-05-11 14:49:19 -04:00
#[ test ]
fn std_tests ( ) {
let dir = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
2020-05-11 17:33:36 -04:00
let std_path = util ::root_path ( ) . join ( " std " ) ;
2020-07-08 05:26:39 -04:00
let std_config = std_path . join ( " tsconfig_test.json " ) ;
2020-05-11 17:33:36 -04:00
let status = util ::deno_cmd ( )
. env ( " DENO_DIR " , dir . path ( ) )
. current_dir ( std_path ) // TODO(ry) change this to root_path
2020-05-11 14:49:19 -04:00
. arg ( " test " )
. arg ( " --unstable " )
. arg ( " --seed=86 " ) // Some tests rely on specific random numbers.
. arg ( " -A " )
2020-07-08 05:26:39 -04:00
. arg ( " --config " )
. arg ( std_config . to_str ( ) . unwrap ( ) )
2020-05-11 14:49:19 -04:00
// .arg("-Ldebug")
. spawn ( )
2020-05-11 17:33:36 -04:00
. unwrap ( )
. wait ( )
. unwrap ( ) ;
2020-05-11 14:49:19 -04:00
assert! ( status . success ( ) ) ;
}
2020-06-12 09:19:29 -04:00
#[ test ]
fn std_lint ( ) {
let status = util ::deno_cmd ( )
. arg ( " lint " )
. arg ( " --unstable " )
. arg ( util ::root_path ( ) . join ( " std " ) )
2020-06-19 05:05:37 -04:00
. arg ( util ::root_path ( ) . join ( " cli/tests/unit " ) )
2020-06-12 09:19:29 -04:00
. spawn ( )
. unwrap ( )
. wait ( )
. unwrap ( ) ;
assert! ( status . success ( ) ) ;
}
2020-05-09 12:43:24 -04:00
#[ test ]
fn x_deno_warning ( ) {
2020-08-10 17:31:05 -04:00
let _g = util ::http_server ( ) ;
2020-05-09 12:43:24 -04:00
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( " --reload " )
. arg ( " http://127.0.0.1:4545/cli/tests/x_deno_warning.js " )
. stdout ( std ::process ::Stdio ::piped ( ) )
. stderr ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( )
. wait_with_output ( )
. unwrap ( ) ;
assert! ( output . status . success ( ) ) ;
let stdout_str = std ::str ::from_utf8 ( & output . stdout ) . unwrap ( ) . trim ( ) ;
let stderr_str = std ::str ::from_utf8 ( & output . stderr ) . unwrap ( ) . trim ( ) ;
assert_eq! ( " testing x-deno-warning header " , stdout_str ) ;
2020-05-11 17:33:36 -04:00
assert! ( util ::strip_ansi_codes ( stderr_str ) . contains ( " Warning foobar " ) ) ;
2020-05-09 12:43:24 -04:00
}
2020-05-21 10:35:36 -04:00
#[ test ]
fn eval_p ( ) {
let output = util ::deno_cmd ( )
. arg ( " eval " )
. arg ( " -p " )
. arg ( " 1+2 " )
. stdout ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( )
. wait_with_output ( )
. unwrap ( ) ;
assert! ( output . status . success ( ) ) ;
let stdout_str =
util ::strip_ansi_codes ( std ::str ::from_utf8 ( & output . stdout ) . unwrap ( ) . trim ( ) ) ;
assert_eq! ( " 3 " , stdout_str ) ;
}
2020-06-11 10:58:09 -04:00
#[ test ]
fn run_from_stdin ( ) {
let mut deno = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( " - " )
. stdout ( std ::process ::Stdio ::piped ( ) )
. stdin ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( ) ;
deno
. stdin
. as_mut ( )
. unwrap ( )
. write_all ( b " console.log( \" Hello World \" ); " )
. unwrap ( ) ;
let output = deno . wait_with_output ( ) . unwrap ( ) ;
assert! ( output . status . success ( ) ) ;
let deno_out = std ::str ::from_utf8 ( & output . stdout ) . unwrap ( ) . trim ( ) ;
assert_eq! ( " Hello World " , deno_out ) ;
let mut deno = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( " - " )
. stdout ( std ::process ::Stdio ::piped ( ) )
. stdin ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( ) ;
deno
. stdin
. as_mut ( )
. unwrap ( )
. write_all ( b " console.log( \" Bye cached code \" ); " )
. unwrap ( ) ;
let output = deno . wait_with_output ( ) . unwrap ( ) ;
assert! ( output . status . success ( ) ) ;
let deno_out = std ::str ::from_utf8 ( & output . stdout ) . unwrap ( ) . trim ( ) ;
assert_eq! ( " Bye cached code " , deno_out ) ;
}
2020-05-06 16:34:48 -04:00
#[ test ]
fn no_color ( ) {
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( " cli/tests/no_color.js " )
. env ( " NO_COLOR " , " 1 " )
. stdout ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( )
. wait_with_output ( )
. unwrap ( ) ;
assert! ( output . status . success ( ) ) ;
let stdout_str = std ::str ::from_utf8 ( & output . stdout ) . unwrap ( ) . trim ( ) ;
assert_eq! ( " noColor true " , stdout_str ) ;
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( " cli/tests/no_color.js " )
. stdout ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( )
. wait_with_output ( )
. unwrap ( ) ;
assert! ( output . status . success ( ) ) ;
let stdout_str = std ::str ::from_utf8 ( & output . stdout ) . unwrap ( ) . trim ( ) ;
2020-05-19 14:19:26 -04:00
assert_eq! ( " noColor false " , util ::strip_ansi_codes ( stdout_str ) ) ;
2020-05-06 16:34:48 -04:00
}
2020-03-08 12:10:45 -04:00
// TODO re-enable. This hangs on macOS
// https://github.com/denoland/deno/issues/4262
2020-02-26 01:01:24 -05:00
#[ cfg(unix) ]
#[ test ]
2020-03-08 12:10:45 -04:00
#[ ignore ]
2020-02-26 01:01:24 -05:00
pub fn test_raw_tty ( ) {
use std ::io ::{ Read , Write } ;
2020-08-18 16:29:32 -04:00
use util ::pty ::fork ::* ;
2020-02-26 01:01:24 -05:00
let fork = Fork ::from_ptmx ( ) . unwrap ( ) ;
if let Ok ( mut master ) = fork . is_parent ( ) {
let mut obytes : [ u8 ; 100 ] = [ 0 ; 100 ] ;
let mut nread = master . read ( & mut obytes ) . unwrap ( ) ;
assert_eq! ( String ::from_utf8_lossy ( & obytes [ 0 .. nread ] ) , " S " ) ;
master . write_all ( b " a " ) . unwrap ( ) ;
nread = master . read ( & mut obytes ) . unwrap ( ) ;
assert_eq! ( String ::from_utf8_lossy ( & obytes [ 0 .. nread ] ) , " A " ) ;
master . write_all ( b " b " ) . unwrap ( ) ;
nread = master . read ( & mut obytes ) . unwrap ( ) ;
assert_eq! ( String ::from_utf8_lossy ( & obytes [ 0 .. nread ] ) , " B " ) ;
master . write_all ( b " c " ) . unwrap ( ) ;
nread = master . read ( & mut obytes ) . unwrap ( ) ;
assert_eq! ( String ::from_utf8_lossy ( & obytes [ 0 .. nread ] ) , " C " ) ;
} else {
use nix ::sys ::termios ;
use std ::os ::unix ::io ::AsRawFd ;
use std ::process ::* ;
// Turn off echo such that parent is reading works properly.
let stdin_fd = std ::io ::stdin ( ) . as_raw_fd ( ) ;
let mut t = termios ::tcgetattr ( stdin_fd ) . unwrap ( ) ;
t . local_flags . remove ( termios ::LocalFlags ::ECHO ) ;
termios ::tcsetattr ( stdin_fd , termios ::SetArg ::TCSANOW , & t ) . unwrap ( ) ;
let deno_dir = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
2020-05-11 17:33:36 -04:00
let mut child = Command ::new ( util ::deno_exe_path ( ) )
2020-02-26 01:01:24 -05:00
. env ( " DENO_DIR " , deno_dir . path ( ) )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( " cli/tests/raw_mode.ts " )
. stdin ( Stdio ::inherit ( ) )
. stdout ( Stdio ::inherit ( ) )
. stderr ( Stdio ::null ( ) )
. spawn ( )
. expect ( " Failed to spawn script " ) ;
child . wait ( ) . unwrap ( ) ;
}
}
2019-10-29 17:52:57 -04:00
#[ test ]
fn test_pattern_match ( ) {
2020-06-08 13:24:27 -04:00
// foo, bar, baz, qux, quux, quuz, corge, grault, garply, waldo, fred, plugh, xyzzy
let wildcard = " [BAR] " ;
assert! ( util ::pattern_match ( " foo[BAR]baz " , " foobarbaz " , wildcard ) ) ;
assert! ( ! util ::pattern_match ( " foo[BAR]baz " , " foobazbar " , wildcard ) ) ;
let multiline_pattern = " [BAR]
foo :
[ BAR ] baz [ BAR ] " ;
fn multi_line_builder ( input : & str , leading_text : Option < & str > ) -> String {
// If there is leading text add a newline so it's on it's own line
let head = match leading_text {
Some ( v ) = > format! ( " {} \n " , v ) ,
None = > " " . to_string ( ) ,
} ;
format! (
" {}foo:
quuz { } corge
grault " ,
head , input
)
}
// Validate multi-line string builder
assert_eq! (
" QUUX=qux
foo :
quuz BAZ corge
grault " ,
multi_line_builder ( " BAZ " , Some ( " QUUX=qux " ) )
) ;
// Correct input & leading line
assert! ( util ::pattern_match (
multiline_pattern ,
& multi_line_builder ( " baz " , Some ( " QUX=quux " ) ) ,
wildcard
) ) ;
// Correct input & no leading line
assert! ( util ::pattern_match (
multiline_pattern ,
& multi_line_builder ( " baz " , None ) ,
wildcard
) ) ;
// Incorrect input & leading line
assert! ( ! util ::pattern_match (
multiline_pattern ,
& multi_line_builder ( " garply " , Some ( " QUX=quux " ) ) ,
wildcard
) ) ;
// Incorrect input & no leading line
assert! ( ! util ::pattern_match (
multiline_pattern ,
& multi_line_builder ( " garply " , None ) ,
wildcard
) ) ;
2019-10-29 17:52:57 -04:00
}
2019-09-16 21:05:14 -04:00
2019-09-19 14:48:05 -04:00
#[ test ]
fn deno_dir_test ( ) {
2020-05-15 10:22:28 -04:00
use std ::fs ::remove_dir_all ;
2020-08-10 17:31:05 -04:00
let _g = util ::http_server ( ) ;
2020-05-15 10:22:28 -04:00
let deno_dir = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
remove_dir_all ( deno_dir . path ( ) ) . unwrap ( ) ;
// Run deno with no env flag
let status = util ::deno_cmd ( )
. env_remove ( " DENO_DIR " )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( " http://localhost:4545/cli/tests/subdir/print_hello.ts " )
. spawn ( )
. expect ( " Failed to spawn script " )
. wait ( )
. expect ( " Failed to wait for child process " ) ;
assert! ( status . success ( ) ) ;
assert! ( ! deno_dir . path ( ) . exists ( ) ) ;
// Run deno with DENO_DIR env flag
let status = util ::deno_cmd ( )
. env ( " DENO_DIR " , deno_dir . path ( ) )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( " http://localhost:4545/cli/tests/subdir/print_hello.ts " )
. spawn ( )
. expect ( " Failed to spawn script " )
. wait ( )
. expect ( " Failed to wait for child process " ) ;
assert! ( status . success ( ) ) ;
assert! ( deno_dir . path ( ) . is_dir ( ) ) ;
assert! ( deno_dir . path ( ) . join ( " deps " ) . is_dir ( ) ) ;
assert! ( deno_dir . path ( ) . join ( " gen " ) . is_dir ( ) ) ;
remove_dir_all ( deno_dir . path ( ) ) . unwrap ( ) ;
2019-09-19 14:48:05 -04:00
}
#[ test ]
2020-05-11 14:49:19 -04:00
fn cache_test ( ) {
2020-08-10 17:31:05 -04:00
let _g = util ::http_server ( ) ;
2020-02-04 17:42:07 -05:00
let deno_dir = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
2020-02-19 08:17:13 -05:00
let module_url =
2020-05-11 14:49:19 -04:00
url ::Url ::parse ( " http://localhost:4545/cli/tests/006_url_imports.ts " )
. unwrap ( ) ;
let output = Command ::new ( util ::deno_exe_path ( ) )
2020-02-04 17:42:07 -05:00
. env ( " DENO_DIR " , deno_dir . path ( ) )
. current_dir ( util ::root_path ( ) )
2020-04-07 11:24:47 -04:00
. arg ( " cache " )
2020-02-19 08:17:13 -05:00
. arg ( module_url . to_string ( ) )
2020-02-04 17:42:07 -05:00
. output ( )
. expect ( " Failed to spawn script " ) ;
2020-02-27 15:39:41 -05:00
assert! ( output . status . success ( ) ) ;
2020-02-04 17:42:07 -05:00
let out = std ::str ::from_utf8 ( & output . stdout ) . unwrap ( ) ;
assert_eq! ( out , " " ) ;
2020-05-11 14:49:19 -04:00
// TODO(ry) Is there some way to check that the file was actually cached in
// DENO_DIR?
2019-09-19 14:48:05 -04:00
}
#[ test ]
fn fmt_test ( ) {
2020-01-29 21:16:48 -05:00
let t = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
let fixed = util ::root_path ( ) . join ( " cli/tests/badly_formatted_fixed.js " ) ;
let badly_formatted_original =
2020-07-14 15:24:17 -04:00
util ::root_path ( ) . join ( " cli/tests/badly_formatted.mjs " ) ;
2020-01-29 21:16:48 -05:00
let badly_formatted = t . path ( ) . join ( " badly_formatted.js " ) ;
let badly_formatted_str = badly_formatted . to_str ( ) . unwrap ( ) ;
std ::fs ::copy ( & badly_formatted_original , & badly_formatted )
. expect ( " Failed to copy file " ) ;
2020-07-30 12:09:08 -04:00
// First, check formatting by ignoring the badly formatted file.
let status = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " fmt " )
. arg ( format! ( " --ignore= {} " , badly_formatted_str ) )
. arg ( " --unstable " )
. arg ( " --check " )
. arg ( badly_formatted_str )
. spawn ( )
. expect ( " Failed to spawn script " )
. wait ( )
. expect ( " Failed to wait for child process " ) ;
assert! ( status . success ( ) ) ;
// Check without ignore.
2020-01-29 21:16:48 -05:00
let status = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " fmt " )
. arg ( " --check " )
. arg ( badly_formatted_str )
. spawn ( )
. expect ( " Failed to spawn script " )
. wait ( )
. expect ( " Failed to wait for child process " ) ;
2020-02-27 15:39:41 -05:00
assert! ( ! status . success ( ) ) ;
2020-07-30 12:09:08 -04:00
// Format the source file.
2020-01-29 21:16:48 -05:00
let status = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " fmt " )
. arg ( badly_formatted_str )
. spawn ( )
. expect ( " Failed to spawn script " )
. wait ( )
. expect ( " Failed to wait for child process " ) ;
2020-02-27 15:39:41 -05:00
assert! ( status . success ( ) ) ;
2020-01-29 21:16:48 -05:00
let expected = std ::fs ::read_to_string ( fixed ) . unwrap ( ) ;
let actual = std ::fs ::read_to_string ( badly_formatted ) . unwrap ( ) ;
assert_eq! ( expected , actual ) ;
2019-09-19 14:48:05 -04:00
}
2020-02-27 15:39:41 -05:00
#[ test ]
fn fmt_stdin_error ( ) {
use std ::io ::Write ;
let mut deno = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " fmt " )
. arg ( " - " )
. stdin ( std ::process ::Stdio ::piped ( ) )
. stdout ( std ::process ::Stdio ::piped ( ) )
. stderr ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( ) ;
let stdin = deno . stdin . as_mut ( ) . unwrap ( ) ;
let invalid_js = b " import { example } " ;
stdin . write_all ( invalid_js ) . unwrap ( ) ;
let output = deno . wait_with_output ( ) . unwrap ( ) ;
// Error message might change. Just check stdout empty, stderr not.
assert! ( output . stdout . is_empty ( ) ) ;
assert! ( ! output . stderr . is_empty ( ) ) ;
assert! ( ! output . status . success ( ) ) ;
}
2020-03-23 11:37:24 -04:00
// Warning: this test requires internet access.
#[ test ]
fn upgrade_in_tmpdir ( ) {
let temp_dir = TempDir ::new ( ) . unwrap ( ) ;
2020-07-06 18:21:26 -04:00
let exe_path = temp_dir . path ( ) . join ( " deno " ) ;
2020-03-23 11:37:24 -04:00
let _ = std ::fs ::copy ( util ::deno_exe_path ( ) , & exe_path ) . unwrap ( ) ;
assert! ( exe_path . exists ( ) ) ;
let _mtime1 = std ::fs ::metadata ( & exe_path ) . unwrap ( ) . modified ( ) . unwrap ( ) ;
let status = Command ::new ( & exe_path )
. arg ( " upgrade " )
. arg ( " --force " )
. spawn ( )
. unwrap ( )
. wait ( )
. unwrap ( ) ;
assert! ( status . success ( ) ) ;
let _mtime2 = std ::fs ::metadata ( & exe_path ) . unwrap ( ) . modified ( ) . unwrap ( ) ;
// TODO(ry) assert!(mtime1 < mtime2);
}
2020-06-29 09:13:07 -04:00
// Warning: this test requires internet access.
#[ test ]
fn upgrade_with_space_in_path ( ) {
let temp_dir = tempfile ::Builder ::new ( )
. prefix ( " directory with spaces " )
. tempdir ( )
. unwrap ( ) ;
let exe_path = temp_dir . path ( ) . join ( " deno " ) ;
let _ = std ::fs ::copy ( util ::deno_exe_path ( ) , & exe_path ) . unwrap ( ) ;
assert! ( exe_path . exists ( ) ) ;
let status = Command ::new ( & exe_path )
. arg ( " upgrade " )
. arg ( " --force " )
. env ( " TMP " , temp_dir . path ( ) )
. spawn ( )
. unwrap ( )
. wait ( )
. unwrap ( ) ;
assert! ( status . success ( ) ) ;
}
2020-05-09 06:31:15 -04:00
// Warning: this test requires internet access.
#[ test ]
fn upgrade_with_version_in_tmpdir ( ) {
let temp_dir = TempDir ::new ( ) . unwrap ( ) ;
2020-07-06 18:21:26 -04:00
let exe_path = temp_dir . path ( ) . join ( " deno " ) ;
2020-05-09 06:31:15 -04:00
let _ = std ::fs ::copy ( util ::deno_exe_path ( ) , & exe_path ) . unwrap ( ) ;
assert! ( exe_path . exists ( ) ) ;
let _mtime1 = std ::fs ::metadata ( & exe_path ) . unwrap ( ) . modified ( ) . unwrap ( ) ;
let status = Command ::new ( & exe_path )
. arg ( " upgrade " )
. arg ( " --force " )
. arg ( " --version " )
. arg ( " 0.42.0 " )
. spawn ( )
. unwrap ( )
. wait ( )
. unwrap ( ) ;
assert! ( status . success ( ) ) ;
let upgraded_deno_version = String ::from_utf8 (
Command ::new ( & exe_path ) . arg ( " -V " ) . output ( ) . unwrap ( ) . stdout ,
)
. unwrap ( ) ;
assert! ( upgraded_deno_version . contains ( " 0.42.0 " ) ) ;
let _mtime2 = std ::fs ::metadata ( & exe_path ) . unwrap ( ) . modified ( ) . unwrap ( ) ;
// TODO(ry) assert!(mtime1 < mtime2);
}
2020-07-06 18:21:26 -04:00
// Warning: this test requires internet access.
#[ test ]
fn upgrade_with_out_in_tmpdir ( ) {
let temp_dir = TempDir ::new ( ) . unwrap ( ) ;
let exe_path = temp_dir . path ( ) . join ( " deno " ) ;
let new_exe_path = temp_dir . path ( ) . join ( " foo " ) ;
let _ = std ::fs ::copy ( util ::deno_exe_path ( ) , & exe_path ) . unwrap ( ) ;
assert! ( exe_path . exists ( ) ) ;
let mtime1 = std ::fs ::metadata ( & exe_path ) . unwrap ( ) . modified ( ) . unwrap ( ) ;
let status = Command ::new ( & exe_path )
. arg ( " upgrade " )
. arg ( " --version " )
. arg ( " 1.0.2 " )
. arg ( " --output " )
. arg ( & new_exe_path . to_str ( ) . unwrap ( ) )
. spawn ( )
. unwrap ( )
. wait ( )
. unwrap ( ) ;
assert! ( status . success ( ) ) ;
assert! ( new_exe_path . exists ( ) ) ;
let mtime2 = std ::fs ::metadata ( & exe_path ) . unwrap ( ) . modified ( ) . unwrap ( ) ;
assert_eq! ( mtime1 , mtime2 ) ; // Original exe_path was not changed.
let v = String ::from_utf8 (
Command ::new ( & new_exe_path )
. arg ( " -V " )
. output ( )
. unwrap ( )
. stdout ,
)
. unwrap ( ) ;
assert! ( v . contains ( " 1.0.2 " ) ) ;
}
2020-01-31 11:34:50 -05:00
#[ test ]
fn installer_test_local_module_run ( ) {
let temp_dir = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
2020-04-16 18:15:42 -04:00
let bin_dir = temp_dir . path ( ) . join ( " bin " ) ;
std ::fs ::create_dir ( & bin_dir ) . unwrap ( ) ;
2020-05-11 17:33:36 -04:00
let status = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " install " )
. arg ( " --name " )
. arg ( " echo_test " )
. arg ( " --root " )
. arg ( temp_dir . path ( ) )
. arg ( util ::tests_path ( ) . join ( " echo.ts " ) )
. arg ( " hello " )
. spawn ( )
. unwrap ( )
. wait ( )
. unwrap ( ) ;
assert! ( status . success ( ) ) ;
2020-04-16 18:15:42 -04:00
let mut file_path = bin_dir . join ( " echo_test " ) ;
2020-01-31 11:34:50 -05:00
if cfg! ( windows ) {
2020-03-04 03:40:56 -05:00
file_path = file_path . with_extension ( " cmd " ) ;
2020-01-31 11:34:50 -05:00
}
assert! ( file_path . exists ( ) ) ;
// NOTE: using file_path here instead of exec_name, because tests
// shouldn't mess with user's PATH env variable
let output = Command ::new ( file_path )
. current_dir ( temp_dir . path ( ) )
. arg ( " foo " )
2020-03-19 17:20:46 -04:00
. env ( " PATH " , util ::target_dir ( ) )
2020-01-31 11:34:50 -05:00
. output ( )
. expect ( " failed to spawn script " ) ;
2020-02-03 18:08:44 -05:00
let stdout_str = std ::str ::from_utf8 ( & output . stdout ) . unwrap ( ) . trim ( ) ;
2020-02-07 03:31:19 -05:00
assert! ( stdout_str . ends_with ( " hello, foo " ) ) ;
2020-01-31 11:34:50 -05:00
}
#[ test ]
fn installer_test_remote_module_run ( ) {
2020-08-10 17:31:05 -04:00
let _g = util ::http_server ( ) ;
2020-01-31 11:34:50 -05:00
let temp_dir = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
2020-04-16 18:15:42 -04:00
let bin_dir = temp_dir . path ( ) . join ( " bin " ) ;
std ::fs ::create_dir ( & bin_dir ) . unwrap ( ) ;
2020-05-11 17:33:36 -04:00
let status = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " install " )
. arg ( " --name " )
. arg ( " echo_test " )
. arg ( " --root " )
. arg ( temp_dir . path ( ) )
. arg ( " http://localhost:4545/cli/tests/echo.ts " )
. arg ( " hello " )
. spawn ( )
. unwrap ( )
. wait ( )
. unwrap ( ) ;
assert! ( status . success ( ) ) ;
2020-04-16 18:15:42 -04:00
let mut file_path = bin_dir . join ( " echo_test " ) ;
2020-01-31 11:34:50 -05:00
if cfg! ( windows ) {
2020-03-04 03:40:56 -05:00
file_path = file_path . with_extension ( " cmd " ) ;
2020-01-31 11:34:50 -05:00
}
assert! ( file_path . exists ( ) ) ;
let output = Command ::new ( file_path )
. current_dir ( temp_dir . path ( ) )
. arg ( " foo " )
2020-03-19 17:20:46 -04:00
. env ( " PATH " , util ::target_dir ( ) )
2020-01-31 11:34:50 -05:00
. output ( )
. expect ( " failed to spawn script " ) ;
2020-02-07 03:31:19 -05:00
assert! ( std ::str ::from_utf8 ( & output . stdout )
. unwrap ( )
. trim ( )
. ends_with ( " hello, foo " ) ) ;
2020-01-31 11:34:50 -05:00
}
2019-09-19 14:48:05 -04:00
#[ test ]
fn js_unit_tests ( ) {
2020-08-10 17:31:05 -04:00
let _g = util ::http_server ( ) ;
2019-10-29 17:52:57 -04:00
let mut deno = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
2019-09-19 14:48:05 -04:00
. arg ( " run " )
2020-04-30 11:23:40 -04:00
. arg ( " --unstable " )
2019-09-19 14:48:05 -04:00
. arg ( " --reload " )
2020-03-13 10:57:32 -04:00
. arg ( " -A " )
2020-05-20 17:52:51 -04:00
. arg ( " cli/tests/unit/unit_test_runner.ts " )
2020-03-14 06:53:20 -04:00
. arg ( " --master " )
2020-03-17 17:35:38 -04:00
. arg ( " --verbose " )
2020-05-19 14:19:26 -04:00
. env ( " NO_COLOR " , " 1 " )
2019-09-19 14:48:05 -04:00
. spawn ( )
. expect ( " failed to spawn script " ) ;
let status = deno . wait ( ) . expect ( " failed to wait for the child process " ) ;
assert_eq! ( Some ( 0 ) , status . code ( ) ) ;
assert! ( status . success ( ) ) ;
}
2020-05-29 10:32:15 -04:00
#[ test ]
fn ts_dependency_recompilation ( ) {
let t = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
let ats = t . path ( ) . join ( " a.ts " ) ;
std ::fs ::write (
& ats ,
"
import { foo } from \ " ./b.ts \" ;
function print ( str : string ) : void {
console . log ( str ) ;
}
2020-06-09 08:12:47 -04:00
2020-05-29 10:32:15 -04:00
print ( foo ) ; " ,
)
. unwrap ( ) ;
let bts = t . path ( ) . join ( " b.ts " ) ;
std ::fs ::write (
& bts ,
"
export const foo = \ " foo \" ; " ,
)
. unwrap ( ) ;
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. env ( " NO_COLOR " , " 1 " )
. arg ( " run " )
. arg ( & ats )
. output ( )
. expect ( " failed to spawn script " ) ;
let stdout_output = std ::str ::from_utf8 ( & output . stdout ) . unwrap ( ) . trim ( ) ;
let stderr_output = std ::str ::from_utf8 ( & output . stderr ) . unwrap ( ) . trim ( ) ;
assert! ( stdout_output . ends_with ( " foo " ) ) ;
2020-06-26 16:59:08 -04:00
assert! ( stderr_output . starts_with ( " Check " ) ) ;
2020-05-29 10:32:15 -04:00
// Overwrite contents of b.ts and run again
std ::fs ::write (
& bts ,
"
export const foo = 5 ; " ,
)
. expect ( " error writing file " ) ;
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. env ( " NO_COLOR " , " 1 " )
. arg ( " run " )
. arg ( & ats )
. output ( )
. expect ( " failed to spawn script " ) ;
let stdout_output = std ::str ::from_utf8 ( & output . stdout ) . unwrap ( ) . trim ( ) ;
let stderr_output = std ::str ::from_utf8 ( & output . stderr ) . unwrap ( ) . trim ( ) ;
// error: TS2345 [ERROR]: Argument of type '5' is not assignable to parameter of type 'string'.
assert! ( stderr_output . contains ( " TS2345 " ) ) ;
assert! ( ! output . status . success ( ) ) ;
assert! ( stdout_output . is_empty ( ) ) ;
}
2020-06-26 08:23:25 -04:00
#[ test ]
fn ts_reload ( ) {
let hello_ts = util ::root_path ( ) . join ( " cli/tests/002_hello.ts " ) ;
assert! ( hello_ts . is_file ( ) ) ;
let mut initial = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " cache " )
. arg ( " --reload " )
. arg ( hello_ts . clone ( ) )
. spawn ( )
. expect ( " failed to spawn script " ) ;
let status_initial =
initial . wait ( ) . expect ( " failed to wait for child process " ) ;
assert! ( status_initial . success ( ) ) ;
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " cache " )
. arg ( " --reload " )
. arg ( " -L " )
. arg ( " debug " )
. arg ( hello_ts )
. output ( )
. expect ( " failed to spawn script " ) ;
// check the output of the the bundle program.
assert! ( std ::str ::from_utf8 ( & output . stdout )
. unwrap ( )
. trim ( )
2020-07-23 09:29:36 -04:00
. contains ( " \" compiler::host.writeFile \" \" deno://002_hello.js \" " ) ) ;
2020-06-26 08:23:25 -04:00
}
2019-11-20 11:02:08 -05:00
#[ test ]
fn bundle_exports ( ) {
// First we have to generate a bundle of some module that has exports.
let mod1 = util ::root_path ( ) . join ( " cli/tests/subdir/mod1.ts " ) ;
assert! ( mod1 . is_file ( ) ) ;
let t = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
let bundle = t . path ( ) . join ( " mod1.bundle.js " ) ;
let mut deno = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " bundle " )
. arg ( mod1 )
. arg ( & bundle )
. spawn ( )
. expect ( " failed to spawn script " ) ;
let status = deno . wait ( ) . expect ( " failed to wait for the child process " ) ;
assert! ( status . success ( ) ) ;
assert! ( bundle . is_file ( ) ) ;
// Now we try to use that bundle from another module.
let test = t . path ( ) . join ( " test.js " ) ;
std ::fs ::write (
& test ,
"
import { printHello3 } from \ " ./mod1.bundle.js \" ;
printHello3 ( ) ; " ,
)
. expect ( " error writing file " ) ;
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( & test )
. output ( )
. expect ( " failed to spawn script " ) ;
// check the output of the test.ts program.
2020-02-07 03:31:19 -05:00
assert! ( std ::str ::from_utf8 ( & output . stdout )
. unwrap ( )
. trim ( )
. ends_with ( " Hello " ) ) ;
2019-11-20 11:02:08 -05:00
assert_eq! ( output . stderr , b " " ) ;
}
2020-02-12 16:41:51 -05:00
#[ test ]
fn bundle_circular ( ) {
// First we have to generate a bundle of some module that has exports.
let circular1 = util ::root_path ( ) . join ( " cli/tests/subdir/circular1.ts " ) ;
assert! ( circular1 . is_file ( ) ) ;
let t = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
let bundle = t . path ( ) . join ( " circular1.bundle.js " ) ;
let mut deno = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " bundle " )
. arg ( circular1 )
. arg ( & bundle )
. spawn ( )
. expect ( " failed to spawn script " ) ;
let status = deno . wait ( ) . expect ( " failed to wait for the child process " ) ;
assert! ( status . success ( ) ) ;
assert! ( bundle . is_file ( ) ) ;
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( & bundle )
. output ( )
. expect ( " failed to spawn script " ) ;
// check the output of the the bundle program.
assert! ( std ::str ::from_utf8 ( & output . stdout )
. unwrap ( )
. trim ( )
. ends_with ( " f1 \n f2 " ) ) ;
assert_eq! ( output . stderr , b " " ) ;
}
2020-02-19 22:35:21 -05:00
#[ test ]
fn bundle_single_module ( ) {
// First we have to generate a bundle of some module that has exports.
let single_module =
util ::root_path ( ) . join ( " cli/tests/subdir/single_module.ts " ) ;
assert! ( single_module . is_file ( ) ) ;
let t = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
let bundle = t . path ( ) . join ( " single_module.bundle.js " ) ;
let mut deno = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " bundle " )
. arg ( single_module )
. arg ( & bundle )
. spawn ( )
. expect ( " failed to spawn script " ) ;
let status = deno . wait ( ) . expect ( " failed to wait for the child process " ) ;
assert! ( status . success ( ) ) ;
assert! ( bundle . is_file ( ) ) ;
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( " --reload " )
. arg ( & bundle )
. output ( )
. expect ( " failed to spawn script " ) ;
// check the output of the the bundle program.
assert! ( std ::str ::from_utf8 ( & output . stdout )
. unwrap ( )
. trim ( )
. ends_with ( " Hello world! " ) ) ;
assert_eq! ( output . stderr , b " " ) ;
}
2020-02-25 15:33:19 -05:00
#[ test ]
fn bundle_tla ( ) {
// First we have to generate a bundle of some module that has exports.
let tla_import = util ::root_path ( ) . join ( " cli/tests/subdir/tla.ts " ) ;
assert! ( tla_import . is_file ( ) ) ;
let t = tempfile ::TempDir ::new ( ) . expect ( " tempdir fail " ) ;
let bundle = t . path ( ) . join ( " tla.bundle.js " ) ;
let mut deno = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " bundle " )
. arg ( tla_import )
. arg ( & bundle )
. spawn ( )
. expect ( " failed to spawn script " ) ;
let status = deno . wait ( ) . expect ( " failed to wait for the child process " ) ;
assert! ( status . success ( ) ) ;
assert! ( bundle . is_file ( ) ) ;
// Now we try to use that bundle from another module.
let test = t . path ( ) . join ( " test.js " ) ;
std ::fs ::write (
& test ,
"
import { foo } from \ " ./tla.bundle.js \" ;
console . log ( foo ) ; " ,
)
. expect ( " error writing file " ) ;
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( & test )
. output ( )
. expect ( " failed to spawn script " ) ;
// check the output of the test.ts program.
assert! ( std ::str ::from_utf8 ( & output . stdout )
. unwrap ( )
. trim ( )
. ends_with ( " Hello " ) ) ;
assert_eq! ( output . stderr , b " " ) ;
}
2020-03-02 16:18:27 -05:00
#[ test ]
fn bundle_js ( ) {
// First we have to generate a bundle of some module that has exports.
let mod6 = util ::root_path ( ) . join ( " cli/tests/subdir/mod6.js " ) ;
assert! ( mod6 . is_file ( ) ) ;
let t = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
let bundle = t . path ( ) . join ( " mod6.bundle.js " ) ;
let mut deno = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " bundle " )
. arg ( mod6 )
. arg ( & bundle )
. spawn ( )
. expect ( " failed to spawn script " ) ;
let status = deno . wait ( ) . expect ( " failed to wait for the child process " ) ;
assert! ( status . success ( ) ) ;
assert! ( bundle . is_file ( ) ) ;
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( & bundle )
. output ( )
. expect ( " failed to spawn script " ) ;
// check that nothing went to stderr
assert_eq! ( output . stderr , b " " ) ;
}
2020-04-01 23:14:30 -04:00
#[ test ]
fn bundle_dynamic_import ( ) {
let dynamic_import =
util ::root_path ( ) . join ( " cli/tests/subdir/subdir2/dynamic_import.ts " ) ;
assert! ( dynamic_import . is_file ( ) ) ;
let t = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
let bundle = t . path ( ) . join ( " dynamic_import.bundle.js " ) ;
let mut deno = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " bundle " )
. arg ( dynamic_import )
. arg ( & bundle )
. spawn ( )
. expect ( " failed to spawn script " ) ;
let status = deno . wait ( ) . expect ( " failed to wait for the child process " ) ;
assert! ( status . success ( ) ) ;
assert! ( bundle . is_file ( ) ) ;
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( & bundle )
. output ( )
. expect ( " failed to spawn script " ) ;
// check the output of the test.ts program.
assert! ( std ::str ::from_utf8 ( & output . stdout )
. unwrap ( )
. trim ( )
. ends_with ( " Hello " ) ) ;
assert_eq! ( output . stderr , b " " ) ;
}
2020-04-07 06:32:09 -04:00
#[ test ]
fn bundle_import_map ( ) {
let import = util ::root_path ( ) . join ( " cli/tests/bundle_im.ts " ) ;
let import_map_path = util ::root_path ( ) . join ( " cli/tests/bundle_im.json " ) ;
assert! ( import . is_file ( ) ) ;
let t = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
let bundle = t . path ( ) . join ( " import_map.bundle.js " ) ;
let mut deno = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " bundle " )
. arg ( " --importmap " )
. arg ( import_map_path )
2020-04-27 19:12:38 -04:00
. arg ( " --unstable " )
2020-04-07 06:32:09 -04:00
. arg ( import )
. arg ( & bundle )
. spawn ( )
. expect ( " failed to spawn script " ) ;
let status = deno . wait ( ) . expect ( " failed to wait for the child process " ) ;
assert! ( status . success ( ) ) ;
assert! ( bundle . is_file ( ) ) ;
// Now we try to use that bundle from another module.
let test = t . path ( ) . join ( " test.js " ) ;
std ::fs ::write (
& test ,
"
import { printHello3 } from \ " ./import_map.bundle.js \" ;
printHello3 ( ) ; " ,
)
. expect ( " error writing file " ) ;
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( & test )
. output ( )
. expect ( " failed to spawn script " ) ;
// check the output of the test.ts program.
assert! ( std ::str ::from_utf8 ( & output . stdout )
. unwrap ( )
. trim ( )
. ends_with ( " Hello " ) ) ;
assert_eq! ( output . stderr , b " " ) ;
}
2019-09-19 14:48:05 -04:00
#[ test ]
2020-02-24 17:49:40 -05:00
fn repl_test_console_log ( ) {
2020-03-07 05:27:16 -05:00
let ( out , err ) = util ::run_and_collect_output (
true ,
2020-02-25 15:36:35 -05:00
" repl " ,
Some ( vec! [ " console.log('hello') " , " 'world' " ] ) ,
2020-05-19 14:19:26 -04:00
Some ( vec! [ ( " NO_COLOR " . to_owned ( ) , " 1 " . to_owned ( ) ) ] ) ,
2020-03-01 19:51:54 -05:00
false ,
2020-02-25 15:36:35 -05:00
) ;
2020-05-08 18:58:51 -04:00
assert! ( out . ends_with ( " hello \n undefined \n world \n " ) ) ;
2020-02-24 17:49:40 -05:00
assert! ( err . is_empty ( ) ) ;
}
2020-06-02 16:37:52 -04:00
#[ test ]
fn repl_cwd ( ) {
let ( _out , err ) = util ::run_and_collect_output (
true ,
" repl " ,
Some ( vec! [ " Deno.cwd() " ] ) ,
Some ( vec! [ ( " NO_COLOR " . to_owned ( ) , " 1 " . to_owned ( ) ) ] ) ,
false ,
) ;
assert! ( err . is_empty ( ) ) ;
}
2020-02-24 17:49:40 -05:00
#[ test ]
fn repl_test_eof ( ) {
2020-03-07 05:27:16 -05:00
let ( out , err ) = util ::run_and_collect_output (
true ,
" repl " ,
Some ( vec! [ " 1 + 2 " ] ) ,
2020-05-19 14:19:26 -04:00
Some ( vec! [ ( " NO_COLOR " . to_owned ( ) , " 1 " . to_owned ( ) ) ] ) ,
2020-03-07 05:27:16 -05:00
false ,
) ;
2020-05-08 18:58:51 -04:00
assert! ( out . ends_with ( " 3 \n " ) ) ;
2020-02-24 17:49:40 -05:00
assert! ( err . is_empty ( ) ) ;
}
2020-05-29 06:24:06 -04:00
#[ test ]
fn repl_test_strict ( ) {
let ( _ , err ) = util ::run_and_collect_output (
true ,
" repl " ,
Some ( vec! [
" let a = {}; " ,
" Object.preventExtensions(a); " ,
" a.c = 1; " ,
] ) ,
None ,
false ,
) ;
assert! ( err . contains (
" Uncaught TypeError: Cannot add property c, object is not extensible "
) ) ;
}
2020-05-08 18:58:51 -04:00
const REPL_MSG : & str = " exit using ctrl+d or close() \n " ;
2020-02-24 17:49:40 -05:00
#[ test ]
2020-05-08 18:58:51 -04:00
fn repl_test_close_command ( ) {
2020-05-19 13:33:11 -04:00
let ( out , err ) = util ::run_and_collect_output (
2020-03-07 05:27:16 -05:00
true ,
2020-03-01 19:51:54 -05:00
" repl " ,
2020-05-08 18:58:51 -04:00
Some ( vec! [ " close() " , " 'ignored' " ] ) ,
2020-03-01 19:51:54 -05:00
None ,
false ,
) ;
2020-05-19 13:33:11 -04:00
assert! ( ! out . contains ( " ignored " ) ) ;
2020-02-24 17:49:40 -05:00
assert! ( err . is_empty ( ) ) ;
}
#[ test ]
fn repl_test_function ( ) {
2020-03-07 05:27:16 -05:00
let ( out , err ) = util ::run_and_collect_output (
true ,
2020-02-25 15:36:35 -05:00
" repl " ,
Some ( vec! [ " Deno.writeFileSync " ] ) ,
2020-05-19 14:19:26 -04:00
Some ( vec! [ ( " NO_COLOR " . to_owned ( ) , " 1 " . to_owned ( ) ) ] ) ,
2020-03-01 19:51:54 -05:00
false ,
2020-02-25 15:36:35 -05:00
) ;
2020-05-08 18:58:51 -04:00
assert! ( out . ends_with ( " [Function: writeFileSync] \n " ) ) ;
2020-02-24 17:49:40 -05:00
assert! ( err . is_empty ( ) ) ;
}
#[ test ]
fn repl_test_multiline ( ) {
2020-03-07 05:27:16 -05:00
let ( out , err ) = util ::run_and_collect_output (
true ,
2020-03-01 19:51:54 -05:00
" repl " ,
Some ( vec! [ " ( \n 1 + 2 \n ) " ] ) ,
2020-05-19 14:19:26 -04:00
Some ( vec! [ ( " NO_COLOR " . to_owned ( ) , " 1 " . to_owned ( ) ) ] ) ,
2020-03-01 19:51:54 -05:00
false ,
) ;
2020-05-08 18:58:51 -04:00
assert! ( out . ends_with ( " 3 \n " ) ) ;
2020-02-24 17:49:40 -05:00
assert! ( err . is_empty ( ) ) ;
}
#[ test ]
fn repl_test_eval_unterminated ( ) {
2020-03-07 05:27:16 -05:00
let ( out , err ) = util ::run_and_collect_output (
true ,
" repl " ,
Some ( vec! [ " eval('{') " ] ) ,
None ,
false ,
) ;
2020-05-08 18:58:51 -04:00
assert! ( out . ends_with ( REPL_MSG ) ) ;
2020-02-24 17:49:40 -05:00
assert! ( err . contains ( " Unexpected end of input " ) ) ;
}
#[ test ]
fn repl_test_reference_error ( ) {
2020-03-07 05:27:16 -05:00
let ( out , err ) = util ::run_and_collect_output (
true ,
2020-03-01 19:51:54 -05:00
" repl " ,
Some ( vec! [ " not_a_variable " ] ) ,
None ,
false ,
) ;
2020-05-08 18:58:51 -04:00
assert! ( out . ends_with ( REPL_MSG ) ) ;
2020-02-24 17:49:40 -05:00
assert! ( err . contains ( " not_a_variable is not defined " ) ) ;
}
#[ test ]
fn repl_test_syntax_error ( ) {
2020-03-07 05:27:16 -05:00
let ( out , err ) = util ::run_and_collect_output (
true ,
2020-03-01 19:51:54 -05:00
" repl " ,
Some ( vec! [ " syntax error " ] ) ,
None ,
false ,
) ;
2020-05-08 18:58:51 -04:00
assert! ( out . ends_with ( REPL_MSG ) ) ;
2020-02-24 17:49:40 -05:00
assert! ( err . contains ( " Unexpected identifier " ) ) ;
}
#[ test ]
fn repl_test_type_error ( ) {
2020-03-07 05:27:16 -05:00
let ( out , err ) = util ::run_and_collect_output (
true ,
" repl " ,
Some ( vec! [ " console() " ] ) ,
None ,
false ,
) ;
2020-05-08 18:58:51 -04:00
assert! ( out . ends_with ( REPL_MSG ) ) ;
2020-02-24 17:49:40 -05:00
assert! ( err . contains ( " console is not a function " ) ) ;
}
#[ test ]
fn repl_test_variable ( ) {
2020-03-07 05:27:16 -05:00
let ( out , err ) = util ::run_and_collect_output (
true ,
2020-03-01 19:51:54 -05:00
" repl " ,
Some ( vec! [ " var a = 123; " , " a " ] ) ,
2020-05-19 14:19:26 -04:00
Some ( vec! [ ( " NO_COLOR " . to_owned ( ) , " 1 " . to_owned ( ) ) ] ) ,
2020-03-01 19:51:54 -05:00
false ,
) ;
2020-05-08 18:58:51 -04:00
assert! ( out . ends_with ( " undefined \n 123 \n " ) ) ;
2020-02-24 17:49:40 -05:00
assert! ( err . is_empty ( ) ) ;
}
#[ test ]
fn repl_test_lexical_scoped_variable ( ) {
2020-03-07 05:27:16 -05:00
let ( out , err ) = util ::run_and_collect_output (
true ,
2020-03-01 19:51:54 -05:00
" repl " ,
Some ( vec! [ " let a = 123; " , " a " ] ) ,
2020-05-19 14:19:26 -04:00
Some ( vec! [ ( " NO_COLOR " . to_owned ( ) , " 1 " . to_owned ( ) ) ] ) ,
2020-03-01 19:51:54 -05:00
false ,
) ;
2020-05-08 18:58:51 -04:00
assert! ( out . ends_with ( " undefined \n 123 \n " ) ) ;
2020-02-24 17:49:40 -05:00
assert! ( err . is_empty ( ) ) ;
}
#[ test ]
fn repl_test_missing_deno_dir ( ) {
use std ::fs ::{ read_dir , remove_dir_all } ;
const DENO_DIR : & str = " nonexistent " ;
2020-02-25 15:36:35 -05:00
let test_deno_dir =
util ::root_path ( ) . join ( " cli " ) . join ( " tests " ) . join ( DENO_DIR ) ;
2020-03-07 05:27:16 -05:00
let ( out , err ) = util ::run_and_collect_output (
true ,
2020-02-25 15:36:35 -05:00
" repl " ,
Some ( vec! [ " 1 " ] ) ,
2020-05-19 14:19:26 -04:00
Some ( vec! [
( " DENO_DIR " . to_owned ( ) , DENO_DIR . to_owned ( ) ) ,
( " NO_COLOR " . to_owned ( ) , " 1 " . to_owned ( ) ) ,
] ) ,
2020-03-01 19:51:54 -05:00
false ,
2020-02-24 17:49:40 -05:00
) ;
2020-02-25 15:36:35 -05:00
assert! ( read_dir ( & test_deno_dir ) . is_ok ( ) ) ;
remove_dir_all ( & test_deno_dir ) . unwrap ( ) ;
2020-05-08 18:58:51 -04:00
assert! ( out . ends_with ( " 1 \n " ) ) ;
2020-02-24 17:49:40 -05:00
assert! ( err . is_empty ( ) ) ;
}
#[ test ]
fn repl_test_save_last_eval ( ) {
2020-03-07 05:27:16 -05:00
let ( out , err ) = util ::run_and_collect_output (
true ,
" repl " ,
Some ( vec! [ " 1 " , " _ " ] ) ,
2020-05-19 14:19:26 -04:00
Some ( vec! [ ( " NO_COLOR " . to_owned ( ) , " 1 " . to_owned ( ) ) ] ) ,
2020-03-07 05:27:16 -05:00
false ,
) ;
2020-05-08 18:58:51 -04:00
assert! ( out . ends_with ( " 1 \n 1 \n " ) ) ;
2020-02-24 17:49:40 -05:00
assert! ( err . is_empty ( ) ) ;
}
#[ test ]
fn repl_test_save_last_thrown ( ) {
2020-03-07 05:27:16 -05:00
let ( out , err ) = util ::run_and_collect_output (
true ,
2020-03-01 19:51:54 -05:00
" repl " ,
Some ( vec! [ " throw 1 " , " _error " ] ) ,
2020-05-19 14:19:26 -04:00
Some ( vec! [ ( " NO_COLOR " . to_owned ( ) , " 1 " . to_owned ( ) ) ] ) ,
2020-03-01 19:51:54 -05:00
false ,
) ;
2020-05-08 18:58:51 -04:00
assert! ( out . ends_with ( " 1 \n " ) ) ;
2020-02-24 17:49:40 -05:00
assert_eq! ( err , " Thrown: 1 \n " ) ;
}
#[ test ]
fn repl_test_assign_underscore ( ) {
2020-03-07 05:27:16 -05:00
let ( out , err ) = util ::run_and_collect_output (
true ,
2020-03-01 19:51:54 -05:00
" repl " ,
Some ( vec! [ " _ = 1 " , " 2 " , " _ " ] ) ,
2020-05-19 14:19:26 -04:00
Some ( vec! [ ( " NO_COLOR " . to_owned ( ) , " 1 " . to_owned ( ) ) ] ) ,
2020-03-01 19:51:54 -05:00
false ,
) ;
2020-05-08 18:58:51 -04:00
assert! (
out . ends_with ( " Last evaluation result is no longer saved to _. \n 1 \n 2 \n 1 \n " )
2020-02-24 17:49:40 -05:00
) ;
assert! ( err . is_empty ( ) ) ;
}
#[ test ]
fn repl_test_assign_underscore_error ( ) {
2020-03-07 05:27:16 -05:00
let ( out , err ) = util ::run_and_collect_output (
true ,
2020-02-25 15:36:35 -05:00
" repl " ,
Some ( vec! [ " _error = 1 " , " throw 2 " , " _error " ] ) ,
2020-05-19 14:19:26 -04:00
Some ( vec! [ ( " NO_COLOR " . to_owned ( ) , " 1 " . to_owned ( ) ) ] ) ,
2020-03-01 19:51:54 -05:00
false ,
2020-02-25 15:36:35 -05:00
) ;
2020-05-08 18:58:51 -04:00
assert! (
out . ends_with ( " Last thrown error is no longer saved to _error. \n 1 \n 1 \n " )
2020-02-24 17:49:40 -05:00
) ;
assert_eq! ( err , " Thrown: 2 \n " ) ;
2019-09-19 14:48:05 -04:00
}
2020-06-19 06:10:31 -04:00
#[ test ]
fn deno_test_no_color ( ) {
let ( out , _ ) = util ::run_and_collect_output (
false ,
" test deno_test_no_color.ts " ,
None ,
Some ( vec! [ ( " NO_COLOR " . to_owned ( ) , " true " . to_owned ( ) ) ] ) ,
false ,
) ;
// ANSI escape codes should be stripped.
assert! ( out . contains ( " test success ... ok " ) ) ;
assert! ( out . contains ( " test fail ... FAILED " ) ) ;
assert! ( out . contains ( " test ignored ... ignored " ) ) ;
assert! ( out . contains ( " test result: FAILED. 1 passed; 1 failed; 1 ignored; 0 measured; 0 filtered out " ) ) ;
}
2019-09-19 14:48:05 -04:00
#[ test ]
fn util_test ( ) {
2019-10-29 17:52:57 -04:00
util ::run_python_script ( " tools/util_test.py " )
2019-09-19 14:48:05 -04:00
}
2019-09-10 11:09:54 -04:00
macro_rules ! itest (
( $name :ident { $( $key :ident : $value :expr , ) * } ) = > {
#[ test ]
fn $name ( ) {
2019-10-29 17:52:57 -04:00
( util ::CheckOutputIntegrationTest {
2019-09-10 11:09:54 -04:00
$(
$key : $value ,
) *
.. Default ::default ( )
} ) . run ( )
}
}
) ;
2020-03-03 16:02:35 -05:00
// Unfortunately #[ignore] doesn't work with itest!
2020-07-11 12:29:55 -04:00
#[ allow(unused) ]
2020-03-03 16:02:35 -05:00
macro_rules ! itest_ignore (
( $name :ident { $( $key :ident : $value :expr , ) * } ) = > {
#[ ignore ]
#[ test ]
fn $name ( ) {
( util ::CheckOutputIntegrationTest {
$(
$key : $value ,
) *
.. Default ::default ( )
} ) . run ( )
}
}
) ;
2019-09-10 11:09:54 -04:00
itest! ( _001_hello {
args : " run --reload 001_hello.js " ,
2019-09-19 14:48:05 -04:00
output : " 001_hello.js.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _002_hello {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload 002_hello.ts " ,
2019-09-19 14:48:05 -04:00
output : " 002_hello.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _003_relative_import {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload 003_relative_import.ts " ,
2019-09-19 14:48:05 -04:00
output : " 003_relative_import.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _004_set_timeout {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload 004_set_timeout.ts " ,
2019-09-19 14:48:05 -04:00
output : " 004_set_timeout.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _005_more_imports {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload 005_more_imports.ts " ,
2019-09-19 14:48:05 -04:00
output : " 005_more_imports.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _006_url_imports {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload 006_url_imports.ts " ,
2019-09-19 14:48:05 -04:00
output : " 006_url_imports.ts.out " ,
http_server : true ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _012_async {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload 012_async.ts " ,
2019-09-19 14:48:05 -04:00
output : " 012_async.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _013_dynamic_import {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload --allow-read 013_dynamic_import.ts " ,
2019-09-19 14:48:05 -04:00
output : " 013_dynamic_import.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _014_duplicate_import {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload --allow-read 014_duplicate_import.ts " ,
2019-09-19 14:48:05 -04:00
output : " 014_duplicate_import.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _015_duplicate_parallel_import {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload --allow-read 015_duplicate_parallel_import.js " ,
2019-09-19 14:48:05 -04:00
output : " 015_duplicate_parallel_import.js.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _016_double_await {
2020-05-17 11:42:39 -04:00
args : " run --quiet --allow-read --reload 016_double_await.ts " ,
2019-09-19 14:48:05 -04:00
output : " 016_double_await.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _017_import_redirect {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload 017_import_redirect.ts " ,
2019-09-19 14:48:05 -04:00
output : " 017_import_redirect.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _018_async_catch {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload 018_async_catch.ts " ,
2019-09-19 14:48:05 -04:00
output : " 018_async_catch.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2020-07-05 23:09:50 -04:00
itest! ( _019_media_types {
2019-09-10 11:09:54 -04:00
args : " run --reload 019_media_types.ts " ,
2019-09-19 14:48:05 -04:00
output : " 019_media_types.ts.out " ,
http_server : true ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _020_json_modules {
args : " run --reload 020_json_modules.ts " ,
2019-09-19 14:48:05 -04:00
output : " 020_json_modules.ts.out " ,
2020-05-01 18:32:05 -04:00
exit_code : 1 ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _021_mjs_modules {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload 021_mjs_modules.ts " ,
2019-09-19 14:48:05 -04:00
output : " 021_mjs_modules.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2020-07-05 23:09:50 -04:00
itest! ( _022_info_flag_script {
2019-09-19 14:48:05 -04:00
args : " info http://127.0.0.1:4545/cli/tests/019_media_types.ts " ,
output : " 022_info_flag_script.out " ,
http_server : true ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _023_no_ext_with_headers {
args : " run --reload 023_no_ext_with_headers " ,
2019-09-19 14:48:05 -04:00
output : " 023_no_ext_with_headers.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2020-04-30 11:23:40 -04:00
// TODO(lucacasonato): remove --unstable when permissions goes stable
2019-09-10 11:09:54 -04:00
itest! ( _025_hrtime {
2020-05-17 11:42:39 -04:00
args : " run --quiet --allow-hrtime --unstable --reload 025_hrtime.ts " ,
2019-09-19 14:48:05 -04:00
output : " 025_hrtime.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _025_reload_js_type_error {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload 025_reload_js_type_error.js " ,
2019-09-19 14:48:05 -04:00
output : " 025_reload_js_type_error.js.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _026_redirect_javascript {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload 026_redirect_javascript.js " ,
2019-09-19 14:48:05 -04:00
output : " 026_redirect_javascript.js.out " ,
http_server : true ,
2019-09-10 11:09:54 -04:00
} ) ;
2020-06-12 11:58:04 -04:00
itest! ( deno_test {
args : " test test_runner_test.ts " ,
exit_code : 1 ,
output : " deno_test.out " ,
} ) ;
2020-03-19 09:26:47 -04:00
itest! ( deno_test_fail_fast {
args : " test --failfast test_runner_test.ts " ,
exit_code : 1 ,
output : " deno_test_fail_fast.out " ,
} ) ;
2020-06-12 11:58:04 -04:00
itest! ( deno_test_only {
args : " test deno_test_only.ts " ,
2020-03-19 09:26:47 -04:00
exit_code : 1 ,
2020-06-12 11:58:04 -04:00
output : " deno_test_only.ts.out " ,
2020-03-19 09:26:47 -04:00
} ) ;
2020-05-04 10:40:18 -04:00
#[ test ]
fn workers ( ) {
2020-08-10 17:31:05 -04:00
let _g = util ::http_server ( ) ;
2020-05-04 10:40:18 -04:00
let status = util ::deno_cmd ( )
. current_dir ( util ::tests_path ( ) )
. arg ( " test " )
. arg ( " --reload " )
. arg ( " --allow-net " )
2020-05-11 07:13:27 -04:00
. arg ( " --allow-read " )
2020-05-07 15:15:59 -04:00
. arg ( " --unstable " )
2020-05-04 10:40:18 -04:00
. arg ( " workers_test.ts " )
. spawn ( )
. unwrap ( )
. wait ( )
. unwrap ( ) ;
assert! ( status . success ( ) ) ;
}
2020-02-05 17:16:07 -05:00
2020-05-04 10:40:18 -04:00
#[ test ]
fn compiler_api ( ) {
let status = util ::deno_cmd ( )
. current_dir ( util ::tests_path ( ) )
. arg ( " test " )
. arg ( " --unstable " )
. arg ( " --reload " )
2020-05-11 07:13:27 -04:00
. arg ( " --allow-read " )
2020-05-04 10:40:18 -04:00
. arg ( " compiler_api_test.ts " )
. spawn ( )
. unwrap ( )
. wait ( )
. unwrap ( ) ;
assert! ( status . success ( ) ) ;
}
2020-03-11 16:54:53 -04:00
2019-09-10 11:09:54 -04:00
itest! ( _027_redirect_typescript {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload 027_redirect_typescript.ts " ,
2019-09-19 14:48:05 -04:00
output : " 027_redirect_typescript.ts.out " ,
http_server : true ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _028_args {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload 028_args.ts --arg1 val1 --arg2=val2 -- arg3 arg4 " ,
2019-09-19 14:48:05 -04:00
output : " 028_args.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _029_eval {
args : " eval console.log( \" hello \" ) " ,
2019-09-19 14:48:05 -04:00
output : " 029_eval.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2020-02-28 09:17:56 -05:00
// Ugly parentheses due to whitespace delimiting problem.
itest! ( _030_eval_ts {
2020-05-17 11:42:39 -04:00
args : " eval --quiet -T console.log((123)as(number)) " , // 'as' is a TS keyword only
2020-02-28 09:17:56 -05:00
output : " 030_eval_ts.out " ,
} ) ;
2020-08-07 16:46:54 -04:00
itest! ( _031_info_no_check {
2020-08-26 14:27:06 -04:00
args : " info --no-check 031_info_no_check.ts " ,
2020-08-07 16:46:54 -04:00
output : " 031_info_no_check.out " ,
} ) ;
2019-09-10 11:09:54 -04:00
itest! ( _033_import_map {
args :
2020-05-17 11:42:39 -04:00
" run --quiet --reload --importmap=importmaps/import_map.json --unstable importmaps/test.ts " ,
2019-09-19 14:48:05 -04:00
output : " 033_import_map.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2020-04-27 19:12:38 -04:00
itest! ( import_map_no_unstable {
args :
2020-05-17 11:42:39 -04:00
" run --quiet --reload --importmap=importmaps/import_map.json importmaps/test.ts " ,
2020-04-27 19:12:38 -04:00
output : " import_map_no_unstable.out " ,
exit_code : 70 ,
} ) ;
2019-09-10 11:09:54 -04:00
itest! ( _034_onload {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload 034_onload/main.ts " ,
2019-09-19 14:48:05 -04:00
output : " 034_onload.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2020-07-05 23:09:50 -04:00
itest! ( _035_cached_only_flag {
2019-09-19 14:48:05 -04:00
args :
2020-07-05 23:09:50 -04:00
" run --reload --cached-only http://127.0.0.1:4545/cli/tests/019_media_types.ts " ,
2019-12-03 17:48:53 -05:00
output : " 035_cached_only_flag.out " ,
2019-09-10 11:09:54 -04:00
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
http_server : true ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _036_import_map_fetch {
args :
2020-05-17 11:42:39 -04:00
" cache --quiet --reload --importmap=importmaps/import_map.json --unstable importmaps/test.ts " ,
2019-09-19 14:48:05 -04:00
output : " 036_import_map_fetch.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2020-01-31 16:07:37 -05:00
itest! ( _037_fetch_multiple {
2020-04-07 11:24:47 -04:00
args : " cache --reload fetch/test.ts fetch/other.ts " ,
2020-01-31 16:07:37 -05:00
http_server : true ,
output : " 037_fetch_multiple.out " ,
} ) ;
2019-09-10 11:09:54 -04:00
itest! ( _038_checkjs {
// checking if JS file is run through TS compiler
args : " run --reload --config 038_checkjs.tsconfig.json 038_checkjs.js " ,
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
output : " 038_checkjs.js.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _041_dyn_import_eval {
args : " eval import('./subdir/mod4.js').then(console.log) " ,
2019-09-19 14:48:05 -04:00
output : " 041_dyn_import_eval.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( _041_info_flag {
args : " info " ,
2019-09-19 14:48:05 -04:00
output : " 041_info_flag.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2020-07-08 10:50:12 -04:00
itest! ( info_json {
args : " info --json --unstable " ,
output : " info_json.out " ,
} ) ;
2019-09-10 11:09:54 -04:00
itest! ( _042_dyn_import_evalcontext {
2020-05-17 11:42:39 -04:00
args : " run --quiet --allow-read --reload 042_dyn_import_evalcontext.ts " ,
2019-09-19 14:48:05 -04:00
output : " 042_dyn_import_evalcontext.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2019-09-24 10:46:57 -04:00
itest! ( _044_bad_resource {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload --allow-read 044_bad_resource.ts " ,
2019-09-24 10:46:57 -04:00
output : " 044_bad_resource.ts.out " ,
exit_code : 1 ,
} ) ;
2020-07-11 12:29:55 -04:00
itest! ( _045_proxy {
args : " run --allow-net --allow-env --allow-run --allow-read --reload --quiet 045_proxy_test.ts " ,
2019-09-24 18:52:01 -04:00
output : " 045_proxy_test.ts.out " ,
2019-10-22 09:52:41 -04:00
http_server : true ,
2019-09-24 18:52:01 -04:00
} ) ;
2019-10-02 10:46:36 -04:00
itest! ( _046_tsx {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload 046_jsx_test.tsx " ,
2019-10-02 10:46:36 -04:00
output : " 046_jsx_test.tsx.out " ,
} ) ;
itest! ( _047_jsx {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload 047_jsx_test.jsx " ,
2019-10-02 10:46:36 -04:00
output : " 047_jsx_test.jsx.out " ,
} ) ;
2020-07-05 23:09:50 -04:00
itest! ( _048_media_types_jsx {
2019-10-16 13:35:04 -04:00
args : " run --reload 048_media_types_jsx.ts " ,
output : " 048_media_types_jsx.ts.out " ,
http_server : true ,
} ) ;
2020-08-26 14:27:06 -04:00
itest! ( _049_info_flag_script_jsx {
2019-10-16 13:35:04 -04:00
args : " info http://127.0.0.1:4545/cli/tests/048_media_types_jsx.ts " ,
output : " 049_info_flag_script_jsx.out " ,
http_server : true ,
} ) ;
2020-07-05 23:09:50 -04:00
itest! ( _052_no_remote_flag {
2019-12-03 17:48:53 -05:00
args :
2020-07-05 23:09:50 -04:00
" run --reload --no-remote http://127.0.0.1:4545/cli/tests/019_media_types.ts " ,
2019-12-03 17:48:53 -05:00
output : " 052_no_remote_flag.out " ,
exit_code : 1 ,
http_server : true ,
} ) ;
2020-01-25 12:53:16 -05:00
itest! ( _054_info_local_imports {
2020-05-17 11:42:39 -04:00
args : " info --quiet 005_more_imports.ts " ,
2020-01-25 12:53:16 -05:00
output : " 054_info_local_imports.out " ,
exit_code : 0 ,
} ) ;
2020-07-08 10:50:12 -04:00
itest! ( _055_info_file_json {
args : " info --quiet --json --unstable 005_more_imports.ts " ,
output : " 055_info_file_json.out " ,
exit_code : 0 ,
} ) ;
2020-02-25 09:23:23 -05:00
itest! ( _056_make_temp_file_write_perm {
2020-04-30 11:23:40 -04:00
args :
2020-05-17 11:42:39 -04:00
" run --quiet --allow-read --allow-write=./subdir/ 056_make_temp_file_write_perm.ts " ,
2020-02-25 09:23:23 -05:00
output : " 056_make_temp_file_write_perm.out " ,
} ) ;
2020-03-24 23:56:40 -04:00
itest! ( _058_tasks_microtasks_close {
2020-05-17 11:42:39 -04:00
args : " run --quiet 058_tasks_microtasks_close.ts " ,
2020-03-24 23:56:40 -04:00
output : " 058_tasks_microtasks_close.ts.out " ,
} ) ;
2020-05-29 11:27:43 -04:00
itest! ( _059_fs_relative_path_perm {
args : " run 059_fs_relative_path_perm.ts " ,
output : " 059_fs_relative_path_perm.ts.out " ,
exit_code : 1 ,
} ) ;
2020-06-09 08:12:47 -04:00
itest! ( _060_deno_doc_displays_all_overloads_in_details_view {
args : " doc 060_deno_doc_displays_all_overloads_in_details_view.ts NS.test " ,
output : " 060_deno_doc_displays_all_overloads_in_details_view.ts.out " ,
} ) ;
2020-08-18 16:29:32 -04:00
#[ cfg(unix) ]
#[ test ]
fn _061_permissions_request ( ) {
let args = " run --unstable 061_permissions_request.ts " ;
let output = " 061_permissions_request.ts.out " ;
let input = b " g \n d \n " ;
util ::test_pty ( args , output , input ) ;
}
#[ cfg(unix) ]
#[ test ]
fn _062_permissions_request_global ( ) {
let args = " run --unstable 062_permissions_request_global.ts " ;
let output = " 062_permissions_request_global.ts.out " ;
let input = b " g \n " ;
util ::test_pty ( args , output , input ) ;
}
itest! ( _063_permissions_revoke {
args : " run --unstable --allow-read=foo,bar 063_permissions_revoke.ts " ,
output : " 063_permissions_revoke.ts.out " ,
} ) ;
itest! ( _064_permissions_revoke_global {
args : " run --unstable --allow-read=foo,bar 064_permissions_revoke_global.ts " ,
output : " 064_permissions_revoke_global.ts.out " ,
} ) ;
2020-02-16 05:11:44 -05:00
itest! ( js_import_detect {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload js_import_detect.ts " ,
2020-02-16 05:11:44 -05:00
output : " js_import_detect.ts.out " ,
exit_code : 0 ,
} ) ;
2020-07-02 11:54:51 -04:00
itest! ( lock_write_requires_lock {
args : " run --lock-write some_file.ts " ,
output : " lock_write_requires_lock.out " ,
exit_code : 1 ,
} ) ;
2020-01-26 13:43:59 -05:00
itest! ( lock_write_fetch {
args :
2020-05-17 11:42:39 -04:00
" run --quiet --allow-read --allow-write --allow-env --allow-run lock_write_fetch.ts " ,
2020-01-26 13:43:59 -05:00
output : " lock_write_fetch.ts.out " ,
exit_code : 0 ,
} ) ;
2019-11-03 10:39:27 -05:00
itest! ( lock_check_ok {
args : " run --lock=lock_check_ok.json http://127.0.0.1:4545/cli/tests/003_relative_import.ts " ,
output : " 003_relative_import.ts.out " ,
http_server : true ,
} ) ;
2020-07-05 23:09:50 -04:00
itest! ( lock_check_ok2 {
args : " run --lock=lock_check_ok2.json 019_media_types.ts " ,
2019-11-03 10:39:27 -05:00
output : " 019_media_types.ts.out " ,
http_server : true ,
} ) ;
2020-07-02 11:54:51 -04:00
itest! ( lock_dynamic_imports {
args : " run --lock=lock_dynamic_imports.json --allow-read --allow-net http://127.0.0.1:4545/cli/tests/013_dynamic_import.ts " ,
output : " lock_dynamic_imports.out " ,
exit_code : 10 ,
http_server : true ,
} ) ;
2019-11-03 10:39:27 -05:00
itest! ( lock_check_err {
args : " run --lock=lock_check_err.json http://127.0.0.1:4545/cli/tests/003_relative_import.ts " ,
output : " lock_check_err.out " ,
exit_code : 10 ,
http_server : true ,
} ) ;
2020-07-05 23:09:50 -04:00
itest! ( lock_check_err2 {
2019-11-26 11:06:32 -05:00
args : " run --lock=lock_check_err2.json 019_media_types.ts " ,
2019-11-03 10:39:27 -05:00
output : " lock_check_err2.out " ,
exit_code : 10 ,
http_server : true ,
} ) ;
2020-07-07 07:05:28 -04:00
itest! ( lock_check_err_with_bundle {
args : " bundle --lock=lock_check_err_with_bundle.json http://127.0.0.1:4545/cli/tests/subdir/mod1.ts " ,
output : " lock_check_err_with_bundle.out " ,
exit_code : 10 ,
http_server : true ,
} ) ;
2019-09-10 11:09:54 -04:00
itest! ( async_error {
exit_code : 1 ,
args : " run --reload async_error.ts " ,
2019-09-19 14:48:05 -04:00
output : " async_error.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2019-11-13 10:35:56 -05:00
itest! ( bundle {
args : " bundle subdir/mod1.ts " ,
output : " bundle.test.out " ,
} ) ;
2020-06-17 15:50:30 -04:00
itest! ( fmt_check_tests_dir {
args : " fmt --check ./ " ,
output : " fmt_check_tests_dir.out " ,
exit_code : 1 ,
} ) ;
2020-02-09 05:19:05 -05:00
itest! ( fmt_stdin {
args : " fmt - " ,
input : Some ( " const a = 1 \n " ) ,
output_str : Some ( " const a = 1; \n " ) ,
} ) ;
itest! ( fmt_stdin_check_formatted {
args : " fmt --check - " ,
input : Some ( " const a = 1; \n " ) ,
output_str : Some ( " " ) ,
} ) ;
itest! ( fmt_stdin_check_not_formatted {
args : " fmt --check - " ,
input : Some ( " const a = 1 \n " ) ,
output_str : Some ( " Not formatted stdin \n " ) ,
} ) ;
2019-09-10 11:09:54 -04:00
itest! ( circular1 {
args : " run --reload circular1.js " ,
2019-09-19 14:48:05 -04:00
output : " circular1.js.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( config {
args : " run --reload --config config.tsconfig.json config.ts " ,
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
output : " config.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( error_001 {
args : " run --reload error_001.ts " ,
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
output : " error_001.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( error_002 {
args : " run --reload error_002.ts " ,
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
output : " error_002.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( error_003_typescript {
args : " run --reload error_003_typescript.ts " ,
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
output : " error_003_typescript.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
// Supposing that we've already attempted to run error_003_typescript.ts
// we want to make sure that JS wasn't emitted. Running again without reload flag
// should result in the same output.
// https://github.com/denoland/deno/issues/2436
itest! ( error_003_typescript2 {
args : " run error_003_typescript.ts " ,
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
output : " error_003_typescript.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( error_004_missing_module {
args : " run --reload error_004_missing_module.ts " ,
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
output : " error_004_missing_module.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( error_005_missing_dynamic_import {
2020-05-29 10:32:15 -04:00
args : " run --reload --allow-read --quiet error_005_missing_dynamic_import.ts " ,
2019-09-10 11:09:54 -04:00
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
output : " error_005_missing_dynamic_import.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( error_006_import_ext_failure {
args : " run --reload error_006_import_ext_failure.ts " ,
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
output : " error_006_import_ext_failure.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( error_007_any {
args : " run --reload error_007_any.ts " ,
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
output : " error_007_any.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( error_008_checkjs {
args : " run --reload error_008_checkjs.js " ,
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
output : " error_008_checkjs.js.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( error_011_bad_module_specifier {
args : " run --reload error_011_bad_module_specifier.ts " ,
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
output : " error_011_bad_module_specifier.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( error_012_bad_dynamic_import_specifier {
args : " run --reload error_012_bad_dynamic_import_specifier.ts " ,
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
output : " error_012_bad_dynamic_import_specifier.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( error_013_missing_script {
args : " run --reload missing_file_name " ,
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
output : " error_013_missing_script.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( error_014_catch_dynamic_import_error {
2019-11-26 11:06:32 -05:00
args : " run --reload --allow-read error_014_catch_dynamic_import_error.js " ,
2019-09-19 14:48:05 -04:00
output : " error_014_catch_dynamic_import_error.js.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( error_015_dynamic_import_permissions {
2020-05-29 10:32:15 -04:00
args : " run --reload --quiet error_015_dynamic_import_permissions.js " ,
2019-09-19 14:48:05 -04:00
output : " error_015_dynamic_import_permissions.out " ,
2019-09-10 11:09:54 -04:00
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
http_server : true ,
2019-09-10 11:09:54 -04:00
} ) ;
// We have an allow-net flag but not allow-read, it should still result in error.
itest! ( error_016_dynamic_import_permissions2 {
2020-05-04 07:03:30 -04:00
args : " run --reload --allow-net error_016_dynamic_import_permissions2.js " ,
2019-09-19 14:48:05 -04:00
output : " error_016_dynamic_import_permissions2.out " ,
2019-09-10 11:09:54 -04:00
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
http_server : true ,
2019-09-10 11:09:54 -04:00
} ) ;
2020-03-24 23:53:48 -04:00
itest! ( error_017_hide_long_source_ts {
2020-05-04 07:03:30 -04:00
args : " run --reload error_017_hide_long_source_ts.ts " ,
2020-03-24 23:53:48 -04:00
output : " error_017_hide_long_source_ts.ts.out " ,
exit_code : 1 ,
} ) ;
itest! ( error_018_hide_long_source_js {
2020-05-04 07:03:30 -04:00
args : " run error_018_hide_long_source_js.js " ,
2020-03-24 23:53:48 -04:00
output : " error_018_hide_long_source_js.js.out " ,
exit_code : 1 ,
} ) ;
2020-04-11 02:08:11 -04:00
itest! ( error_019_stack_function {
2020-05-04 07:03:30 -04:00
args : " run error_019_stack_function.ts " ,
2020-04-11 02:08:11 -04:00
output : " error_019_stack_function.ts.out " ,
exit_code : 1 ,
} ) ;
itest! ( error_020_stack_constructor {
2020-05-04 07:03:30 -04:00
args : " run error_020_stack_constructor.ts " ,
2020-04-11 02:08:11 -04:00
output : " error_020_stack_constructor.ts.out " ,
exit_code : 1 ,
} ) ;
itest! ( error_021_stack_method {
2020-05-04 07:03:30 -04:00
args : " run error_021_stack_method.ts " ,
2020-04-11 02:08:11 -04:00
output : " error_021_stack_method.ts.out " ,
exit_code : 1 ,
} ) ;
itest! ( error_022_stack_custom_error {
2020-05-04 07:03:30 -04:00
args : " run error_022_stack_custom_error.ts " ,
2020-04-11 02:08:11 -04:00
output : " error_022_stack_custom_error.ts.out " ,
exit_code : 1 ,
} ) ;
itest! ( error_023_stack_async {
2020-05-04 07:03:30 -04:00
args : " run error_023_stack_async.ts " ,
2020-04-11 02:08:11 -04:00
output : " error_023_stack_async.ts.out " ,
2019-09-10 11:09:54 -04:00
exit_code : 1 ,
} ) ;
2020-04-13 10:54:16 -04:00
itest! ( error_024_stack_promise_all {
2020-05-04 07:03:30 -04:00
args : " run error_024_stack_promise_all.ts " ,
2020-04-13 10:54:16 -04:00
output : " error_024_stack_promise_all.ts.out " ,
exit_code : 1 ,
} ) ;
2020-05-01 13:03:54 -04:00
itest! ( error_025_tab_indent {
2020-05-04 07:03:30 -04:00
args : " run error_025_tab_indent " ,
2020-05-01 13:03:54 -04:00
output : " error_025_tab_indent.out " ,
exit_code : 1 ,
} ) ;
2020-07-08 05:26:39 -04:00
itest! ( error_no_check {
args : " run --reload --no-check error_no_check.ts " ,
output : " error_no_check.ts.out " ,
exit_code : 1 ,
} ) ;
2019-09-10 11:09:54 -04:00
itest! ( error_syntax {
args : " run --reload error_syntax.js " ,
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
output : " error_syntax.js.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2020-03-24 23:55:54 -04:00
itest! ( error_syntax_empty_trailing_line {
args : " run --reload error_syntax_empty_trailing_line.mjs " ,
exit_code : 1 ,
output : " error_syntax_empty_trailing_line.mjs.out " ,
} ) ;
2019-09-10 11:09:54 -04:00
itest! ( error_type_definitions {
args : " run --reload error_type_definitions.ts " ,
exit_code : 1 ,
2019-09-19 14:48:05 -04:00
output : " error_type_definitions.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2020-05-02 09:51:08 -04:00
itest! ( error_local_static_import_from_remote_ts {
args : " run --reload http://localhost:4545/cli/tests/error_local_static_import_from_remote.ts " ,
exit_code : 1 ,
http_server : true ,
output : " error_local_static_import_from_remote.ts.out " ,
} ) ;
itest! ( error_local_static_import_from_remote_js {
args : " run --reload http://localhost:4545/cli/tests/error_local_static_import_from_remote.js " ,
exit_code : 1 ,
http_server : true ,
output : " error_local_static_import_from_remote.js.out " ,
} ) ;
2019-09-10 11:09:54 -04:00
itest! ( exit_error42 {
exit_code : 42 ,
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload exit_error42.ts " ,
2019-09-19 14:48:05 -04:00
output : " exit_error42.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( https_import {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload https_import.ts " ,
2019-09-19 14:48:05 -04:00
output : " https_import.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( if_main {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload if_main.ts " ,
2019-09-19 14:48:05 -04:00
output : " if_main.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( import_meta {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload import_meta.ts " ,
2019-09-19 14:48:05 -04:00
output : " import_meta.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2020-06-10 23:00:29 -04:00
itest! ( main_module {
2020-08-10 16:41:51 -04:00
args : " run --quiet --allow-read --reload main_module.ts " ,
2020-06-10 23:00:29 -04:00
output : " main_module.ts.out " ,
} ) ;
2020-07-08 05:26:39 -04:00
itest! ( no_check {
args : " run --quiet --reload --no-check 006_url_imports.ts " ,
output : " 006_url_imports.ts.out " ,
http_server : true ,
} ) ;
2020-02-19 00:34:11 -05:00
itest! ( lib_ref {
2020-05-17 11:42:39 -04:00
args : " run --quiet --unstable --reload lib_ref.ts " ,
2020-02-19 00:34:11 -05:00
output : " lib_ref.ts.out " ,
} ) ;
itest! ( lib_runtime_api {
2020-05-17 11:42:39 -04:00
args : " run --quiet --unstable --reload lib_runtime_api.ts " ,
2020-02-19 00:34:11 -05:00
output : " lib_runtime_api.ts.out " ,
} ) ;
2019-09-10 11:09:54 -04:00
itest! ( seed_random {
args : " run --seed=100 seed_random.js " ,
2020-05-19 14:19:26 -04:00
2019-09-19 14:48:05 -04:00
output : " seed_random.js.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( type_definitions {
args : " run --reload type_definitions.ts " ,
2019-09-19 14:48:05 -04:00
output : " type_definitions.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2020-06-10 08:19:41 -04:00
itest! ( type_definitions_for_export {
args : " run --reload type_definitions_for_export.ts " ,
output : " type_definitions_for_export.ts.out " ,
exit_code : 1 ,
} ) ;
2020-01-26 13:59:41 -05:00
itest! ( type_directives_01 {
args : " run --reload -L debug type_directives_01.ts " ,
output : " type_directives_01.ts.out " ,
http_server : true ,
} ) ;
itest! ( type_directives_02 {
args : " run --reload -L debug type_directives_02.ts " ,
output : " type_directives_02.ts.out " ,
} ) ;
2020-04-06 16:52:25 -04:00
itest! ( type_directives_js_main {
args : " run --reload -L debug type_directives_js_main.js " ,
output : " type_directives_js_main.js.out " ,
exit_code : 0 ,
} ) ;
2020-05-22 10:01:00 -04:00
itest! ( type_directives_redirect {
args : " run --reload type_directives_redirect.ts " ,
output : " type_directives_redirect.ts.out " ,
http_server : true ,
} ) ;
2020-07-24 08:21:36 -04:00
itest! ( type_headers_deno_types {
args : " run --reload type_headers_deno_types.ts " ,
output : " type_headers_deno_types.ts.out " ,
http_server : true ,
} ) ;
2020-05-22 13:05:18 -04:00
itest! ( ts_type_imports {
args : " run --reload ts_type_imports.ts " ,
output : " ts_type_imports.ts.out " ,
exit_code : 1 ,
2020-05-22 13:23:35 -04:00
} ) ;
itest! ( ts_decorators {
args : " run --reload -c tsconfig.decorators.json ts_decorators.ts " ,
output : " ts_decorators.ts.out " ,
} ) ;
2020-07-17 09:50:17 -04:00
itest! ( ts_type_only_import {
args : " run --reload ts_type_only_import.ts " ,
output : " ts_type_only_import.ts.out " ,
} ) ;
2020-05-22 13:23:35 -04:00
itest! ( swc_syntax_error {
args : " run --reload swc_syntax_error.ts " ,
output : " swc_syntax_error.ts.out " ,
exit_code : 1 ,
2020-05-22 13:05:18 -04:00
} ) ;
2019-09-10 11:09:54 -04:00
itest! ( types {
args : " types " ,
2019-09-19 14:48:05 -04:00
output : " types.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( unbuffered_stderr {
args : " run --reload unbuffered_stderr.ts " ,
2019-09-19 14:48:05 -04:00
output : " unbuffered_stderr.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( unbuffered_stdout {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload unbuffered_stdout.ts " ,
2019-09-19 14:48:05 -04:00
output : " unbuffered_stdout.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2020-01-26 09:49:34 -05:00
// Cannot write the expression to evaluate as "console.log(typeof gc)"
// because itest! splits args on whitespace.
2020-08-07 18:51:59 -04:00
itest! ( v8_flags_eval {
2020-01-26 09:49:34 -05:00
args : " eval --v8-flags=--expose-gc console.log(typeof(gc)) " ,
output : " v8_flags.js.out " ,
} ) ;
2020-08-07 18:51:59 -04:00
itest! ( v8_flags_run {
2019-09-10 11:09:54 -04:00
args : " run --v8-flags=--expose-gc v8_flags.js " ,
2019-09-19 14:48:05 -04:00
output : " v8_flags.js.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2020-08-07 18:51:59 -04:00
itest! ( v8_flags_unrecognized {
args : " repl --v8-flags=--foo,bar,--trace-gc,-baz " ,
output : " v8_flags_unrecognized.out " ,
exit_code : 1 ,
} ) ;
itest! ( v8_help {
2020-05-04 07:03:30 -04:00
args : " repl --v8-flags=--help " ,
2019-09-19 14:48:05 -04:00
output : " v8_help.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2020-05-07 09:57:10 -04:00
itest! ( unsupported_dynamic_import_scheme {
args : " eval import('xxx:') " ,
output : " unsupported_dynamic_import_scheme.out " ,
exit_code : 1 ,
} ) ;
2019-09-10 11:09:54 -04:00
itest! ( wasm {
2020-05-17 11:42:39 -04:00
args : " run --quiet wasm.ts " ,
2019-09-19 14:48:05 -04:00
output : " wasm.ts.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
itest! ( wasm_async {
2020-05-04 07:03:30 -04:00
args : " run wasm_async.js " ,
2019-09-19 14:48:05 -04:00
output : " wasm_async.out " ,
2019-09-10 11:09:54 -04:00
} ) ;
2019-09-24 18:37:04 -04:00
2020-08-14 13:48:37 -04:00
itest! ( wasm_streaming {
args : " run wasm_streaming.js " ,
output : " wasm_streaming.out " ,
} ) ;
2020-06-11 11:03:27 -04:00
itest! ( wasm_unreachable {
args : " run wasm_unreachable.js " ,
output : " wasm_unreachable.out " ,
exit_code : 1 ,
} ) ;
2019-09-24 18:37:04 -04:00
itest! ( top_level_await {
2020-05-04 07:03:30 -04:00
args : " run --allow-read top_level_await.js " ,
2019-09-24 18:37:04 -04:00
output : " top_level_await.out " ,
} ) ;
2019-09-30 12:38:23 -04:00
itest! ( top_level_await_ts {
2020-05-17 11:42:39 -04:00
args : " run --quiet --allow-read top_level_await.ts " ,
2019-09-30 12:38:23 -04:00
output : " top_level_await.out " ,
} ) ;
2019-10-27 09:04:42 -04:00
itest! ( top_level_for_await {
2020-05-17 11:42:39 -04:00
args : " run --quiet top_level_for_await.js " ,
2019-10-27 09:04:42 -04:00
output : " top_level_for_await.out " ,
} ) ;
itest! ( top_level_for_await_ts {
2020-05-17 11:42:39 -04:00
args : " run --quiet top_level_for_await.ts " ,
2019-10-27 09:04:42 -04:00
output : " top_level_for_await.out " ,
} ) ;
2019-10-29 17:52:57 -04:00
2020-04-30 11:23:40 -04:00
itest! ( unstable_disabled {
args : " run --reload unstable.ts " ,
exit_code : 1 ,
output : " unstable_disabled.out " ,
} ) ;
itest! ( unstable_enabled {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload --unstable unstable.ts " ,
2020-04-30 11:23:40 -04:00
output : " unstable_enabled.out " ,
} ) ;
itest! ( unstable_disabled_js {
args : " run --reload unstable.js " ,
output : " unstable_disabled_js.out " ,
} ) ;
itest! ( unstable_enabled_js {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload --unstable unstable.ts " ,
2020-04-30 11:23:40 -04:00
output : " unstable_enabled_js.out " ,
2020-04-25 09:31:54 -04:00
} ) ;
2020-07-13 08:00:56 -04:00
itest! ( unstable_disabled_ts2551 {
args : " run --reload unstable_ts2551.ts " ,
exit_code : 1 ,
output : " unstable_disabled_ts2551.out " ,
} ) ;
2020-01-11 05:11:05 -05:00
itest! ( _053_import_compression {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload --allow-net 053_import_compression/main.ts " ,
2020-01-11 05:11:05 -05:00
output : " 053_import_compression.out " ,
http_server : true ,
} ) ;
2020-02-17 11:59:51 -05:00
itest! ( cafile_url_imports {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload --cert tls/RootCA.pem cafile_url_imports.ts " ,
2020-02-17 11:59:51 -05:00
output : " cafile_url_imports.ts.out " ,
http_server : true ,
} ) ;
itest! ( cafile_ts_fetch {
2020-05-17 11:42:39 -04:00
args :
" run --quiet --reload --allow-net --cert tls/RootCA.pem cafile_ts_fetch.ts " ,
2020-02-17 11:59:51 -05:00
output : " cafile_ts_fetch.ts.out " ,
http_server : true ,
} ) ;
itest! ( cafile_eval {
args : " eval --cert tls/RootCA.pem fetch('https://localhost:5545/cli/tests/cafile_ts_fetch.ts.out').then(r=>r.text()).then(t=>console.log(t.trimEnd())) " ,
output : " cafile_ts_fetch.ts.out " ,
http_server : true ,
} ) ;
2020-07-11 12:29:55 -04:00
itest! ( cafile_info {
2020-02-17 11:59:51 -05:00
args :
2020-07-11 12:29:55 -04:00
" info --quiet --cert tls/RootCA.pem https://localhost:5545/cli/tests/cafile_info.ts " ,
2020-02-17 11:59:51 -05:00
output : " cafile_info.ts.out " ,
http_server : true ,
} ) ;
2020-05-21 07:06:12 -04:00
itest! ( disallow_http_from_https_js {
args : " run --quiet --reload --cert tls/RootCA.pem https://localhost:5545/cli/tests/disallow_http_from_https.js " ,
output : " disallow_http_from_https_js.out " ,
http_server : true ,
exit_code : 1 ,
} ) ;
itest! ( disallow_http_from_https_ts {
args : " run --quiet --reload --cert tls/RootCA.pem https://localhost:5545/cli/tests/disallow_http_from_https.ts " ,
output : " disallow_http_from_https_ts.out " ,
http_server : true ,
exit_code : 1 ,
} ) ;
2020-05-23 13:04:29 -04:00
itest! ( tsx_imports {
args : " run --reload tsx_imports.ts " ,
output : " tsx_imports.ts.out " ,
} ) ;
2020-02-25 03:32:43 -05:00
itest! ( fix_js_import_js {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload fix_js_import_js.ts " ,
2020-02-25 03:32:43 -05:00
output : " fix_js_import_js.ts.out " ,
} ) ;
2020-02-19 22:58:05 -05:00
itest! ( fix_js_imports {
2020-05-17 11:42:39 -04:00
args : " run --quiet --reload fix_js_imports.ts " ,
2020-02-19 22:58:05 -05:00
output : " fix_js_imports.ts.out " ,
} ) ;
2020-05-30 11:32:48 -04:00
itest! ( es_private_fields {
args : " run --quiet --reload es_private_fields.js " ,
output : " es_private_fields.js.out " ,
} ) ;
2020-05-31 15:08:26 -04:00
itest! ( cjs_imports {
args : " run --quiet --reload cjs_imports.ts " ,
output : " cjs_imports.ts.out " ,
} ) ;
2020-06-01 15:01:51 -04:00
itest! ( ts_import_from_js {
args : " run --quiet --reload ts_import_from_js.js " ,
output : " ts_import_from_js.js.out " ,
2020-06-10 10:02:41 -04:00
http_server : true ,
} ) ;
2020-06-15 11:53:05 -04:00
itest! ( jsx_import_from_ts {
args : " run --quiet --reload jsx_import_from_ts.ts " ,
output : " jsx_import_from_ts.ts.out " ,
} ) ;
2020-06-10 10:02:41 -04:00
itest! ( single_compile_with_reload {
args : " run --reload --allow-read single_compile_with_reload.ts " ,
output : " single_compile_with_reload.ts.out " ,
2020-06-01 15:01:51 -04:00
} ) ;
2020-06-24 05:58:23 -04:00
itest! ( performance_stats {
2020-06-25 09:50:16 -04:00
args : " cache --reload --log-level debug 002_hello.ts " ,
2020-06-24 05:58:23 -04:00
output : " performance_stats.out " ,
} ) ;
2020-03-15 06:34:22 -04:00
itest! ( proto_exploit {
args : " run proto_exploit.js " ,
output : " proto_exploit.js.out " ,
} ) ;
2020-06-09 12:40:08 -04:00
itest! ( deno_lint {
args : " lint --unstable lint/file1.js lint/file2.ts lint/ignored_file.ts " ,
output : " lint/expected.out " ,
exit_code : 1 ,
} ) ;
2020-08-13 11:30:46 -04:00
itest! ( deno_lint_json {
args :
" lint --unstable --json lint/file1.js lint/file2.ts lint/ignored_file.ts lint/malformed.js " ,
output : " lint/expected_json.out " ,
exit_code : 1 ,
} ) ;
2020-08-12 09:47:44 -04:00
itest! ( deno_lint_ignore {
2020-08-13 11:30:46 -04:00
args : " lint --unstable --ignore=lint/file1.js,lint/malformed.js lint/ " ,
2020-08-12 09:47:44 -04:00
output : " lint/expected_ignore.out " ,
exit_code : 1 ,
} ) ;
2020-06-10 17:29:48 -04:00
itest! ( deno_lint_glob {
2020-08-13 11:30:46 -04:00
args : " lint --unstable --ignore=lint/malformed.js lint/ " ,
2020-06-10 17:29:48 -04:00
output : " lint/expected_glob.out " ,
exit_code : 1 ,
} ) ;
2020-08-31 07:53:42 -04:00
itest! ( deno_lint_from_stdin {
args : " lint --unstable - " ,
input : Some ( " let a: any; " ) ,
output : " lint/expected_from_stdin.out " ,
exit_code : 1 ,
} ) ;
itest! ( deno_lint_from_stdin_json {
args : " lint --unstable --json - " ,
input : Some ( " let a: any; " ) ,
output : " lint/expected_from_stdin_json.out " ,
exit_code : 1 ,
} ) ;
2020-08-23 09:48:35 -04:00
itest! ( deno_doc_builtin {
args : " doc " ,
output : " deno_doc_builtin.out " ,
} ) ;
itest! ( deno_doc {
args : " doc deno_doc.ts " ,
output : " deno_doc.out " ,
} ) ;
2020-07-15 08:23:17 -04:00
itest! ( compiler_js_error {
args : " run --unstable compiler_js_error.ts " ,
output : " compiler_js_error.ts.out " ,
exit_code : 1 ,
} ) ;
2020-08-03 08:55:03 -04:00
itest! ( import_file_with_colon {
args : " run --quiet --reload import_file_with_colon.ts " ,
output : " import_file_with_colon.ts.out " ,
http_server : true ,
} ) ;
2020-08-26 14:27:06 -04:00
itest! ( info_type_import {
args : " info info_type_import.ts " ,
output : " info_type_import.out " ,
} ) ;
2020-07-12 19:18:27 -04:00
#[ test ]
fn cafile_env_fetch ( ) {
use url ::Url ;
2020-08-10 17:31:05 -04:00
let _g = util ::http_server ( ) ;
2020-07-12 19:18:27 -04:00
let deno_dir = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
let module_url =
Url ::parse ( " https://localhost:5545/cli/tests/cafile_url_imports.ts " )
. unwrap ( ) ;
let cafile = util ::root_path ( ) . join ( " cli/tests/tls/RootCA.pem " ) ;
let output = Command ::new ( util ::deno_exe_path ( ) )
. env ( " DENO_DIR " , deno_dir . path ( ) )
. env ( " DENO_CERT " , cafile )
. current_dir ( util ::root_path ( ) )
. arg ( " cache " )
. arg ( module_url . to_string ( ) )
. output ( )
. expect ( " Failed to spawn script " ) ;
assert! ( output . status . success ( ) ) ;
}
2020-02-17 11:59:51 -05:00
#[ test ]
fn cafile_fetch ( ) {
2020-02-19 08:17:13 -05:00
use url ::Url ;
2020-08-10 17:31:05 -04:00
let _g = util ::http_server ( ) ;
2020-02-17 11:59:51 -05:00
let deno_dir = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
2020-02-19 08:17:13 -05:00
let module_url =
Url ::parse ( " http://localhost:4545/cli/tests/cafile_url_imports.ts " )
. unwrap ( ) ;
2020-02-17 11:59:51 -05:00
let cafile = util ::root_path ( ) . join ( " cli/tests/tls/RootCA.pem " ) ;
2020-05-11 14:49:19 -04:00
let output = Command ::new ( util ::deno_exe_path ( ) )
2020-02-17 11:59:51 -05:00
. env ( " DENO_DIR " , deno_dir . path ( ) )
. current_dir ( util ::root_path ( ) )
2020-04-07 11:24:47 -04:00
. arg ( " cache " )
2020-02-17 11:59:51 -05:00
. arg ( " --cert " )
. arg ( cafile )
2020-02-19 08:17:13 -05:00
. arg ( module_url . to_string ( ) )
2020-02-17 11:59:51 -05:00
. output ( )
. expect ( " Failed to spawn script " ) ;
2020-05-11 14:49:19 -04:00
assert! ( output . status . success ( ) ) ;
2020-02-17 11:59:51 -05:00
let out = std ::str ::from_utf8 ( & output . stdout ) . unwrap ( ) ;
assert_eq! ( out , " " ) ;
}
#[ test ]
fn cafile_install_remote_module ( ) {
2020-08-10 17:31:05 -04:00
let _g = util ::http_server ( ) ;
2020-02-17 11:59:51 -05:00
let temp_dir = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
2020-04-16 18:15:42 -04:00
let bin_dir = temp_dir . path ( ) . join ( " bin " ) ;
std ::fs ::create_dir ( & bin_dir ) . unwrap ( ) ;
2020-02-17 11:59:51 -05:00
let deno_dir = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
let cafile = util ::root_path ( ) . join ( " cli/tests/tls/RootCA.pem " ) ;
2020-05-11 17:33:36 -04:00
let install_output = Command ::new ( util ::deno_exe_path ( ) )
2020-02-17 11:59:51 -05:00
. env ( " DENO_DIR " , deno_dir . path ( ) )
. current_dir ( util ::root_path ( ) )
. arg ( " install " )
. arg ( " --cert " )
. arg ( cafile )
2020-04-16 18:15:42 -04:00
. arg ( " --root " )
2020-02-17 11:59:51 -05:00
. arg ( temp_dir . path ( ) )
2020-05-01 15:33:11 -04:00
. arg ( " -n " )
2020-02-17 11:59:51 -05:00
. arg ( " echo_test " )
. arg ( " https://localhost:5545/cli/tests/echo.ts " )
. output ( )
. expect ( " Failed to spawn script " ) ;
2020-03-19 12:46:56 -04:00
assert! ( install_output . status . success ( ) ) ;
2020-02-17 11:59:51 -05:00
2020-04-16 18:15:42 -04:00
let mut echo_test_path = bin_dir . join ( " echo_test " ) ;
2020-02-17 11:59:51 -05:00
if cfg! ( windows ) {
2020-03-19 12:46:56 -04:00
echo_test_path = echo_test_path . with_extension ( " cmd " ) ;
2020-02-17 11:59:51 -05:00
}
2020-03-19 12:46:56 -04:00
assert! ( echo_test_path . exists ( ) ) ;
2020-02-17 11:59:51 -05:00
2020-03-19 12:46:56 -04:00
let output = Command ::new ( echo_test_path )
2020-02-17 11:59:51 -05:00
. current_dir ( temp_dir . path ( ) )
. arg ( " foo " )
2020-03-19 12:46:56 -04:00
. env ( " PATH " , util ::target_dir ( ) )
2020-02-17 11:59:51 -05:00
. output ( )
. expect ( " failed to spawn script " ) ;
2020-03-19 12:46:56 -04:00
let stdout = std ::str ::from_utf8 ( & output . stdout ) . unwrap ( ) . trim ( ) ;
assert! ( stdout . ends_with ( " foo " ) ) ;
2020-02-17 11:59:51 -05:00
}
#[ test ]
fn cafile_bundle_remote_exports ( ) {
2020-08-10 17:31:05 -04:00
let _g = util ::http_server ( ) ;
2020-02-17 11:59:51 -05:00
// First we have to generate a bundle of some remote module that has exports.
let mod1 = " https://localhost:5545/cli/tests/subdir/mod1.ts " ;
let cafile = util ::root_path ( ) . join ( " cli/tests/tls/RootCA.pem " ) ;
let t = TempDir ::new ( ) . expect ( " tempdir fail " ) ;
let bundle = t . path ( ) . join ( " mod1.bundle.js " ) ;
let mut deno = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " bundle " )
. arg ( " --cert " )
. arg ( cafile )
. arg ( mod1 )
. arg ( & bundle )
. spawn ( )
. expect ( " failed to spawn script " ) ;
let status = deno . wait ( ) . expect ( " failed to wait for the child process " ) ;
assert! ( status . success ( ) ) ;
assert! ( bundle . is_file ( ) ) ;
// Now we try to use that bundle from another module.
let test = t . path ( ) . join ( " test.js " ) ;
std ::fs ::write (
& test ,
"
import { printHello3 } from \ " ./mod1.bundle.js \" ;
printHello3 ( ) ; " ,
)
. expect ( " error writing file " ) ;
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( & test )
. output ( )
. expect ( " failed to spawn script " ) ;
// check the output of the test.ts program.
assert! ( std ::str ::from_utf8 ( & output . stdout )
. unwrap ( )
. trim ( )
. ends_with ( " Hello " ) ) ;
assert_eq! ( output . stderr , b " " ) ;
}
2020-02-25 15:36:35 -05:00
#[ test ]
fn test_permissions_with_allow ( ) {
for permission in & util ::PERMISSION_VARIANTS {
2020-05-28 19:40:33 -04:00
let status = util ::deno_cmd ( )
. current_dir ( & util ::tests_path ( ) )
. arg ( " run " )
. arg ( format! ( " --allow- {0} " , permission ) )
. arg ( " permission_test.ts " )
. arg ( format! ( " {0} Required " , permission ) )
. spawn ( )
. unwrap ( )
. wait ( )
. unwrap ( ) ;
assert! ( status . success ( ) ) ;
2020-02-25 15:36:35 -05:00
}
}
#[ test ]
fn test_permissions_without_allow ( ) {
for permission in & util ::PERMISSION_VARIANTS {
2020-03-07 05:27:16 -05:00
let ( _ , err ) = util ::run_and_collect_output (
false ,
2020-02-25 15:36:35 -05:00
& format! ( " run permission_test.ts {0} Required " , permission ) ,
None ,
None ,
2020-03-01 19:51:54 -05:00
false ,
2020-02-25 15:36:35 -05:00
) ;
assert! ( err . contains ( util ::PERMISSION_DENIED_PATTERN ) ) ;
}
}
2020-03-01 19:51:54 -05:00
#[ test ]
fn test_permissions_rw_inside_project_dir ( ) {
const PERMISSION_VARIANTS : [ & str ; 2 ] = [ " read " , " write " ] ;
for permission in & PERMISSION_VARIANTS {
2020-05-28 19:40:33 -04:00
let status = util ::deno_cmd ( )
. current_dir ( & util ::tests_path ( ) )
. arg ( " run " )
. arg ( format! (
" --allow-{0}={1} " ,
2020-03-01 19:51:54 -05:00
permission ,
2020-05-28 19:40:33 -04:00
util ::root_path ( ) . into_os_string ( ) . into_string ( ) . unwrap ( )
) )
. arg ( " complex_permissions_test.ts " )
. arg ( permission )
. arg ( " complex_permissions_test.ts " )
. spawn ( )
. unwrap ( )
. wait ( )
. unwrap ( ) ;
assert! ( status . success ( ) ) ;
2020-03-01 19:51:54 -05:00
}
}
#[ test ]
fn test_permissions_rw_outside_test_dir ( ) {
const PERMISSION_VARIANTS : [ & str ; 2 ] = [ " read " , " write " ] ;
for permission in & PERMISSION_VARIANTS {
2020-03-07 05:27:16 -05:00
let ( _ , err ) = util ::run_and_collect_output (
false ,
2020-03-01 19:51:54 -05:00
& format! (
" run --allow-{0}={1} complex_permissions_test.ts {0} {2} " ,
permission ,
util ::root_path ( )
. join ( " cli " )
. join ( " tests " )
. into_os_string ( )
. into_string ( )
. unwrap ( ) ,
util ::root_path ( )
. join ( " Cargo.toml " )
. into_os_string ( )
. into_string ( )
. unwrap ( ) ,
) ,
None ,
None ,
false ,
) ;
assert! ( err . contains ( util ::PERMISSION_DENIED_PATTERN ) ) ;
}
}
#[ test ]
fn test_permissions_rw_inside_test_dir ( ) {
const PERMISSION_VARIANTS : [ & str ; 2 ] = [ " read " , " write " ] ;
for permission in & PERMISSION_VARIANTS {
2020-05-28 19:40:33 -04:00
let status = util ::deno_cmd ( )
. current_dir ( & util ::tests_path ( ) )
. arg ( " run " )
. arg ( format! (
" --allow-{0}={1} " ,
2020-03-01 19:51:54 -05:00
permission ,
util ::root_path ( )
. join ( " cli " )
. join ( " tests " )
. into_os_string ( )
. into_string ( )
2020-05-28 19:40:33 -04:00
. unwrap ( )
) )
. arg ( " complex_permissions_test.ts " )
. arg ( permission )
. arg ( " complex_permissions_test.ts " )
. spawn ( )
. unwrap ( )
. wait ( )
. unwrap ( ) ;
assert! ( status . success ( ) ) ;
2020-03-01 19:51:54 -05:00
}
}
#[ test ]
fn test_permissions_rw_outside_test_and_js_dir ( ) {
const PERMISSION_VARIANTS : [ & str ; 2 ] = [ " read " , " write " ] ;
let test_dir = util ::root_path ( )
. join ( " cli " )
. join ( " tests " )
. into_os_string ( )
. into_string ( )
. unwrap ( ) ;
let js_dir = util ::root_path ( )
. join ( " js " )
. into_os_string ( )
. into_string ( )
. unwrap ( ) ;
for permission in & PERMISSION_VARIANTS {
2020-03-07 05:27:16 -05:00
let ( _ , err ) = util ::run_and_collect_output (
false ,
2020-03-01 19:51:54 -05:00
& format! (
" run --allow-{0}={1},{2} complex_permissions_test.ts {0} {3} " ,
permission ,
test_dir ,
js_dir ,
util ::root_path ( )
. join ( " Cargo.toml " )
. into_os_string ( )
. into_string ( )
. unwrap ( ) ,
) ,
None ,
None ,
false ,
) ;
assert! ( err . contains ( util ::PERMISSION_DENIED_PATTERN ) ) ;
}
}
#[ test ]
fn test_permissions_rw_inside_test_and_js_dir ( ) {
const PERMISSION_VARIANTS : [ & str ; 2 ] = [ " read " , " write " ] ;
let test_dir = util ::root_path ( )
. join ( " cli " )
. join ( " tests " )
. into_os_string ( )
. into_string ( )
. unwrap ( ) ;
let js_dir = util ::root_path ( )
. join ( " js " )
. into_os_string ( )
. into_string ( )
. unwrap ( ) ;
for permission in & PERMISSION_VARIANTS {
2020-05-28 19:40:33 -04:00
let status = util ::deno_cmd ( )
. current_dir ( & util ::tests_path ( ) )
. arg ( " run " )
. arg ( format! ( " --allow- {0} = {1} , {2} " , permission , test_dir , js_dir ) )
. arg ( " complex_permissions_test.ts " )
. arg ( permission )
. arg ( " complex_permissions_test.ts " )
. spawn ( )
. unwrap ( )
. wait ( )
. unwrap ( ) ;
assert! ( status . success ( ) ) ;
2020-03-01 19:51:54 -05:00
}
}
#[ test ]
fn test_permissions_rw_relative ( ) {
const PERMISSION_VARIANTS : [ & str ; 2 ] = [ " read " , " write " ] ;
for permission in & PERMISSION_VARIANTS {
2020-05-28 19:40:33 -04:00
let status = util ::deno_cmd ( )
. current_dir ( & util ::tests_path ( ) )
. arg ( " run " )
. arg ( format! ( " --allow- {0} =. " , permission ) )
. arg ( " complex_permissions_test.ts " )
. arg ( permission )
. arg ( " complex_permissions_test.ts " )
. spawn ( )
. unwrap ( )
. wait ( )
. unwrap ( ) ;
assert! ( status . success ( ) ) ;
2020-03-01 19:51:54 -05:00
}
}
#[ test ]
fn test_permissions_rw_no_prefix ( ) {
const PERMISSION_VARIANTS : [ & str ; 2 ] = [ " read " , " write " ] ;
for permission in & PERMISSION_VARIANTS {
2020-05-28 19:40:33 -04:00
let status = util ::deno_cmd ( )
. current_dir ( & util ::tests_path ( ) )
. arg ( " run " )
. arg ( format! ( " --allow- {0} =tls/../ " , permission ) )
. arg ( " complex_permissions_test.ts " )
. arg ( permission )
. arg ( " complex_permissions_test.ts " )
. spawn ( )
. unwrap ( )
. wait ( )
. unwrap ( ) ;
assert! ( status . success ( ) ) ;
2020-03-01 19:51:54 -05:00
}
}
#[ test ]
fn test_permissions_net_fetch_allow_localhost_4545 ( ) {
2020-03-07 05:27:16 -05:00
let ( _ , err ) = util ::run_and_collect_output (
true ,
2020-03-01 19:51:54 -05:00
" run --allow-net=localhost:4545 complex_permissions_test.ts netFetch http://localhost:4545/ " ,
None ,
2020-03-11 18:19:24 -04:00
None ,
true ,
2020-03-01 19:51:54 -05:00
) ;
assert! ( ! err . contains ( util ::PERMISSION_DENIED_PATTERN ) ) ;
}
#[ test ]
fn test_permissions_net_fetch_allow_deno_land ( ) {
2020-03-07 05:27:16 -05:00
let ( _ , err ) = util ::run_and_collect_output (
false ,
2020-03-01 19:51:54 -05:00
" run --allow-net=deno.land complex_permissions_test.ts netFetch http://localhost:4545/ " ,
None ,
None ,
true ,
) ;
assert! ( err . contains ( util ::PERMISSION_DENIED_PATTERN ) ) ;
}
#[ test ]
fn test_permissions_net_fetch_localhost_4545_fail ( ) {
2020-03-07 05:27:16 -05:00
let ( _ , err ) = util ::run_and_collect_output (
false ,
2020-03-01 19:51:54 -05:00
" run --allow-net=localhost:4545 complex_permissions_test.ts netFetch http://localhost:4546/ " ,
None ,
None ,
true ,
) ;
assert! ( err . contains ( util ::PERMISSION_DENIED_PATTERN ) ) ;
}
#[ test ]
fn test_permissions_net_fetch_localhost ( ) {
2020-03-07 05:27:16 -05:00
let ( _ , err ) = util ::run_and_collect_output (
true ,
2020-03-01 19:51:54 -05:00
" run --allow-net=localhost complex_permissions_test.ts netFetch http://localhost:4545/ http://localhost:4546/ http://localhost:4547/ " ,
None ,
None ,
true ,
) ;
assert! ( ! err . contains ( util ::PERMISSION_DENIED_PATTERN ) ) ;
}
#[ test ]
fn test_permissions_net_connect_allow_localhost_ip_4555 ( ) {
2020-03-07 05:27:16 -05:00
let ( _ , err ) = util ::run_and_collect_output (
true ,
2020-03-01 19:51:54 -05:00
" run --allow-net=127.0.0.1:4545 complex_permissions_test.ts netConnect 127.0.0.1:4545 " ,
None ,
None ,
true ,
) ;
assert! ( ! err . contains ( util ::PERMISSION_DENIED_PATTERN ) ) ;
}
#[ test ]
fn test_permissions_net_connect_allow_deno_land ( ) {
2020-03-07 05:27:16 -05:00
let ( _ , err ) = util ::run_and_collect_output (
false ,
2020-03-01 19:51:54 -05:00
" run --allow-net=deno.land complex_permissions_test.ts netConnect 127.0.0.1:4546 " ,
None ,
None ,
true ,
) ;
assert! ( err . contains ( util ::PERMISSION_DENIED_PATTERN ) ) ;
}
#[ test ]
fn test_permissions_net_connect_allow_localhost_ip_4545_fail ( ) {
2020-03-07 05:27:16 -05:00
let ( _ , err ) = util ::run_and_collect_output (
false ,
2020-03-01 19:51:54 -05:00
" run --allow-net=127.0.0.1:4545 complex_permissions_test.ts netConnect 127.0.0.1:4546 " ,
None ,
None ,
true ,
) ;
assert! ( err . contains ( util ::PERMISSION_DENIED_PATTERN ) ) ;
}
#[ test ]
fn test_permissions_net_connect_allow_localhost_ip ( ) {
2020-03-07 05:27:16 -05:00
let ( _ , err ) = util ::run_and_collect_output (
true ,
2020-03-01 19:51:54 -05:00
" run --allow-net=127.0.0.1 complex_permissions_test.ts netConnect 127.0.0.1:4545 127.0.0.1:4546 127.0.0.1:4547 " ,
None ,
None ,
true ,
) ;
assert! ( ! err . contains ( util ::PERMISSION_DENIED_PATTERN ) ) ;
}
#[ test ]
fn test_permissions_net_listen_allow_localhost_4555 ( ) {
2020-03-07 05:27:16 -05:00
let ( _ , err ) = util ::run_and_collect_output (
true ,
2020-03-01 19:51:54 -05:00
" run --allow-net=localhost:4558 complex_permissions_test.ts netListen localhost:4558 " ,
None ,
None ,
false ,
) ;
assert! ( ! err . contains ( util ::PERMISSION_DENIED_PATTERN ) ) ;
}
#[ test ]
fn test_permissions_net_listen_allow_deno_land ( ) {
2020-03-07 05:27:16 -05:00
let ( _ , err ) = util ::run_and_collect_output (
false ,
2020-03-01 19:51:54 -05:00
" run --allow-net=deno.land complex_permissions_test.ts netListen localhost:4545 " ,
None ,
None ,
false ,
) ;
assert! ( err . contains ( util ::PERMISSION_DENIED_PATTERN ) ) ;
}
#[ test ]
fn test_permissions_net_listen_allow_localhost_4555_fail ( ) {
2020-03-07 05:27:16 -05:00
let ( _ , err ) = util ::run_and_collect_output (
false ,
2020-03-01 19:51:54 -05:00
" run --allow-net=localhost:4555 complex_permissions_test.ts netListen localhost:4556 " ,
None ,
None ,
false ,
) ;
assert! ( err . contains ( util ::PERMISSION_DENIED_PATTERN ) ) ;
}
#[ test ]
fn test_permissions_net_listen_allow_localhost ( ) {
2020-07-04 13:05:01 -04:00
// Port 4600 is chosen to not colide with those used by
// target/debug/test_server
2020-03-07 05:27:16 -05:00
let ( _ , err ) = util ::run_and_collect_output (
true ,
2020-03-06 11:40:18 -05:00
" run --allow-net=localhost complex_permissions_test.ts netListen localhost:4600 " ,
2020-03-01 19:51:54 -05:00
None ,
None ,
2020-03-11 18:19:24 -04:00
false ,
2020-03-01 19:51:54 -05:00
) ;
assert! ( ! err . contains ( util ::PERMISSION_DENIED_PATTERN ) ) ;
}
2020-05-24 20:08:59 -04:00
fn inspect_flag_with_unique_port ( flag_prefix : & str ) -> String {
use std ::sync ::atomic ::{ AtomicU16 , Ordering } ;
static PORT : AtomicU16 = AtomicU16 ::new ( 9229 ) ;
let port = PORT . fetch_add ( 1 , Ordering ::Relaxed ) ;
format! ( " {} =127.0.0.1: {} " , flag_prefix , port )
}
2020-03-27 16:09:51 -04:00
fn extract_ws_url_from_stderr (
2020-05-24 16:28:19 -04:00
stderr_lines : & mut impl std ::iter ::Iterator < Item = String > ,
2020-03-27 16:09:51 -04:00
) -> url ::Url {
2020-05-24 16:28:19 -04:00
let stderr_first_line = stderr_lines . next ( ) . unwrap ( ) ;
2020-03-27 16:09:51 -04:00
assert! ( stderr_first_line . starts_with ( " Debugger listening on " ) ) ;
let v : Vec < _ > = stderr_first_line . match_indices ( " ws: " ) . collect ( ) ;
assert_eq! ( v . len ( ) , 1 ) ;
let ws_url_index = v [ 0 ] . 0 ;
let ws_url = & stderr_first_line [ ws_url_index .. ] ;
url ::Url ::parse ( ws_url ) . unwrap ( )
}
#[ tokio::test ]
async fn inspector_connect ( ) {
2020-05-04 23:39:42 -04:00
let script = util ::tests_path ( ) . join ( " inspector1.js " ) ;
2020-03-27 16:09:51 -04:00
let mut child = util ::deno_cmd ( )
. arg ( " run " )
2020-05-24 20:08:59 -04:00
. arg ( inspect_flag_with_unique_port ( " --inspect " ) )
2020-03-27 16:09:51 -04:00
. arg ( script )
. stderr ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( ) ;
2020-05-24 16:28:19 -04:00
let stderr = child . stderr . as_mut ( ) . unwrap ( ) ;
let mut stderr_lines =
std ::io ::BufReader ::new ( stderr ) . lines ( ) . map ( | r | r . unwrap ( ) ) ;
let ws_url = extract_ws_url_from_stderr ( & mut stderr_lines ) ;
2020-03-27 16:09:51 -04:00
// We use tokio_tungstenite as a websocket client because warp (which is
// a dependency of Deno) uses it.
let ( _socket , response ) = tokio_tungstenite ::connect_async ( ws_url )
. await
. expect ( " Can't connect " ) ;
assert_eq! ( " 101 Switching Protocols " , response . status ( ) . to_string ( ) ) ;
child . kill ( ) . unwrap ( ) ;
2020-05-04 23:39:42 -04:00
child . wait ( ) . unwrap ( ) ;
2020-03-27 16:09:51 -04:00
}
2020-04-03 13:40:11 -04:00
enum TestStep {
StdOut ( & 'static str ) ,
2020-05-24 16:28:19 -04:00
StdErr ( & 'static str ) ,
2020-04-03 13:40:11 -04:00
WsRecv ( & 'static str ) ,
WsSend ( & 'static str ) ,
}
#[ tokio::test ]
async fn inspector_break_on_first_line ( ) {
2020-05-04 23:39:42 -04:00
let script = util ::tests_path ( ) . join ( " inspector2.js " ) ;
2020-04-03 13:40:11 -04:00
let mut child = util ::deno_cmd ( )
. arg ( " run " )
2020-05-24 20:08:59 -04:00
. arg ( inspect_flag_with_unique_port ( " --inspect-brk " ) )
2020-04-03 13:40:11 -04:00
. arg ( script )
. stdout ( std ::process ::Stdio ::piped ( ) )
. stderr ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( ) ;
let stderr = child . stderr . as_mut ( ) . unwrap ( ) ;
2020-05-24 16:28:19 -04:00
let mut stderr_lines =
std ::io ::BufReader ::new ( stderr ) . lines ( ) . map ( | r | r . unwrap ( ) ) ;
let ws_url = extract_ws_url_from_stderr ( & mut stderr_lines ) ;
2020-04-03 13:40:11 -04:00
let ( socket , response ) = tokio_tungstenite ::connect_async ( ws_url )
. await
. expect ( " Can't connect " ) ;
assert_eq! ( response . status ( ) , 101 ) ; // Switching protocols.
2020-05-05 21:50:55 -04:00
let ( mut socket_tx , socket_rx ) = socket . split ( ) ;
let mut socket_rx =
socket_rx . map ( | msg | msg . unwrap ( ) . to_string ( ) ) . filter ( | msg | {
let pass = ! msg . starts_with ( r # "{"method":"Debugger.scriptParsed","# ) ;
futures ::future ::ready ( pass )
} ) ;
2020-04-03 13:40:11 -04:00
let stdout = child . stdout . as_mut ( ) . unwrap ( ) ;
2020-05-05 21:50:55 -04:00
let mut stdout_lines =
std ::io ::BufReader ::new ( stdout ) . lines ( ) . map ( | r | r . unwrap ( ) ) ;
2020-04-03 13:40:11 -04:00
use TestStep ::* ;
let test_steps = vec! [
WsSend ( r # "{"id":1,"method":"Runtime.enable"}"# ) ,
WsSend ( r # "{"id":2,"method":"Debugger.enable"}"# ) ,
WsRecv (
r # "{"method":"Runtime.executionContextCreated","params":{"context":{"id":1,"# ,
) ,
WsRecv ( r # "{"id":1,"result":{}}"# ) ,
WsRecv ( r # "{"id":2,"result":{"debuggerId":"# ) ,
WsSend ( r # "{"id":3,"method":"Runtime.runIfWaitingForDebugger"}"# ) ,
WsRecv ( r # "{"id":3,"result":{}}"# ) ,
WsRecv ( r # "{"method":"Debugger.paused","# ) ,
WsSend (
2020-05-04 23:39:42 -04:00
r # "{"id":4,"method":"Runtime.evaluate","params":{"expression":"Deno.core.print(\"hello from the inspector\\n\")","contextId":1,"includeCommandLineAPI":true,"silent":false,"returnByValue":true}}"# ,
2020-04-03 13:40:11 -04:00
) ,
2020-05-04 23:39:42 -04:00
WsRecv ( r # "{"id":4,"result":{"result":{"type":"undefined"}}}"# ) ,
2020-04-03 13:40:11 -04:00
StdOut ( " hello from the inspector " ) ,
2020-05-04 23:39:42 -04:00
WsSend ( r # "{"id":5,"method":"Debugger.resume"}"# ) ,
WsRecv ( r # "{"id":5,"result":{}}"# ) ,
2020-04-03 13:40:11 -04:00
StdOut ( " hello from the script " ) ,
] ;
for step in test_steps {
match step {
2020-05-05 21:50:55 -04:00
StdOut ( s ) = > assert_eq! ( & stdout_lines . next ( ) . unwrap ( ) , s ) ,
WsRecv ( s ) = > assert! ( socket_rx . next ( ) . await . unwrap ( ) . starts_with ( s ) ) ,
2020-04-03 13:40:11 -04:00
WsSend ( s ) = > socket_tx . send ( s . into ( ) ) . await . unwrap ( ) ,
2020-05-24 16:28:19 -04:00
_ = > unreachable! ( ) ,
2020-04-03 13:40:11 -04:00
}
}
child . kill ( ) . unwrap ( ) ;
2020-05-04 23:39:42 -04:00
child . wait ( ) . unwrap ( ) ;
2020-04-03 13:40:11 -04:00
}
2020-03-27 16:09:51 -04:00
#[ tokio::test ]
async fn inspector_pause ( ) {
2020-05-04 23:39:42 -04:00
let script = util ::tests_path ( ) . join ( " inspector1.js " ) ;
2020-03-27 16:09:51 -04:00
let mut child = util ::deno_cmd ( )
. arg ( " run " )
2020-05-24 20:08:59 -04:00
. arg ( inspect_flag_with_unique_port ( " --inspect " ) )
2020-03-27 16:09:51 -04:00
. arg ( script )
. stderr ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( ) ;
2020-05-24 16:28:19 -04:00
let stderr = child . stderr . as_mut ( ) . unwrap ( ) ;
let mut stderr_lines =
std ::io ::BufReader ::new ( stderr ) . lines ( ) . map ( | r | r . unwrap ( ) ) ;
let ws_url = extract_ws_url_from_stderr ( & mut stderr_lines ) ;
2020-03-27 16:09:51 -04:00
// We use tokio_tungstenite as a websocket client because warp (which is
// a dependency of Deno) uses it.
let ( mut socket , _ ) = tokio_tungstenite ::connect_async ( ws_url )
. await
. expect ( " Can't connect " ) ;
/// Returns the next websocket message as a string ignoring
/// Debugger.scriptParsed messages.
async fn ws_read_msg (
socket : & mut tokio_tungstenite ::WebSocketStream < tokio ::net ::TcpStream > ,
) -> String {
use futures ::stream ::StreamExt ;
while let Some ( msg ) = socket . next ( ) . await {
let msg = msg . unwrap ( ) . to_string ( ) ;
2020-07-19 13:49:44 -04:00
// FIXME(bartlomieju): fails because there's a file loaded
// called 150_errors.js
// assert!(!msg.contains("error"));
2020-03-27 16:09:51 -04:00
if ! msg . contains ( " Debugger.scriptParsed " ) {
return msg ;
}
}
unreachable! ( )
}
socket
. send ( r # "{"id":6,"method":"Debugger.enable"}"# . into ( ) )
. await
. unwrap ( ) ;
let msg = ws_read_msg ( & mut socket ) . await ;
println! ( " response msg 1 {} " , msg ) ;
assert! ( msg . starts_with ( r # "{"id":6,"result":{"debuggerId":"# ) ) ;
socket
. send ( r # "{"id":31,"method":"Debugger.pause"}"# . into ( ) )
. await
. unwrap ( ) ;
let msg = ws_read_msg ( & mut socket ) . await ;
println! ( " response msg 2 {} " , msg ) ;
assert_eq! ( msg , r # "{"id":31,"result":{}}"# ) ;
child . kill ( ) . unwrap ( ) ;
}
2020-03-28 17:42:29 -04:00
#[ tokio::test ]
async fn inspector_port_collision ( ) {
2020-08-08 14:15:11 -04:00
// Skip this test on WSL, which allows multiple processes to listen on the
// same port, rather than making `bind()` fail with `EADDRINUSE`.
if cfg! ( target_os = " linux " ) & & std ::env ::var_os ( " WSL_DISTRO_NAME " ) . is_some ( )
{
return ;
}
2020-05-04 23:39:42 -04:00
let script = util ::tests_path ( ) . join ( " inspector1.js " ) ;
2020-05-24 20:08:59 -04:00
let inspect_flag = inspect_flag_with_unique_port ( " --inspect " ) ;
2020-03-28 17:42:29 -04:00
let mut child1 = util ::deno_cmd ( )
. arg ( " run " )
2020-05-24 20:08:59 -04:00
. arg ( & inspect_flag )
2020-03-28 17:42:29 -04:00
. arg ( script . clone ( ) )
. stderr ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( ) ;
2020-05-24 16:28:19 -04:00
let stderr_1 = child1 . stderr . as_mut ( ) . unwrap ( ) ;
2020-08-08 14:01:54 -04:00
let mut stderr_1_lines = std ::io ::BufReader ::new ( stderr_1 )
2020-05-24 16:28:19 -04:00
. lines ( )
. map ( | r | r . unwrap ( ) ) ;
2020-08-08 14:01:54 -04:00
let _ = extract_ws_url_from_stderr ( & mut stderr_1_lines ) ;
2020-03-28 17:42:29 -04:00
let mut child2 = util ::deno_cmd ( )
. arg ( " run " )
2020-05-24 20:08:59 -04:00
. arg ( & inspect_flag )
2020-03-28 17:42:29 -04:00
. arg ( script )
. stderr ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( ) ;
2020-08-08 14:01:54 -04:00
let stderr_2 = child2 . stderr . as_mut ( ) . unwrap ( ) ;
let stderr_2_error_message = std ::io ::BufReader ::new ( stderr_2 )
. lines ( )
. map ( | r | r . unwrap ( ) )
. inspect ( | line | assert! ( ! line . contains ( " Debugger listening " ) ) )
. find ( | line | line . contains ( " Cannot start inspector server " ) ) ;
assert! ( stderr_2_error_message . is_some ( ) ) ;
2020-05-04 23:39:42 -04:00
2020-03-28 17:42:29 -04:00
child1 . kill ( ) . unwrap ( ) ;
2020-05-04 23:39:42 -04:00
child1 . wait ( ) . unwrap ( ) ;
child2 . wait ( ) . unwrap ( ) ;
}
#[ tokio::test ]
async fn inspector_does_not_hang ( ) {
let script = util ::tests_path ( ) . join ( " inspector3.js " ) ;
let mut child = util ::deno_cmd ( )
. arg ( " run " )
2020-05-24 20:08:59 -04:00
. arg ( inspect_flag_with_unique_port ( " --inspect-brk " ) )
2020-05-19 14:19:26 -04:00
. env ( " NO_COLOR " , " 1 " )
2020-05-04 23:39:42 -04:00
. arg ( script )
. stdout ( std ::process ::Stdio ::piped ( ) )
. stderr ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( ) ;
let stderr = child . stderr . as_mut ( ) . unwrap ( ) ;
2020-05-24 16:28:19 -04:00
let mut stderr_lines =
std ::io ::BufReader ::new ( stderr ) . lines ( ) . map ( | r | r . unwrap ( ) ) ;
let ws_url = extract_ws_url_from_stderr ( & mut stderr_lines ) ;
2020-05-04 23:39:42 -04:00
let ( socket , response ) = tokio_tungstenite ::connect_async ( ws_url )
. await
. expect ( " Can't connect " ) ;
assert_eq! ( response . status ( ) , 101 ) ; // Switching protocols.
let ( mut socket_tx , socket_rx ) = socket . split ( ) ;
let mut socket_rx =
socket_rx . map ( | msg | msg . unwrap ( ) . to_string ( ) ) . filter ( | msg | {
let pass = ! msg . starts_with ( r # "{"method":"Debugger.scriptParsed","# ) ;
futures ::future ::ready ( pass )
} ) ;
let stdout = child . stdout . as_mut ( ) . unwrap ( ) ;
let mut stdout_lines =
std ::io ::BufReader ::new ( stdout ) . lines ( ) . map ( | r | r . unwrap ( ) ) ;
use TestStep ::* ;
let test_steps = vec! [
WsSend ( r # "{"id":1,"method":"Runtime.enable"}"# ) ,
WsSend ( r # "{"id":2,"method":"Debugger.enable"}"# ) ,
WsRecv (
r # "{"method":"Runtime.executionContextCreated","params":{"context":{"id":1,"# ,
) ,
WsRecv ( r # "{"id":1,"result":{}}"# ) ,
WsRecv ( r # "{"id":2,"result":{"debuggerId":"# ) ,
WsSend ( r # "{"id":3,"method":"Runtime.runIfWaitingForDebugger"}"# ) ,
WsRecv ( r # "{"id":3,"result":{}}"# ) ,
WsRecv ( r # "{"method":"Debugger.paused","# ) ,
WsSend ( r # "{"id":4,"method":"Debugger.resume"}"# ) ,
WsRecv ( r # "{"id":4,"result":{}}"# ) ,
WsRecv ( r # "{"method":"Debugger.resumed","params":{}}"# ) ,
] ;
for step in test_steps {
match step {
WsRecv ( s ) = > assert! ( socket_rx . next ( ) . await . unwrap ( ) . starts_with ( s ) ) ,
WsSend ( s ) = > socket_tx . send ( s . into ( ) ) . await . unwrap ( ) ,
_ = > unreachable! ( ) ,
}
}
for i in 0 .. 128 u32 {
let request_id = i + 10 ;
// Expect the number {i} on stdout.
let s = format! ( " {} " , i ) ;
assert_eq! ( stdout_lines . next ( ) . unwrap ( ) , s ) ;
// Expect hitting the `debugger` statement.
let s = r # "{"method":"Debugger.paused","# ;
assert! ( socket_rx . next ( ) . await . unwrap ( ) . starts_with ( s ) ) ;
// Send the 'Debugger.resume' request.
let s = format! ( r # "{{"id":{},"method":"Debugger.resume"}}"# , request_id ) ;
socket_tx . send ( s . into ( ) ) . await . unwrap ( ) ;
// Expect confirmation of the 'Debugger.resume' request.
let s = format! ( r # "{{"id":{},"result":{{}}}}"# , request_id ) ;
assert_eq! ( socket_rx . next ( ) . await . unwrap ( ) , s ) ;
let s = r # "{"method":"Debugger.resumed","params":{}}"# ;
assert_eq! ( socket_rx . next ( ) . await . unwrap ( ) , s ) ;
}
// Check that we can gracefully close the websocket connection.
socket_tx . close ( ) . await . unwrap ( ) ;
socket_rx . for_each ( | _ | async { } ) . await ;
assert_eq! ( & stdout_lines . next ( ) . unwrap ( ) , " done " ) ;
assert! ( child . wait ( ) . unwrap ( ) . success ( ) ) ;
2020-03-28 17:42:29 -04:00
}
2020-05-21 14:34:25 -04:00
#[ tokio::test ]
async fn inspector_without_brk_runs_code ( ) {
let script = util ::tests_path ( ) . join ( " inspector4.js " ) ;
let mut child = util ::deno_cmd ( )
. arg ( " run " )
2020-05-24 20:08:59 -04:00
. arg ( inspect_flag_with_unique_port ( " --inspect " ) )
2020-05-21 14:34:25 -04:00
. arg ( script )
. stdout ( std ::process ::Stdio ::piped ( ) )
. stderr ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( ) ;
2020-05-24 16:28:19 -04:00
let stderr = child . stderr . as_mut ( ) . unwrap ( ) ;
let mut stderr_lines =
std ::io ::BufReader ::new ( stderr ) . lines ( ) . map ( | r | r . unwrap ( ) ) ;
let _ = extract_ws_url_from_stderr ( & mut stderr_lines ) ;
2020-05-21 14:34:25 -04:00
// Check that inspector actually runs code without waiting for inspector
2020-05-24 16:28:19 -04:00
// connection.
let stdout = child . stdout . as_mut ( ) . unwrap ( ) ;
let mut stdout_lines =
std ::io ::BufReader ::new ( stdout ) . lines ( ) . map ( | r | r . unwrap ( ) ) ;
let stdout_first_line = stdout_lines . next ( ) . unwrap ( ) ;
assert_eq! ( stdout_first_line , " hello " ) ;
2020-05-21 14:34:25 -04:00
child . kill ( ) . unwrap ( ) ;
2020-05-24 16:28:19 -04:00
child . wait ( ) . unwrap ( ) ;
}
#[ tokio::test ]
async fn inspector_runtime_evaluate_does_not_crash ( ) {
let mut child = util ::deno_cmd ( )
. arg ( " repl " )
. arg ( inspect_flag_with_unique_port ( " --inspect " ) )
. stdin ( std ::process ::Stdio ::piped ( ) )
. stdout ( std ::process ::Stdio ::piped ( ) )
. stderr ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( ) ;
let stderr = child . stderr . as_mut ( ) . unwrap ( ) ;
let mut stderr_lines = std ::io ::BufReader ::new ( stderr )
. lines ( )
. map ( | r | r . unwrap ( ) )
. filter ( | s | s . as_str ( ) ! = " Debugger session started. " ) ;
let ws_url = extract_ws_url_from_stderr ( & mut stderr_lines ) ;
let ( socket , response ) = tokio_tungstenite ::connect_async ( ws_url )
. await
. expect ( " Can't connect " ) ;
assert_eq! ( response . status ( ) , 101 ) ; // Switching protocols.
let ( mut socket_tx , socket_rx ) = socket . split ( ) ;
let mut socket_rx =
socket_rx . map ( | msg | msg . unwrap ( ) . to_string ( ) ) . filter ( | msg | {
let pass = ! msg . starts_with ( r # "{"method":"Debugger.scriptParsed","# ) ;
futures ::future ::ready ( pass )
} ) ;
let stdin = child . stdin . take ( ) . unwrap ( ) ;
let stdout = child . stdout . as_mut ( ) . unwrap ( ) ;
let mut stdout_lines = std ::io ::BufReader ::new ( stdout )
. lines ( )
. map ( | r | r . unwrap ( ) )
. filter ( | s | ! s . starts_with ( " Deno " ) ) ;
use TestStep ::* ;
let test_steps = vec! [
WsSend ( r # "{"id":1,"method":"Runtime.enable"}"# ) ,
WsSend ( r # "{"id":2,"method":"Debugger.enable"}"# ) ,
WsRecv (
r # "{"method":"Runtime.executionContextCreated","params":{"context":{"id":1,"# ,
) ,
WsRecv ( r # "{"id":1,"result":{}}"# ) ,
WsRecv ( r # "{"id":2,"result":{"debuggerId":"# ) ,
WsSend ( r # "{"id":3,"method":"Runtime.runIfWaitingForDebugger"}"# ) ,
WsRecv ( r # "{"id":3,"result":{}}"# ) ,
StdOut ( " exit using ctrl+d or close() " ) ,
WsSend (
r # "{"id":4,"method":"Runtime.compileScript","params":{"expression":"Deno.cwd()","sourceURL":"","persistScript":false,"executionContextId":1}}"# ,
) ,
WsRecv ( r # "{"id":4,"result":{}}"# ) ,
WsSend (
r # "{"id":5,"method":"Runtime.evaluate","params":{"expression":"Deno.cwd()","objectGroup":"console","includeCommandLineAPI":true,"silent":false,"contextId":1,"returnByValue":true,"generatePreview":true,"userGesture":true,"awaitPromise":false,"replMode":true}}"# ,
) ,
WsRecv ( r # "{"id":5,"result":{"result":{"type":"string","value":""# ) ,
WsSend (
r # "{"id":6,"method":"Runtime.evaluate","params":{"expression":"console.error('done');","objectGroup":"console","includeCommandLineAPI":true,"silent":false,"contextId":1,"returnByValue":true,"generatePreview":true,"userGesture":true,"awaitPromise":false,"replMode":true}}"# ,
) ,
WsRecv ( r # "{"id":6,"result":{"result":{"type":"undefined"}}}"# ) ,
StdErr ( " done " ) ,
] ;
for step in test_steps {
match step {
StdOut ( s ) = > assert_eq! ( & stdout_lines . next ( ) . unwrap ( ) , s ) ,
StdErr ( s ) = > assert_eq! ( & stderr_lines . next ( ) . unwrap ( ) , s ) ,
WsRecv ( s ) = > assert! ( socket_rx . next ( ) . await . unwrap ( ) . starts_with ( s ) ) ,
WsSend ( s ) = > socket_tx . send ( s . into ( ) ) . await . unwrap ( ) ,
}
}
2020-08-10 17:31:05 -04:00
drop ( stdin ) ;
2020-05-24 16:28:19 -04:00
child . wait ( ) . unwrap ( ) ;
2020-05-21 14:34:25 -04:00
}
2020-05-06 15:51:33 -04:00
#[ test ]
fn exec_path ( ) {
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( " --allow-read " )
. arg ( " cli/tests/exec_path.ts " )
. stdout ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( )
. wait_with_output ( )
. unwrap ( ) ;
assert! ( output . status . success ( ) ) ;
let stdout_str = std ::str ::from_utf8 ( & output . stdout ) . unwrap ( ) . trim ( ) ;
let actual =
std ::fs ::canonicalize ( & std ::path ::Path ::new ( stdout_str ) ) . unwrap ( ) ;
2020-05-11 17:33:36 -04:00
let expected = std ::fs ::canonicalize ( util ::deno_exe_path ( ) ) . unwrap ( ) ;
2020-05-06 15:51:33 -04:00
assert_eq! ( expected , actual ) ;
}
2020-07-06 18:26:34 -04:00
#[ cfg(not(windows)) ]
#[ test ]
fn set_raw_should_not_panic_on_no_tty ( ) {
let output = util ::deno_cmd ( )
. arg ( " eval " )
. arg ( " --unstable " )
. arg ( " Deno.setRaw(Deno.stdin.rid, true) " )
// stdin set to piped so it certainly does not refer to TTY
. stdin ( std ::process ::Stdio ::piped ( ) )
// stderr is piped so we can capture output.
. stderr ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( )
. wait_with_output ( )
. unwrap ( ) ;
assert! ( ! output . status . success ( ) ) ;
let stderr = std ::str ::from_utf8 ( & output . stderr ) . unwrap ( ) . trim ( ) ;
assert! ( stderr . contains ( " BadResource " ) ) ;
}
2020-07-09 15:06:51 -04:00
#[ cfg(windows) ]
2020-08-13 20:15:12 -04:00
// Clippy suggests to remove the `NoStd` prefix from all variants. I disagree.
#[ allow(clippy::enum_variant_names) ]
2020-07-09 15:06:51 -04:00
enum WinProcConstraints {
NoStdIn ,
NoStdOut ,
NoStdErr ,
}
#[ cfg(windows) ]
fn run_deno_script_constrained (
script_path : std ::path ::PathBuf ,
constraints : WinProcConstraints ,
) -> Result < ( ) , i64 > {
let file_path = " cli/tests/DenoWinRunner.ps1 " ;
let constraints = match constraints {
WinProcConstraints ::NoStdIn = > " 1 " ,
WinProcConstraints ::NoStdOut = > " 2 " ,
WinProcConstraints ::NoStdErr = > " 4 " ,
} ;
let deno_exe_path = util ::deno_exe_path ( )
. into_os_string ( )
. into_string ( )
. unwrap ( ) ;
let deno_script_path = script_path . into_os_string ( ) . into_string ( ) . unwrap ( ) ;
let args = vec! [ & deno_exe_path [ .. ] , & deno_script_path [ .. ] , constraints ] ;
util ::run_powershell_script_file ( file_path , args )
}
#[ cfg(windows) ]
#[ test ]
fn should_not_panic_on_no_stdin ( ) {
let output = run_deno_script_constrained (
util ::tests_path ( ) . join ( " echo.ts " ) ,
WinProcConstraints ::NoStdIn ,
) ;
output . unwrap ( ) ;
}
#[ cfg(windows) ]
#[ test ]
fn should_not_panic_on_no_stdout ( ) {
let output = run_deno_script_constrained (
util ::tests_path ( ) . join ( " echo.ts " ) ,
WinProcConstraints ::NoStdOut ,
) ;
output . unwrap ( ) ;
}
#[ cfg(windows) ]
#[ test ]
fn should_not_panic_on_no_stderr ( ) {
let output = run_deno_script_constrained (
util ::tests_path ( ) . join ( " echo.ts " ) ,
WinProcConstraints ::NoStdErr ,
) ;
output . unwrap ( ) ;
}
2020-07-13 12:24:54 -04:00
#[ cfg(not(windows)) ]
#[ test ]
fn should_not_panic_on_undefined_home_environment_variable ( ) {
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( " cli/tests/echo.ts " )
. env_remove ( " HOME " )
. stdout ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( )
. wait_with_output ( )
. unwrap ( ) ;
assert! ( output . status . success ( ) ) ;
}
#[ test ]
fn should_not_panic_on_undefined_deno_dir_environment_variable ( ) {
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( " cli/tests/echo.ts " )
. env_remove ( " DENO_DIR " )
. stdout ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( )
. wait_with_output ( )
. unwrap ( ) ;
assert! ( output . status . success ( ) ) ;
}
#[ cfg(not(windows)) ]
#[ test ]
fn should_not_panic_on_undefined_deno_dir_and_home_environment_variables ( ) {
let output = util ::deno_cmd ( )
. current_dir ( util ::root_path ( ) )
. arg ( " run " )
. arg ( " cli/tests/echo.ts " )
. env_remove ( " DENO_DIR " )
. env_remove ( " HOME " )
. stdout ( std ::process ::Stdio ::piped ( ) )
. spawn ( )
. unwrap ( )
. wait_with_output ( )
. unwrap ( ) ;
assert! ( output . status . success ( ) ) ;
}