summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/compile_tests.rs10
-rw-r--r--cli/tests/integration/worker_tests.rs6
-rw-r--r--cli/tests/testdata/workers/error_event.ts11
-rw-r--r--cli/tests/testdata/workers/error_event.ts.out13
4 files changed, 38 insertions, 2 deletions
diff --git a/cli/tests/integration/compile_tests.rs b/cli/tests/integration/compile_tests.rs
index 3d2a17ecc..4e45adc07 100644
--- a/cli/tests/integration/compile_tests.rs
+++ b/cli/tests/integration/compile_tests.rs
@@ -105,9 +105,12 @@ fn standalone_error() {
assert!(!output.status.success());
assert_eq!(output.stdout, b"");
let stderr = String::from_utf8(output.stderr).unwrap();
+ let stderr = util::strip_ansi_codes(&stderr).to_string();
// On Windows, we cannot assert the file path (because '\').
// Instead we just check for relevant output.
- assert!(stderr.contains("error: Error: boom!\n at boom (file://"));
+ assert!(stderr.contains("error: Uncaught Error: boom!"));
+ assert!(stderr.contains("throw new Error(\"boom!\");"));
+ assert!(stderr.contains("\n at boom (file://"));
assert!(stderr.contains("standalone_error.ts:2:11"));
assert!(stderr.contains("at foo (file://"));
assert!(stderr.contains("standalone_error.ts:5:5"));
@@ -148,9 +151,12 @@ fn standalone_error_module_with_imports() {
println!("{:#?}", &output);
assert_eq!(output.stdout, b"hello\n");
let stderr = String::from_utf8(output.stderr).unwrap();
+ let stderr = util::strip_ansi_codes(&stderr).to_string();
// On Windows, we cannot assert the file path (because '\').
// Instead we just check for relevant output.
- assert!(stderr.contains("error: Error: boom!\n at file://"));
+ assert!(stderr.contains("error: Uncaught Error: boom!"));
+ assert!(stderr.contains("throw new Error(\"boom!\");"));
+ assert!(stderr.contains("\n at file://"));
assert!(stderr.contains("standalone_error_module_with_imports_2.ts:2:7"));
}
diff --git a/cli/tests/integration/worker_tests.rs b/cli/tests/integration/worker_tests.rs
index 57faaa6d3..63d5ccbd3 100644
--- a/cli/tests/integration/worker_tests.rs
+++ b/cli/tests/integration/worker_tests.rs
@@ -104,3 +104,9 @@ itest!(worker_terminate_tla_crash {
args: "run --quiet --reload workers/terminate_tla_crash.js",
output: "workers/terminate_tla_crash.js.out",
});
+
+itest!(worker_error_event {
+ args: "run --quiet -A workers/error_event.ts",
+ output: "workers/error_event.ts.out",
+ exit_code: 1,
+});
diff --git a/cli/tests/testdata/workers/error_event.ts b/cli/tests/testdata/workers/error_event.ts
new file mode 100644
index 000000000..f3046178a
--- /dev/null
+++ b/cli/tests/testdata/workers/error_event.ts
@@ -0,0 +1,11 @@
+const worker = new Worker(new URL("error.ts", import.meta.url).href, {
+ type: "module",
+});
+worker.addEventListener("error", (e) => {
+ console.log({
+ "message": e.message,
+ "filename": e.filename?.slice?.(-100),
+ "lineno": e.lineno,
+ "colno": e.colno,
+ });
+});
diff --git a/cli/tests/testdata/workers/error_event.ts.out b/cli/tests/testdata/workers/error_event.ts.out
new file mode 100644
index 000000000..9c075e23e
--- /dev/null
+++ b/cli/tests/testdata/workers/error_event.ts.out
@@ -0,0 +1,13 @@
+error: Uncaught (in worker "") Error: foo
+ throw new Error("foo");
+ ^
+ at foo ([WILDCARD]/error.ts:2:9)
+ at [WILDCARD]/error.ts:5:1
+{
+ message: "Uncaught Error: foo",
+ filename: "[WILDCARD]/error.ts",
+ lineno: 2,
+ colno: 9
+}
+error: Uncaught (in promise) Error: Unhandled error in child worker.
+ at [WILDCARD]