mirror of
https://github.com/denoland/deno.git
synced 2025-09-29 13:44:47 +00:00
feat(ext/web): add globalThis.reportError() (#13799)
This commit is contained in:
parent
a64e63c361
commit
c30d95f2e3
10 changed files with 93 additions and 17 deletions
|
@ -2753,3 +2753,14 @@ fn deno_no_prompt_environment_variable() {
|
|||
.unwrap();
|
||||
assert!(output.status.success());
|
||||
}
|
||||
|
||||
itest!(report_error {
|
||||
args: "run --quiet report_error.ts",
|
||||
output: "report_error.ts.out",
|
||||
exit_code: 1,
|
||||
});
|
||||
|
||||
itest!(report_error_handled {
|
||||
args: "run --quiet report_error_handled.ts",
|
||||
output: "report_error_handled.ts.out",
|
||||
});
|
||||
|
|
3
cli/tests/testdata/report_error.ts
vendored
Normal file
3
cli/tests/testdata/report_error.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
console.log(1);
|
||||
reportError(new Error("foo"));
|
||||
console.log(2);
|
5
cli/tests/testdata/report_error.ts.out
vendored
Normal file
5
cli/tests/testdata/report_error.ts.out
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
1
|
||||
error: Uncaught Error: foo
|
||||
reportError(new Error("foo"));
|
||||
^
|
||||
at [WILDCARD]/report_error.ts:2:13
|
19
cli/tests/testdata/report_error_handled.ts
vendored
Normal file
19
cli/tests/testdata/report_error_handled.ts
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
addEventListener("error", (event) => {
|
||||
console.log({
|
||||
cancelable: event.cancelable,
|
||||
message: event.message,
|
||||
filename: event.filename,
|
||||
lineno: event.lineno,
|
||||
colno: event.colno,
|
||||
error: event.error,
|
||||
});
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
onerror = (event) => {
|
||||
console.log("onerror() called", event.error);
|
||||
};
|
||||
|
||||
console.log(1);
|
||||
reportError(new Error("foo"));
|
||||
console.log(2);
|
13
cli/tests/testdata/report_error_handled.ts.out
vendored
Normal file
13
cli/tests/testdata/report_error_handled.ts.out
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
1
|
||||
{
|
||||
cancelable: true,
|
||||
message: "Uncaught Error: foo",
|
||||
filename: "[WILDCARD]/report_error_handled.ts",
|
||||
lineno: 18,
|
||||
colno: 13,
|
||||
error: Error: foo
|
||||
at [WILDCARD]/report_error_handled.ts:18:13
|
||||
}
|
||||
onerror() called Error: foo
|
||||
at [WILDCARD]/report_error_handled.ts:18:13
|
||||
2
|
Loading…
Add table
Add a link
Reference in a new issue