2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2021-09-02 17:38:19 +02:00
|
|
|
// deno-lint-ignore-file no-window-prefix
|
2021-11-23 17:45:18 +01:00
|
|
|
import { assert } from "./test_util.ts";
|
2019-01-17 09:57:15 +11:00
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function globalThisExists() {
|
2019-01-17 09:57:15 +11:00
|
|
|
assert(globalThis != null);
|
|
|
|
});
|
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function noInternalGlobals() {
|
2020-09-04 21:52:19 +10:00
|
|
|
// globalThis.__bootstrap should not be there.
|
|
|
|
for (const key of Object.keys(globalThis)) {
|
|
|
|
assert(!key.startsWith("_"));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function windowExists() {
|
2019-01-17 09:57:15 +11:00
|
|
|
assert(window != null);
|
|
|
|
});
|
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function selfExists() {
|
2020-02-26 11:49:38 +01:00
|
|
|
assert(self != null);
|
|
|
|
});
|
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function windowWindowExists() {
|
2019-01-17 09:57:15 +11:00
|
|
|
assert(window.window === window);
|
|
|
|
});
|
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function windowSelfExists() {
|
2020-02-26 11:49:38 +01:00
|
|
|
assert(window.self === window);
|
|
|
|
});
|
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function globalThisEqualsWindow() {
|
2019-01-17 09:57:15 +11:00
|
|
|
assert(globalThis === window);
|
|
|
|
});
|
2019-02-06 00:12:58 +11:00
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function globalThisEqualsSelf() {
|
2020-02-26 11:49:38 +01:00
|
|
|
assert(globalThis === self);
|
|
|
|
});
|
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function globalThisInstanceofWindow() {
|
2020-10-11 23:04:43 +01:00
|
|
|
assert(globalThis instanceof Window);
|
|
|
|
});
|
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function globalThisConstructorLength() {
|
2020-11-14 14:10:23 +02:00
|
|
|
assert(globalThis.constructor.length === 0);
|
|
|
|
});
|
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function globalThisInstanceofEventTarget() {
|
2020-10-11 23:04:43 +01:00
|
|
|
assert(globalThis instanceof EventTarget);
|
|
|
|
});
|
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function navigatorInstanceofNavigator() {
|
2021-03-08 12:27:49 +00:00
|
|
|
// TODO(nayeemrmn): Add `Navigator` to deno_lint globals.
|
|
|
|
// deno-lint-ignore no-undef
|
|
|
|
assert(navigator instanceof Navigator);
|
|
|
|
});
|
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function DenoNamespaceExists() {
|
2019-02-13 02:08:56 +11:00
|
|
|
assert(Deno != null);
|
|
|
|
});
|
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function DenoNamespaceEqualsWindowDeno() {
|
2019-02-13 02:08:56 +11:00
|
|
|
assert(Deno === window.Deno);
|
|
|
|
});
|
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function DenoNamespaceIsNotFrozen() {
|
2021-06-22 07:17:35 +10:00
|
|
|
assert(!Object.isFrozen(Deno));
|
2019-02-13 02:08:56 +11:00
|
|
|
});
|
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function webAssemblyExists() {
|
2019-02-06 00:12:58 +11:00
|
|
|
assert(typeof WebAssembly.compile === "function");
|
|
|
|
});
|
2019-04-19 17:39:54 -07:00
|
|
|
|
2020-06-02 14:24:44 +10:00
|
|
|
declare global {
|
|
|
|
namespace Deno {
|
2021-11-01 16:22:27 -04:00
|
|
|
// deno-lint-ignore no-explicit-any, no-var
|
2020-06-02 14:24:44 +10:00
|
|
|
var core: any;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function DenoNamespaceConfigurable() {
|
2021-06-22 07:17:35 +10:00
|
|
|
const desc = Object.getOwnPropertyDescriptor(globalThis, "Deno");
|
|
|
|
assert(desc);
|
|
|
|
assert(desc.configurable);
|
|
|
|
assert(!desc.writable);
|
|
|
|
});
|
2019-04-19 17:39:54 -07:00
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function DenoCoreNamespaceIsImmutable() {
|
2019-04-19 17:39:54 -07:00
|
|
|
const { print } = Deno.core;
|
|
|
|
try {
|
|
|
|
Deno.core.print = 1;
|
2020-06-19 02:05:37 -07:00
|
|
|
} catch {
|
|
|
|
// pass
|
|
|
|
}
|
2019-04-19 17:39:54 -07:00
|
|
|
assert(print === Deno.core.print);
|
|
|
|
try {
|
|
|
|
delete Deno.core.print;
|
2020-06-19 02:05:37 -07:00
|
|
|
} catch {
|
|
|
|
// pass
|
|
|
|
}
|
2019-04-19 17:39:54 -07:00
|
|
|
assert(print === Deno.core.print);
|
|
|
|
});
|
2019-08-31 12:16:30 -07:00
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(async function windowQueueMicrotask() {
|
2019-08-31 12:16:30 -07:00
|
|
|
let resolve1: () => void | undefined;
|
|
|
|
let resolve2: () => void | undefined;
|
|
|
|
let microtaskDone = false;
|
2021-08-05 13:08:58 +02:00
|
|
|
const p1 = new Promise<void>((res) => {
|
|
|
|
resolve1 = () => {
|
2019-11-14 05:42:34 +11:00
|
|
|
microtaskDone = true;
|
|
|
|
res();
|
|
|
|
};
|
|
|
|
});
|
2021-08-05 13:08:58 +02:00
|
|
|
const p2 = new Promise<void>((res) => {
|
|
|
|
resolve2 = () => {
|
2019-11-14 05:42:34 +11:00
|
|
|
assert(microtaskDone);
|
|
|
|
res();
|
|
|
|
};
|
|
|
|
});
|
2019-08-31 12:16:30 -07:00
|
|
|
window.queueMicrotask(resolve1!);
|
|
|
|
setTimeout(resolve2!, 0);
|
|
|
|
await p1;
|
|
|
|
await p2;
|
|
|
|
});
|
2021-10-21 08:47:14 +02:00
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function webApiGlobalThis() {
|
2021-10-21 08:47:14 +02:00
|
|
|
assert(globalThis.FormData !== null);
|
|
|
|
assert(globalThis.TextEncoder !== null);
|
|
|
|
assert(globalThis.TextEncoderStream !== null);
|
|
|
|
assert(globalThis.TextDecoder !== null);
|
|
|
|
assert(globalThis.TextDecoderStream !== null);
|
|
|
|
assert(globalThis.CountQueuingStrategy !== null);
|
|
|
|
assert(globalThis.ByteLengthQueuingStrategy !== null);
|
|
|
|
});
|