diff options
author | Colin Ihrig <cjihrig@gmail.com> | 2022-06-28 10:49:30 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-28 10:49:30 -0400 |
commit | 0f6a5c5fc24e8dc9125c5c536c8547a86ca87b15 (patch) | |
tree | 41538ee1df06dc80d60e49ed50177f99ba8dc297 /cli/tests | |
parent | ab11b45d1d2678cfea2217ac72fc24317eef777d (diff) |
feat(web): add beforeunload event (#14830)
This commit adds the 'beforeunload' event.
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/integration/run_tests.rs | 6 | ||||
-rw-r--r-- | cli/tests/testdata/before_unload.js | 21 | ||||
-rw-r--r-- | cli/tests/testdata/before_unload.js.out | 8 |
3 files changed, 35 insertions, 0 deletions
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index bd27cd8dd..1cd1db0ef 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -249,6 +249,12 @@ itest!(webstorage_serialization { output: "webstorage/serialization.ts.out", }); +// tests the beforeunload event +itest!(beforeunload_event { + args: "run before_unload.js", + output: "before_unload.js.out", +}); + // tests to ensure that when `--location` is set, all code shares the same // localStorage cache based on the origin of the location URL. #[test] diff --git a/cli/tests/testdata/before_unload.js b/cli/tests/testdata/before_unload.js new file mode 100644 index 000000000..2572e512b --- /dev/null +++ b/cli/tests/testdata/before_unload.js @@ -0,0 +1,21 @@ +let count = 0; + +console.log("0"); + +globalThis.addEventListener("beforeunload", (e) => { + console.log("GOT EVENT"); + if (count === 0 || count === 1) { + e.preventDefault(); + setTimeout(() => { + console.log("3"); + }, 100); + } + + count++; +}); + +console.log("1"); + +setTimeout(() => { + console.log("2"); +}, 100); diff --git a/cli/tests/testdata/before_unload.js.out b/cli/tests/testdata/before_unload.js.out new file mode 100644 index 000000000..f1f2ab49a --- /dev/null +++ b/cli/tests/testdata/before_unload.js.out @@ -0,0 +1,8 @@ +0 +1 +2 +GOT EVENT +3 +GOT EVENT +3 +GOT EVENT |