2023-01-12 20:59:13 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
|
|
|
|
|
|
use test_util as util;
|
|
|
|
use test_util::assert_contains;
|
|
|
|
use test_util::assert_ends_with;
|
|
|
|
use test_util::assert_not_contains;
|
2023-02-01 16:37:05 -05:00
|
|
|
use util::TempDir;
|
2023-04-01 12:02:44 -04:00
|
|
|
use util::TestContext;
|
2023-03-30 10:43:16 -04:00
|
|
|
use util::TestContextBuilder;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pty_multiline() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("(\n1 + 2\n)");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("3");
|
2023-01-12 20:59:13 -05:00
|
|
|
console.write_line("{\nfoo: \"foo\"\n}");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("{ foo: \"foo\" }");
|
2023-01-12 20:59:13 -05:00
|
|
|
console.write_line("`\nfoo\n`");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("\"\\nfoo\\n\"");
|
2023-01-12 20:59:13 -05:00
|
|
|
console.write_line("`\n\\`\n`");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect(r#""\n`\n""#);
|
2023-01-12 20:59:13 -05:00
|
|
|
console.write_line("'{'");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect(r#""{""#);
|
2023-01-12 20:59:13 -05:00
|
|
|
console.write_line("'('");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect(r#""(""#);
|
2023-01-12 20:59:13 -05:00
|
|
|
console.write_line("'['");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect(r#""[""#);
|
2023-01-12 20:59:13 -05:00
|
|
|
console.write_line("/{/");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("/{/");
|
2023-01-12 20:59:13 -05:00
|
|
|
console.write_line("/\\(/");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("/\\(/");
|
2023-01-12 20:59:13 -05:00
|
|
|
console.write_line("/\\[/");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("/\\[/");
|
2023-01-12 20:59:13 -05:00
|
|
|
console.write_line("console.log(\"{test1} abc {test2} def {{test3}}\".match(/{([^{].+?)}/));");
|
2023-04-30 03:24:13 -04:00
|
|
|
console.expect("[");
|
|
|
|
console.expect(" \"{test1}\",");
|
|
|
|
console.expect(" \"test1\",");
|
|
|
|
console.expect(" index: 0,");
|
|
|
|
console.expect(" input: \"{test1} abc {test2} def {{test3}}\",");
|
|
|
|
console.expect(" groups: undefined");
|
|
|
|
console.expect("]");
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pty_null() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("null");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("null");
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pty_unpaired_braces() {
|
|
|
|
for right_brace in &[")", "]", "}"] {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line(right_brace);
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("parse error: Expression expected");
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pty_bad_input() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("'\\u{1f3b5}'[0]");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("Unterminated string literal");
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pty_syntax_error_input() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("('\\u')");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("Bad character escape sequence, expected 4 hex characters");
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
console.write_line("'");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("Unterminated string constant");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-03-28 17:49:00 -04:00
|
|
|
console.write_line("[{'a'}];");
|
|
|
|
console.expect("Expected a semicolon");
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pty_complete_symbol() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
2023-03-28 17:49:00 -04:00
|
|
|
console.write_line_raw("Symbol.it\t");
|
|
|
|
console.expect("Symbol(Symbol.iterator)");
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pty_complete_declarations() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("class MyClass {}");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line_raw("My\t");
|
2023-04-30 03:24:13 -04:00
|
|
|
console.expect("[class MyClass]");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.write_line("let myVar = 2 + 3;");
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line_raw("myV\t");
|
|
|
|
console.expect("5");
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pty_complete_primitives() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("let func = function test(){}");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line_raw("func.appl\t");
|
|
|
|
console.expect("func.apply");
|
2023-01-12 20:59:13 -05:00
|
|
|
console.write_line("let str = ''");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line_raw("str.leng\t");
|
|
|
|
console.expect("str.length");
|
|
|
|
console.write_line_raw("false.valueO\t");
|
|
|
|
console.expect("false.valueOf");
|
|
|
|
console.write_line_raw("5n.valueO\t");
|
|
|
|
console.expect("5n.valueOf");
|
2023-01-12 20:59:13 -05:00
|
|
|
console.write_line("let num = 5");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line_raw("num.toStrin\t");
|
|
|
|
console.expect("num.toString");
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pty_complete_expression() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
2023-03-28 17:49:00 -04:00
|
|
|
console.write_raw("Deno.\t\t");
|
|
|
|
console.expect("Display all");
|
|
|
|
console.write_raw("y");
|
|
|
|
console.expect_all(&["symlink", "args", "permissions", "exit"]);
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pty_complete_imports() {
|
2023-03-30 17:47:53 -04:00
|
|
|
let context = TestContextBuilder::default().use_temp_cwd().build();
|
|
|
|
let temp_dir = context.temp_dir();
|
|
|
|
temp_dir.create_dir_all("subdir");
|
|
|
|
temp_dir.write("./subdir/my_file.ts", "");
|
|
|
|
temp_dir.create_dir_all("run");
|
|
|
|
temp_dir.write("./run/hello.ts", "console.log('Hello World');");
|
|
|
|
temp_dir.write(
|
|
|
|
"./run/output.ts",
|
|
|
|
r#"export function output(text: string) {
|
|
|
|
console.log(text);
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec(["repl", "-A"])
|
|
|
|
.with_pty(|mut console| {
|
|
|
|
// single quotes
|
|
|
|
console.write_line_raw("import './run/hel\t'");
|
|
|
|
console.expect("Hello World");
|
|
|
|
// double quotes
|
|
|
|
console.write_line_raw("import { output } from \"./run/out\t\"");
|
|
|
|
console.expect("\"./run/output.ts\"");
|
|
|
|
console.write_line_raw("output('testing output');");
|
|
|
|
console.expect("testing output");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// ensure when the directory changes that the suggestions come from the cwd
|
2023-03-30 17:47:53 -04:00
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec(["repl", "-A"])
|
|
|
|
.with_pty(|mut console| {
|
|
|
|
console.write_line("Deno.chdir('./subdir');");
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line_raw("import '../run/he\t'");
|
|
|
|
console.expect("Hello World");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pty_complete_imports_no_panic_empty_specifier() {
|
|
|
|
// does not panic when tabbing when empty
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl", "-A"], |mut console| {
|
|
|
|
if cfg!(windows) {
|
|
|
|
console.write_line_raw("import '\t'");
|
|
|
|
console.expect_any(&["not prefixed with", "https://deno.land"]);
|
|
|
|
} else {
|
|
|
|
console.write_raw("import '\t");
|
|
|
|
console.expect("import 'https://deno.land");
|
|
|
|
}
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pty_ignore_symbols() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
2023-03-28 17:49:00 -04:00
|
|
|
console.write_line_raw("Array.Symbol\t");
|
|
|
|
console.expect("undefined");
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pty_assign_global_this() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
2023-03-28 17:49:00 -04:00
|
|
|
console.write_line("globalThis = 40 + 2;");
|
|
|
|
console.expect("42");
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-15 21:41:13 -04:00
|
|
|
#[test]
|
|
|
|
fn pty_assign_deno_keys_and_deno() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line(
|
|
|
|
"Object.keys(Deno).forEach((key)=>{try{Deno[key] = undefined} catch {}})",
|
|
|
|
);
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("undefined");
|
2023-03-15 21:41:13 -04:00
|
|
|
console.write_line("delete globalThis.Deno");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("true");
|
|
|
|
console.write_line("console.log('testing ' + 'this out');");
|
|
|
|
console.expect("testing this out");
|
|
|
|
console.expect("undefined");
|
2023-03-15 21:41:13 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pty_internal_repl() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
2023-03-28 20:25:28 -04:00
|
|
|
console.write_line("'Length: ' + Object.keys(globalThis).filter(k => k.startsWith('__DENO_')).length;");
|
|
|
|
console.expect("Length: 0");
|
2023-03-28 17:49:00 -04:00
|
|
|
|
|
|
|
console.write_line_raw("__\t\t");
|
|
|
|
console.expect("> __");
|
|
|
|
let output = console.read_until("> __");
|
2023-03-15 21:41:13 -04:00
|
|
|
assert_contains!(output, "__defineGetter__");
|
|
|
|
// should not contain the internal repl variable
|
|
|
|
// in the `globalThis` or completions output
|
|
|
|
assert_not_contains!(output, "__DENO_");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
#[test]
|
|
|
|
fn pty_emoji() {
|
|
|
|
// windows was having issues displaying this
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
2023-08-27 00:04:12 -04:00
|
|
|
console.write_line(r"console.log('\u{1F995}');");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("🦕");
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn console_log() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("console.log('hello');");
|
|
|
|
console.expect("hello");
|
|
|
|
console.write_line("'world'");
|
|
|
|
console.expect("\"world\"");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn object_literal() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("{}");
|
|
|
|
console.expect("{}");
|
|
|
|
console.write_line("{ foo: 'bar' }");
|
|
|
|
console.expect("{ foo: \"bar\" }");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn block_expression() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("{};");
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line("{\"\"}");
|
|
|
|
console.expect("\"\"");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn await_resolve() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("await Promise.resolve('done')");
|
|
|
|
console.expect("\"done\"");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn await_timeout() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("await new Promise((r) => setTimeout(r, 0, 'done'))");
|
|
|
|
console.expect("\"done\"");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn let_redeclaration() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("let foo = 0;");
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line("foo");
|
|
|
|
console.expect("0");
|
|
|
|
console.write_line("let foo = 1;");
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line("foo");
|
|
|
|
console.expect("1");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn repl_cwd() {
|
2023-03-30 17:47:53 -04:00
|
|
|
let context = TestContextBuilder::default().use_temp_cwd().build();
|
|
|
|
let temp_dir = context.temp_dir();
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec(["repl", "-A"])
|
|
|
|
.with_pty(|mut console| {
|
|
|
|
console.write_line("Deno.cwd()");
|
2023-06-10 11:09:45 -04:00
|
|
|
console.expect(
|
|
|
|
temp_dir
|
|
|
|
.path()
|
|
|
|
.as_path()
|
|
|
|
.file_name()
|
|
|
|
.unwrap()
|
|
|
|
.to_str()
|
|
|
|
.unwrap(),
|
|
|
|
);
|
2023-03-30 17:47:53 -04:00
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn typescript() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("function add(a: number, b: number) { return a + b }");
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line("const result: number = add(1, 2) as number;");
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line("result");
|
|
|
|
console.expect("3");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn typescript_declarations() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("namespace Test { export enum Values { A, B, C } }");
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line("Test.Values.A");
|
|
|
|
console.expect("0");
|
|
|
|
console.write_line("Test.Values.C");
|
|
|
|
console.expect("2");
|
|
|
|
console.write_line("interface MyInterface { prop: string; }");
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line("type MyTypeAlias = string;");
|
|
|
|
console.expect("undefined");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn typescript_decorators() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console
|
|
|
|
.write_line("function dec(target) { target.prototype.test = () => 2; }");
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line("@dec class Test {}");
|
2023-04-30 03:24:13 -04:00
|
|
|
console.expect("[class Test]");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.write_line("new Test().test()");
|
|
|
|
console.expect("2");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn eof() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("1 + 2");
|
|
|
|
console.expect("3");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn strict() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("let a = {};");
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line("Object.preventExtensions(a)");
|
|
|
|
console.expect("{}");
|
|
|
|
console.write_line("a.c = 1;");
|
|
|
|
console.expect(
|
|
|
|
"Uncaught TypeError: Cannot add property c, object is not extensible",
|
|
|
|
);
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn close_command() {
|
|
|
|
let (out, err) = util::run_and_collect_output(
|
|
|
|
true,
|
|
|
|
"repl",
|
|
|
|
Some(vec!["close()", "'ignored'"]),
|
|
|
|
None,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_not_contains!(out, "ignored");
|
|
|
|
assert!(err.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn function() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("Deno.writeFileSync");
|
|
|
|
console.expect("[Function: writeFileSync]");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn multiline() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("(\n1 + 2\n)");
|
|
|
|
console.expect("3");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn import() {
|
2023-03-30 17:47:53 -04:00
|
|
|
let context = TestContextBuilder::default()
|
|
|
|
.use_copy_temp_dir("./subdir")
|
|
|
|
.build();
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec(["repl", "-A"])
|
|
|
|
.with_pty(|mut console| {
|
|
|
|
console.write_line("import('./subdir/auto_print_hello.ts')");
|
|
|
|
console.expect("hello!");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn import_declarations() {
|
2023-03-30 17:47:53 -04:00
|
|
|
let context = TestContextBuilder::default()
|
|
|
|
.use_copy_temp_dir("./subdir")
|
|
|
|
.build();
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec(["repl", "-A"])
|
|
|
|
.with_pty(|mut console| {
|
|
|
|
console.write_line("import './subdir/auto_print_hello.ts'");
|
|
|
|
console.expect("hello!");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn exports_stripped() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("const test = 5 + 1; export default test;");
|
|
|
|
console.expect("6");
|
|
|
|
console.write_line("export class Test {}");
|
|
|
|
console.expect("undefined");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn call_eval_unterminated() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("eval('{')");
|
|
|
|
console.expect("Unexpected end of input");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unpaired_braces() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
for right_brace in &[")", "]", "}"] {
|
|
|
|
console.write_line(right_brace);
|
|
|
|
console.expect("Expression expected");
|
|
|
|
}
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn reference_error() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("not_a_variable");
|
|
|
|
console.expect("not_a_variable is not defined");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn syntax_error() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("syntax error");
|
|
|
|
console.expect("parse error: Expected ';', '}' or <eof>");
|
|
|
|
// ensure it keeps accepting input after
|
|
|
|
console.write_line("7 * 6");
|
|
|
|
console.expect("42");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2023-11-01 09:42:54 -04:00
|
|
|
fn jsx_errors_without_pragma() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("const element = <div />;");
|
2023-11-01 09:42:54 -04:00
|
|
|
console.expect("React is not defined");
|
2023-03-28 17:49:00 -04:00
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
2023-11-01 19:04:54 -04:00
|
|
|
#[test]
|
|
|
|
fn jsx_import_source() {
|
|
|
|
let context = TestContextBuilder::default()
|
|
|
|
.use_temp_cwd()
|
|
|
|
.use_http_server()
|
|
|
|
.build();
|
|
|
|
context
|
|
|
|
.new_command()
|
|
|
|
.args_vec(["repl", "-A"])
|
|
|
|
.with_pty(|mut console| {
|
|
|
|
console.write_line("/** @jsxImportSource http://localhost:4545/jsx */");
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line("const element = <div />;");
|
|
|
|
console.expect("undefined");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
#[test]
|
|
|
|
fn type_error() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("console()");
|
|
|
|
console.expect("console is not a function");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn variable() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("var a = 123 + 456;");
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line("a");
|
|
|
|
console.expect("579");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn lexical_scoped_variable() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("let a = 123 + 456;");
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line("a");
|
|
|
|
console.expect("579");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn missing_deno_dir() {
|
2023-01-14 23:18:58 -05:00
|
|
|
use std::fs::read_dir;
|
2023-03-07 00:00:51 -05:00
|
|
|
let temp_dir = TempDir::new();
|
|
|
|
let deno_dir_path = temp_dir.path().join("deno");
|
2023-01-12 20:59:13 -05:00
|
|
|
let (out, err) = util::run_and_collect_output(
|
|
|
|
true,
|
|
|
|
"repl",
|
|
|
|
Some(vec!["1"]),
|
|
|
|
Some(vec![
|
2023-06-10 11:09:45 -04:00
|
|
|
("DENO_DIR".to_owned(), deno_dir_path.to_string()),
|
2023-01-12 20:59:13 -05:00
|
|
|
("NO_COLOR".to_owned(), "1".to_owned()),
|
|
|
|
]),
|
|
|
|
false,
|
|
|
|
);
|
2023-03-07 00:00:51 -05:00
|
|
|
assert!(read_dir(deno_dir_path).is_ok());
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_ends_with!(out, "1\n");
|
|
|
|
assert!(err.is_empty());
|
|
|
|
}
|
|
|
|
|
2023-03-16 12:22:24 -04:00
|
|
|
#[test]
|
|
|
|
fn custom_history_path() {
|
|
|
|
use std::fs::read;
|
|
|
|
let temp_dir = TempDir::new();
|
|
|
|
let history_path = temp_dir.path().join("history.txt");
|
|
|
|
let (out, err) = util::run_and_collect_output(
|
|
|
|
true,
|
|
|
|
"repl",
|
|
|
|
Some(vec!["1"]),
|
|
|
|
Some(vec![
|
2023-06-10 11:09:45 -04:00
|
|
|
("DENO_REPL_HISTORY".to_owned(), history_path.to_string()),
|
2023-03-16 12:22:24 -04:00
|
|
|
("NO_COLOR".to_owned(), "1".to_owned()),
|
|
|
|
]),
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
assert!(read(&history_path).is_ok());
|
|
|
|
assert_ends_with!(out, "1\n");
|
|
|
|
assert!(err.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn disable_history_file() {
|
|
|
|
let deno_dir = util::new_deno_dir();
|
|
|
|
let default_history_path = deno_dir.path().join("deno_history.txt");
|
|
|
|
let (out, err) = util::run_and_collect_output(
|
|
|
|
true,
|
|
|
|
"repl",
|
|
|
|
Some(vec!["1"]),
|
|
|
|
Some(vec![
|
2023-06-10 11:09:45 -04:00
|
|
|
("DENO_DIR".to_owned(), deno_dir.path().to_string()),
|
2023-03-16 12:22:24 -04:00
|
|
|
("DENO_REPL_HISTORY".to_owned(), "".to_owned()),
|
|
|
|
("NO_COLOR".to_owned(), "1".to_owned()),
|
|
|
|
]),
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
assert!(!default_history_path.try_exists().unwrap());
|
|
|
|
assert_ends_with!(out, "1\n");
|
|
|
|
assert!(err.is_empty());
|
|
|
|
}
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
#[test]
|
|
|
|
fn save_last_eval() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("1 + 2");
|
|
|
|
console.expect("3");
|
|
|
|
console.write_line("_ + 3");
|
|
|
|
console.expect("6");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn save_last_thrown() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("throw 1 + 2");
|
|
|
|
console.expect("Uncaught 3");
|
|
|
|
console.write_line("_error + 3");
|
|
|
|
console.expect("6");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn assign_underscore() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("_ = 1");
|
|
|
|
console.expect("Last evaluation result is no longer saved to _.");
|
|
|
|
console.write_line("2 + 3");
|
|
|
|
console.expect("5");
|
|
|
|
console.write_line("_");
|
|
|
|
console.expect("1");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn assign_underscore_error() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("_error = 1");
|
|
|
|
console.expect("Last thrown error is no longer saved to _error.");
|
|
|
|
console.write_line("throw 2");
|
|
|
|
console.expect("Uncaught 2");
|
|
|
|
console.write_line("_error");
|
|
|
|
console.expect("1");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn custom_inspect() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line(
|
2023-01-12 20:59:13 -05:00
|
|
|
r#"const o = {
|
2023-03-28 17:49:00 -04:00
|
|
|
[Symbol.for("Deno.customInspect")]() {
|
|
|
|
throw new Error('Oops custom inspect error');
|
|
|
|
},
|
|
|
|
};"#,
|
|
|
|
);
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line("o");
|
|
|
|
console.expect("Oops custom inspect error");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn eval_flag_valid_input() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl", "--eval", "const t = 10;"], |mut console| {
|
|
|
|
console.write_line("t * 500");
|
|
|
|
console.expect("5000");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn eval_flag_parse_error() {
|
|
|
|
let (out, err) = util::run_and_collect_output_with_args(
|
|
|
|
true,
|
|
|
|
vec!["repl", "--eval", "const %"],
|
|
|
|
Some(vec!["250 * 10"]),
|
|
|
|
None,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
assert_contains!(
|
|
|
|
test_util::strip_ansi_codes(&out),
|
|
|
|
"Error in --eval flag: parse error: Unexpected token `%`."
|
|
|
|
);
|
|
|
|
assert_contains!(out, "2500"); // should not prevent input
|
|
|
|
assert!(err.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn eval_flag_runtime_error() {
|
|
|
|
let (out, err) = util::run_and_collect_output_with_args(
|
|
|
|
true,
|
|
|
|
vec!["repl", "--eval", "throw new Error('Testing')"],
|
|
|
|
Some(vec!["250 * 10"]),
|
|
|
|
None,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
assert_contains!(out, "Error in --eval flag: Uncaught Error: Testing");
|
|
|
|
assert_contains!(out, "2500"); // should not prevent input
|
|
|
|
assert!(err.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn eval_file_flag_valid_input() {
|
|
|
|
let (out, err) = util::run_and_collect_output_with_args(
|
|
|
|
true,
|
|
|
|
vec!["repl", "--eval-file=./run/001_hello.js"],
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
assert_contains!(out, "Hello World");
|
|
|
|
assert!(err.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn eval_file_flag_call_defined_function() {
|
|
|
|
let (out, err) = util::run_and_collect_output_with_args(
|
|
|
|
true,
|
|
|
|
vec!["repl", "--eval-file=./tsc/d.ts"],
|
|
|
|
Some(vec!["v4()"]),
|
|
|
|
None,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
assert_contains!(out, "hello");
|
|
|
|
assert!(err.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn eval_file_flag_http_input() {
|
|
|
|
let (out, err) = util::run_and_collect_output_with_args(
|
|
|
|
true,
|
|
|
|
vec!["repl", "--eval-file=http://127.0.0.1:4545/tsc/d.ts"],
|
|
|
|
Some(vec!["v4()"]),
|
|
|
|
None,
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
assert_contains!(out, "hello");
|
|
|
|
assert!(err.contains("Download"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn eval_file_flag_multiple_files() {
|
|
|
|
let (out, err) = util::run_and_collect_output_with_args(
|
|
|
|
true,
|
|
|
|
vec!["repl", "--allow-read", "--eval-file=http://127.0.0.1:4545/repl/import_type.ts,./tsc/d.ts,http://127.0.0.1:4545/type_definitions/foo.js"],
|
|
|
|
Some(vec!["b.method1=v4", "b.method1()+foo.toUpperCase()"]),
|
|
|
|
None,
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
assert_contains!(out, "helloFOO");
|
|
|
|
assert_contains!(err, "Download");
|
|
|
|
}
|
|
|
|
|
2023-06-13 09:36:21 -04:00
|
|
|
#[flaky_test::flaky_test]
|
2023-01-12 20:59:13 -05:00
|
|
|
fn pty_clear_function() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
2023-03-28 17:49:00 -04:00
|
|
|
console.write_line("console.log('h' + 'ello');");
|
|
|
|
console.expect_all(&["hello", "undefined"]);
|
|
|
|
console.write_line_raw("clear();");
|
2023-01-12 20:59:13 -05:00
|
|
|
if cfg!(windows) {
|
2023-03-28 17:49:00 -04:00
|
|
|
// expect a bunch of these in the output
|
|
|
|
console.expect_raw_in_current_output(
|
|
|
|
"\r\n\u{1b}[K\r\n\u{1b}[K\r\n\u{1b}[K\r\n\u{1b}[K\r\n\u{1b}[K",
|
|
|
|
);
|
2023-01-12 20:59:13 -05:00
|
|
|
} else {
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect_raw_in_current_output("[1;1H");
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("undefined"); // advance past the "clear()"'s undefined
|
|
|
|
console.expect("> ");
|
|
|
|
console.write_line("const clear = 1234 + 2000;");
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line("clear;");
|
|
|
|
console.expect("3234");
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pty_tab_handler() {
|
|
|
|
// If the last character is **not** whitespace, we show the completions
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
2023-03-28 17:49:00 -04:00
|
|
|
console.write_raw("a\t\t");
|
|
|
|
console.expect_all(&["addEventListener", "alert", "atob"]);
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
// If the last character is whitespace, we just insert a tab
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
2023-03-28 17:49:00 -04:00
|
|
|
console.write_line("const a = 5;");
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_raw("a; \t\ta + 2;\n"); // last character is whitespace
|
|
|
|
console.expect_any(&[
|
|
|
|
// windows
|
|
|
|
"a; a + 2;",
|
|
|
|
// unix
|
|
|
|
"a; \t\ta + 2;",
|
|
|
|
]);
|
2023-01-12 20:59:13 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-27 17:36:49 -04:00
|
|
|
#[test]
|
|
|
|
fn repl_error() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("console.log(1);");
|
|
|
|
console.expect_all(&["1", "undefined"]);
|
|
|
|
console.write_line(r#"throw new Error("foo");"#);
|
|
|
|
console.expect("Uncaught Error: foo");
|
|
|
|
console.expect(" at <anonymous>");
|
|
|
|
console.write_line("console.log(2);");
|
|
|
|
console.expect("2");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-13 09:36:21 -04:00
|
|
|
#[flaky_test::flaky_test]
|
2023-04-27 17:36:49 -04:00
|
|
|
fn repl_reject() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("console.log(1);");
|
|
|
|
console.expect_all(&["1", "undefined"]);
|
|
|
|
console.write_line(r#"Promise.reject(new Error("foo"));"#);
|
2023-04-30 03:24:13 -04:00
|
|
|
console.expect("Promise {");
|
|
|
|
console.expect(" <rejected> Error: foo");
|
2023-12-06 19:02:52 -05:00
|
|
|
console.expect("Uncaught Error: foo");
|
2023-04-27 17:36:49 -04:00
|
|
|
console.expect(" at <anonymous>");
|
|
|
|
console.write_line("console.log(2);");
|
|
|
|
console.expect("2");
|
2023-06-06 17:06:30 -04:00
|
|
|
console.write_line(r#"throw "hello";"#);
|
|
|
|
console.expect(r#"Uncaught "hello""#);
|
|
|
|
console.write_line(r#"throw `hello ${"world"}`;"#);
|
|
|
|
console.expect(r#"Uncaught "hello world""#);
|
2023-04-27 17:36:49 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-13 09:36:21 -04:00
|
|
|
#[flaky_test::flaky_test]
|
2023-01-12 20:59:13 -05:00
|
|
|
fn repl_report_error() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("console.log(1);");
|
|
|
|
console.expect_all(&["1", "undefined"]);
|
|
|
|
console.write_line(r#"reportError(new Error("foo"));"#);
|
|
|
|
console.expect("undefined");
|
2023-04-27 17:36:49 -04:00
|
|
|
console.expect("Uncaught Error: foo");
|
|
|
|
console.expect(" at <anonymous>");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.write_line("console.log(2);");
|
|
|
|
console.expect("2");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
2023-06-13 09:36:21 -04:00
|
|
|
#[flaky_test::flaky_test]
|
2023-04-28 09:21:55 -04:00
|
|
|
fn repl_error_undefined() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line(r#"throw undefined;"#);
|
|
|
|
console.expect("Uncaught undefined");
|
|
|
|
console.write_line(r#"Promise.reject();"#);
|
|
|
|
console.expect("Promise { <rejected> undefined }");
|
2023-12-06 19:02:52 -05:00
|
|
|
console.expect("Uncaught undefined");
|
2023-04-28 09:21:55 -04:00
|
|
|
console.write_line(r#"reportError(undefined);"#);
|
|
|
|
console.expect("undefined");
|
|
|
|
console.expect("Uncaught undefined");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
#[test]
|
|
|
|
fn pty_aggregate_error() {
|
2023-03-28 17:49:00 -04:00
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("await Promise.any([])");
|
|
|
|
console.expect("AggregateError");
|
|
|
|
});
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn repl_with_quiet_flag() {
|
|
|
|
let (out, err) = util::run_and_collect_output_with_args(
|
|
|
|
true,
|
|
|
|
vec!["repl", "--quiet"],
|
|
|
|
Some(vec!["await Promise.resolve('done')"]),
|
|
|
|
Some(vec![("NO_COLOR".to_owned(), "1".to_owned())]),
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
assert!(!out.contains("Deno"));
|
|
|
|
assert!(!out.contains("exit using ctrl+d, ctrl+c, or close()"));
|
|
|
|
assert_ends_with!(out, "\"done\"\n");
|
|
|
|
assert!(err.is_empty());
|
|
|
|
}
|
|
|
|
|
2023-10-05 16:45:11 -04:00
|
|
|
#[test]
|
|
|
|
fn repl_unit_tests() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
2023-11-17 22:46:15 -05:00
|
|
|
console.write_line_raw(
|
2023-10-05 16:45:11 -04:00
|
|
|
"\
|
|
|
|
console.log('Hello from outside of test!'); \
|
|
|
|
Deno.test('test1', async (t) => { \
|
|
|
|
console.log('Hello from inside of test!'); \
|
|
|
|
await t.step('step1', () => {}); \
|
|
|
|
}); \
|
|
|
|
Deno.test('test2', () => { \
|
|
|
|
throw new Error('some message'); \
|
|
|
|
}); \
|
|
|
|
console.log('Hello again from outside of test!'); \
|
|
|
|
",
|
|
|
|
);
|
|
|
|
|
|
|
|
console.expect("Hello from outside of test!");
|
|
|
|
console.expect("Hello again from outside of test!");
|
|
|
|
// FIXME(nayeemrmn): REPL unit tests don't support output capturing.
|
|
|
|
console.expect("Hello from inside of test!");
|
|
|
|
console.expect("test1 ...");
|
|
|
|
console.expect(" step1 ... ok (");
|
|
|
|
console.expect("test1 ... ok (");
|
|
|
|
console.expect("test2 ... FAILED (");
|
2023-11-17 22:46:15 -05:00
|
|
|
console.expect("ERRORS");
|
2023-11-01 09:42:54 -04:00
|
|
|
console.expect("test2 => <anonymous>:6:6");
|
2023-10-05 16:45:11 -04:00
|
|
|
console.expect("error: Error: some message");
|
2023-11-01 09:42:54 -04:00
|
|
|
console.expect(" at <anonymous>:7:9");
|
2023-11-17 22:46:15 -05:00
|
|
|
console.expect("FAILURES");
|
2023-11-01 09:42:54 -04:00
|
|
|
console.expect("test2 => <anonymous>:6:6");
|
2023-10-05 16:45:11 -04:00
|
|
|
console.expect("FAILED | 1 passed (1 step) | 1 failed (");
|
|
|
|
console.expect("undefined");
|
|
|
|
|
|
|
|
console.write_line("Deno.test('test2', () => {});");
|
|
|
|
|
|
|
|
console.expect("test2 ... ok (");
|
|
|
|
console.expect("ok | 1 passed | 0 failed (");
|
|
|
|
console.expect("undefined");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
#[test]
|
|
|
|
fn npm_packages() {
|
|
|
|
let mut env_vars = util::env_vars_for_npm_tests();
|
|
|
|
env_vars.push(("NO_COLOR".to_owned(), "1".to_owned()));
|
2023-02-01 16:37:05 -05:00
|
|
|
let temp_dir = TempDir::new();
|
2023-06-10 11:09:45 -04:00
|
|
|
env_vars.push(("DENO_DIR".to_string(), temp_dir.path().to_string()));
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
let (out, err) = util::run_and_collect_output_with_args(
|
|
|
|
true,
|
|
|
|
vec!["repl", "--quiet", "--allow-read", "--allow-env"],
|
|
|
|
Some(vec![
|
|
|
|
r#"import chalk from "npm:chalk";"#,
|
|
|
|
"chalk.red('hel' + 'lo')",
|
|
|
|
]),
|
|
|
|
Some(env_vars.clone()),
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_contains!(out, "hello");
|
|
|
|
assert!(err.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
let (out, err) = util::run_and_collect_output_with_args(
|
|
|
|
true,
|
|
|
|
vec!["repl", "--quiet", "--allow-read", "--allow-env"],
|
|
|
|
Some(vec![
|
|
|
|
r#"const chalk = await import("npm:chalk");"#,
|
|
|
|
"chalk.default.red('hel' + 'lo')",
|
|
|
|
]),
|
|
|
|
Some(env_vars.clone()),
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_contains!(out, "hello");
|
|
|
|
assert!(err.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
let (out, err) = util::run_and_collect_output_with_args(
|
|
|
|
true,
|
|
|
|
vec!["repl", "--quiet", "--allow-read", "--allow-env"],
|
|
|
|
Some(vec![r#"export {} from "npm:chalk";"#]),
|
|
|
|
Some(env_vars.clone()),
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
|
2023-04-30 03:24:13 -04:00
|
|
|
assert_contains!(out, "[Module: null prototype] {");
|
|
|
|
assert_contains!(out, "Chalk: [class Chalk],");
|
2023-01-12 20:59:13 -05:00
|
|
|
assert!(err.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
let (out, err) = util::run_and_collect_output_with_args(
|
|
|
|
true,
|
|
|
|
vec!["repl", "--quiet", "--allow-read", "--allow-env"],
|
|
|
|
Some(vec![r#"import foo from "npm:asdfawe52345asdf""#]),
|
2023-02-01 16:37:05 -05:00
|
|
|
Some(env_vars.clone()),
|
2023-01-12 20:59:13 -05:00
|
|
|
true,
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_contains!(
|
|
|
|
out,
|
|
|
|
"error: npm package 'asdfawe52345asdf' does not exist"
|
|
|
|
);
|
|
|
|
assert!(err.is_empty());
|
|
|
|
}
|
2023-02-01 16:37:05 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
let (out, err) = util::run_and_collect_output_with_args(
|
|
|
|
true,
|
|
|
|
vec!["repl", "--quiet", "--allow-read", "--allow-env"],
|
|
|
|
Some(vec![
|
|
|
|
"import path from 'node:path';",
|
|
|
|
"path.isGlob('asdf') ? 'yes' : 'no'",
|
|
|
|
]),
|
|
|
|
Some(env_vars.clone()),
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_contains!(out, "no");
|
|
|
|
assert!(err.is_empty());
|
|
|
|
}
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
2023-03-16 15:46:50 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pty_tab_indexable_props() {
|
|
|
|
util::with_pty(&["repl"], |mut console| {
|
|
|
|
console.write_line("const arr = [1, 2, 3]");
|
2023-03-28 17:49:00 -04:00
|
|
|
console.expect("undefined");
|
|
|
|
console.write_raw("arr.\t\t");
|
|
|
|
console.expect("> arr.");
|
|
|
|
let output = console.read_until("> arr.");
|
2023-03-16 15:46:50 -04:00
|
|
|
assert_contains!(output, "constructor");
|
|
|
|
assert_contains!(output, "sort");
|
|
|
|
assert_contains!(output, "at");
|
|
|
|
assert_not_contains!(output, "0", "1", "2");
|
|
|
|
});
|
|
|
|
}
|
2023-03-30 10:43:16 -04:00
|
|
|
|
2023-06-13 09:36:21 -04:00
|
|
|
#[flaky_test::flaky_test]
|
2023-03-30 10:43:16 -04:00
|
|
|
fn package_json_uncached_no_error() {
|
|
|
|
let test_context = TestContextBuilder::for_npm()
|
|
|
|
.use_temp_cwd()
|
|
|
|
.use_http_server()
|
|
|
|
.env("RUST_BACKTRACE", "1")
|
|
|
|
.build();
|
|
|
|
let temp_dir = test_context.temp_dir();
|
|
|
|
temp_dir.write(
|
|
|
|
"package.json",
|
|
|
|
r#"{
|
|
|
|
"dependencies": {
|
|
|
|
"@denotest/esm-basic": "1.0.0"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
test_context.new_command().with_pty(|mut console| {
|
|
|
|
console.write_line("console.log(123 + 456);");
|
2023-03-30 12:15:21 -04:00
|
|
|
console.expect_all(&["579", "undefined"]);
|
2023-03-30 10:43:16 -04:00
|
|
|
assert_not_contains!(
|
|
|
|
console.all_output(),
|
|
|
|
"Could not set npm package requirements",
|
|
|
|
);
|
|
|
|
|
|
|
|
// should support getting the package now though
|
|
|
|
console
|
|
|
|
.write_line("import { getValue, setValue } from '@denotest/esm-basic';");
|
2023-11-17 22:46:15 -05:00
|
|
|
console.expect_all(&["undefined", "Download"]);
|
2023-03-30 10:43:16 -04:00
|
|
|
console.write_line("setValue(12 + 30);");
|
|
|
|
console.expect("undefined");
|
|
|
|
console.write_line("getValue()");
|
2023-11-17 22:46:15 -05:00
|
|
|
console.expect("42");
|
|
|
|
|
|
|
|
assert!(temp_dir.path().join("node_modules").exists());
|
2023-03-30 10:43:16 -04:00
|
|
|
});
|
|
|
|
}
|
2023-04-01 12:02:44 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn closed_file_pre_load_does_not_occur() {
|
|
|
|
TestContext::default()
|
|
|
|
.new_command()
|
|
|
|
.args_vec(["repl", "-A", "--log-level=debug"])
|
|
|
|
.with_pty(|console| {
|
2023-05-11 17:17:14 -04:00
|
|
|
assert_contains!(console.all_output(), "Skipping document preload.",);
|
2023-04-01 12:02:44 -04:00
|
|
|
});
|
|
|
|
}
|
2023-11-01 11:21:13 -04:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn env_file() {
|
|
|
|
TestContext::default()
|
|
|
|
.new_command()
|
|
|
|
.args_vec([
|
|
|
|
"repl",
|
|
|
|
"--env=env",
|
|
|
|
"--allow-env",
|
|
|
|
"--eval",
|
|
|
|
"console.log(Deno.env.get('FOO'))",
|
|
|
|
])
|
|
|
|
.with_pty(|console| {
|
|
|
|
assert_contains!(console.all_output(), "BAR",);
|
|
|
|
});
|
|
|
|
}
|
2023-11-21 21:45:34 -05:00
|
|
|
|
|
|
|
// Regression test for https://github.com/denoland/deno/issues/20528
|
|
|
|
#[test]
|
|
|
|
fn pty_promise_was_collected_regression_test() {
|
|
|
|
let (out, err) = util::run_and_collect_output_with_args(
|
|
|
|
true,
|
|
|
|
vec!["repl"],
|
|
|
|
Some(vec!["new Uint8Array(64 * 1024 * 1024)"]),
|
|
|
|
None,
|
|
|
|
false,
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_contains!(out, "Uint8Array(67108864)");
|
|
|
|
assert!(err.is_empty());
|
|
|
|
}
|