mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
test: replace usage of window
with globalThis
(#25284)
Fixes several tests blocking https://github.com/denoland/deno/pull/25213 by replacing `window` global that is gone in Deno 2 with `globalThis`. Also adjusted a few tests using deprecated `rid` field.
This commit is contained in:
parent
3afa3db4d3
commit
57541b48ba
15 changed files with 26 additions and 34 deletions
|
@ -1,3 +1,2 @@
|
|||
[WILDCARD]
|
||||
[Module: null prototype] { default: { a: "b", c: { d: 10 } } }
|
||||
[Module: null prototype] { default: { a: "b", c: { d: 10 } } }
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
const data1 = await import("./data.json", { with: { type: "json" } });
|
||||
// deno-lint-ignore no-import-assertions
|
||||
const data2 = await import("./data.json", { assert: { type: "json" } });
|
||||
|
||||
console.log(data1);
|
||||
console.log(data2);
|
||||
|
|
2
tests/testdata/run/025_hrtime.ts
vendored
2
tests/testdata/run/025_hrtime.ts
vendored
|
@ -1,4 +1,4 @@
|
|||
window.onload = async () => {
|
||||
globalThis.onload = async () => {
|
||||
console.log(performance.now() % 2 !== 0);
|
||||
await Deno.permissions.revoke({ name: "hrtime" });
|
||||
console.log(performance.now() % 2 === 0);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// deno-lint-ignore-file
|
||||
// There was a bug where if this was executed with --reload it would throw a
|
||||
// type error.
|
||||
window.test = null;
|
||||
globalThis.test = null;
|
||||
test = console;
|
||||
test.log("hello");
|
||||
|
|
|
@ -9,7 +9,7 @@ setTimeout(() => {
|
|||
Promise.resolve().then(() => {
|
||||
console.log("promise 1");
|
||||
});
|
||||
window.close();
|
||||
globalThis.close();
|
||||
console.log("sync 2");
|
||||
setTimeout(() => {
|
||||
console.log("setTimeout 2");
|
||||
|
|
2
tests/testdata/run/078_unload_on_exit.ts
vendored
2
tests/testdata/run/078_unload_on_exit.ts
vendored
|
@ -1,4 +1,4 @@
|
|||
window.onunload = () => {
|
||||
globalThis.onunload = () => {
|
||||
console.log("onunload is called");
|
||||
// This second exit call doesn't trigger unload event,
|
||||
// and therefore actually stops the process.
|
||||
|
|
7
tests/testdata/run/onload/imported.ts
vendored
7
tests/testdata/run/onload/imported.ts
vendored
|
@ -1,4 +1,3 @@
|
|||
// deno-lint-ignore-file no-window-prefix
|
||||
import { assert } from "@std/assert";
|
||||
import "./nest_imported.ts";
|
||||
|
||||
|
@ -7,7 +6,7 @@ const handler = (e: Event) => {
|
|||
console.log(`got ${e.type} event in event handler (imported)`);
|
||||
};
|
||||
|
||||
window.addEventListener("load", handler);
|
||||
window.addEventListener("beforeunload", handler);
|
||||
window.addEventListener("unload", handler);
|
||||
globalThis.addEventListener("load", handler);
|
||||
globalThis.addEventListener("beforeunload", handler);
|
||||
globalThis.addEventListener("unload", handler);
|
||||
console.log("log from imported script");
|
||||
|
|
18
tests/testdata/run/onload/main.ts
vendored
18
tests/testdata/run/onload/main.ts
vendored
|
@ -1,32 +1,32 @@
|
|||
// deno-lint-ignore-file no-window-prefix no-prototype-builtins
|
||||
// deno-lint-ignore-file no-prototype-builtins
|
||||
import { assert } from "@std/assert";
|
||||
import "./imported.ts";
|
||||
|
||||
assert(window.hasOwnProperty("onload"));
|
||||
assert(window.onload === null);
|
||||
assert(globalThis.hasOwnProperty("onload"));
|
||||
assert(globalThis.onload === null);
|
||||
|
||||
const eventHandler = (e: Event) => {
|
||||
assert(e.type === "beforeunload" ? e.cancelable : !e.cancelable);
|
||||
console.log(`got ${e.type} event in event handler (main)`);
|
||||
};
|
||||
|
||||
window.addEventListener("load", eventHandler);
|
||||
globalThis.addEventListener("load", eventHandler);
|
||||
|
||||
window.addEventListener("beforeunload", eventHandler);
|
||||
globalThis.addEventListener("beforeunload", eventHandler);
|
||||
|
||||
window.addEventListener("unload", eventHandler);
|
||||
globalThis.addEventListener("unload", eventHandler);
|
||||
|
||||
window.onload = (e: Event) => {
|
||||
globalThis.onload = (e: Event) => {
|
||||
assert(!e.cancelable);
|
||||
console.log(`got ${e.type} event in onload function`);
|
||||
};
|
||||
|
||||
window.onbeforeunload = (e: BeforeUnloadEvent) => {
|
||||
globalThis.onbeforeunload = (e: BeforeUnloadEvent) => {
|
||||
assert(e.cancelable);
|
||||
console.log(`got ${e.type} event in onbeforeunload function`);
|
||||
};
|
||||
|
||||
window.onunload = (e: Event) => {
|
||||
globalThis.onunload = (e: Event) => {
|
||||
assert(!e.cancelable);
|
||||
console.log(`got ${e.type} event in onunload function`);
|
||||
};
|
||||
|
|
7
tests/testdata/run/onload/nest_imported.ts
vendored
7
tests/testdata/run/onload/nest_imported.ts
vendored
|
@ -1,4 +1,3 @@
|
|||
// deno-lint-ignore-file no-window-prefix
|
||||
import { assert } from "@std/assert";
|
||||
|
||||
const handler = (e: Event) => {
|
||||
|
@ -6,7 +5,7 @@ const handler = (e: Event) => {
|
|||
console.log(`got ${e.type} event in event handler (nest_imported)`);
|
||||
};
|
||||
|
||||
window.addEventListener("load", handler);
|
||||
window.addEventListener("beforeunload", handler);
|
||||
window.addEventListener("unload", handler);
|
||||
globalThis.addEventListener("load", handler);
|
||||
globalThis.addEventListener("beforeunload", handler);
|
||||
globalThis.addEventListener("unload", handler);
|
||||
console.log("log from nest_imported script");
|
||||
|
|
4
tests/testdata/run/rejection_handled.ts
vendored
4
tests/testdata/run/rejection_handled.ts
vendored
|
@ -1,9 +1,9 @@
|
|||
window.addEventListener("unhandledrejection", (event) => {
|
||||
globalThis.addEventListener("unhandledrejection", (event) => {
|
||||
console.log("unhandledrejection", event.reason, event.promise);
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
window.addEventListener("rejectionhandled", (event) => {
|
||||
globalThis.addEventListener("rejectionhandled", (event) => {
|
||||
console.log("rejectionhandled", event.reason, event.promise);
|
||||
});
|
||||
|
||||
|
|
1
tests/testdata/run/tls_connecttls.js
vendored
1
tests/testdata/run/tls_connecttls.js
vendored
|
@ -37,7 +37,6 @@ const conn = await Deno.connectTls({
|
|||
hostname,
|
||||
port,
|
||||
});
|
||||
assert(conn.rid > 0);
|
||||
const w = new BufWriter(conn);
|
||||
const r = new BufReader(conn);
|
||||
const body = `GET / HTTP/1.1\r\nHost: ${hostname}:${port}\r\n\r\n`;
|
||||
|
|
1
tests/testdata/run/tls_starttls.js
vendored
1
tests/testdata/run/tls_starttls.js
vendored
|
@ -36,7 +36,6 @@ listener.accept().then(
|
|||
|
||||
let conn = await Deno.connect({ hostname, port });
|
||||
conn = await Deno.startTls(conn, { hostname });
|
||||
assert(conn.rid > 0);
|
||||
const w = new BufWriter(conn);
|
||||
const r = new BufReader(conn);
|
||||
const body = `GET / HTTP/1.1\r\nHost: ${hostname}:${port}\r\n\r\n`;
|
||||
|
|
2
tests/testdata/run/webstorage/logger.ts
vendored
2
tests/testdata/run/webstorage/logger.ts
vendored
|
@ -1 +1 @@
|
|||
console.log(window.localStorage);
|
||||
console.log(globalThis.localStorage);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
window.sessionStorage.setItem("hello", "deno");
|
||||
globalThis.sessionStorage.setItem("hello", "deno");
|
||||
|
||||
console.log(window.localStorage);
|
||||
console.log(window.sessionStorage);
|
||||
console.log(globalThis.localStorage);
|
||||
console.log(globalThis.sessionStorage);
|
||||
|
|
2
tests/testdata/run/webstorage/setter.ts
vendored
2
tests/testdata/run/webstorage/setter.ts
vendored
|
@ -1 +1 @@
|
|||
window.localStorage.setItem("hello", "deno");
|
||||
globalThis.localStorage.setItem("hello", "deno");
|
||||
|
|
Loading…
Reference in a new issue