2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-03-04 11:31:14 -05:00
|
|
|
import { unitTest, assert } from "./test_util.ts";
|
2019-01-16 17:57:15 -05:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(function globalThisExists(): void {
|
2019-01-16 17:57:15 -05:00
|
|
|
assert(globalThis != null);
|
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(function windowExists(): void {
|
2019-01-16 17:57:15 -05:00
|
|
|
assert(window != null);
|
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(function selfExists(): void {
|
2020-02-26 05:49:38 -05:00
|
|
|
assert(self != null);
|
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(function windowWindowExists(): void {
|
2019-01-16 17:57:15 -05:00
|
|
|
assert(window.window === window);
|
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(function windowSelfExists(): void {
|
2020-02-26 05:49:38 -05:00
|
|
|
assert(window.self === window);
|
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(function globalThisEqualsWindow(): void {
|
2019-01-16 17:57:15 -05:00
|
|
|
assert(globalThis === window);
|
|
|
|
});
|
2019-02-05 08:12:58 -05:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(function globalThisEqualsSelf(): void {
|
2020-02-26 05:49:38 -05:00
|
|
|
assert(globalThis === self);
|
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(function DenoNamespaceExists(): void {
|
2019-02-12 10:08:56 -05:00
|
|
|
assert(Deno != null);
|
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(function DenoNamespaceEqualsWindowDeno(): void {
|
2019-02-12 10:08:56 -05:00
|
|
|
assert(Deno === window.Deno);
|
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(function DenoNamespaceIsFrozen(): void {
|
2019-02-12 10:08:56 -05:00
|
|
|
assert(Object.isFrozen(Deno));
|
|
|
|
});
|
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(function webAssemblyExists(): void {
|
2019-02-05 08:12:58 -05:00
|
|
|
assert(typeof WebAssembly.compile === "function");
|
|
|
|
});
|
2019-04-19 20:39:54 -04:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(function DenoNamespaceImmutable(): void {
|
2019-04-19 20:39:54 -04:00
|
|
|
const denoCopy = window.Deno;
|
|
|
|
try {
|
2020-05-26 10:02:16 -04:00
|
|
|
// @ts-expect-error
|
2019-04-19 20:39:54 -04:00
|
|
|
Deno = 1;
|
|
|
|
} catch {}
|
|
|
|
assert(denoCopy === Deno);
|
|
|
|
try {
|
2020-05-26 10:02:16 -04:00
|
|
|
// @ts-expect-error
|
2019-04-19 20:39:54 -04:00
|
|
|
window.Deno = 1;
|
|
|
|
} catch {}
|
|
|
|
assert(denoCopy === Deno);
|
|
|
|
try {
|
|
|
|
delete window.Deno;
|
|
|
|
} catch {}
|
|
|
|
assert(denoCopy === Deno);
|
|
|
|
|
|
|
|
const { readFile } = Deno;
|
|
|
|
try {
|
2020-05-26 10:02:16 -04:00
|
|
|
// @ts-expect-error
|
2019-04-19 20:39:54 -04:00
|
|
|
Deno.readFile = 1;
|
|
|
|
} catch {}
|
|
|
|
assert(readFile === Deno.readFile);
|
|
|
|
try {
|
|
|
|
delete window.Deno.readFile;
|
|
|
|
} catch {}
|
|
|
|
assert(readFile === Deno.readFile);
|
|
|
|
|
2020-05-26 10:02:16 -04:00
|
|
|
// @ts-expect-error
|
2019-04-19 20:39:54 -04:00
|
|
|
const { print } = Deno.core;
|
|
|
|
try {
|
2020-05-26 10:02:16 -04:00
|
|
|
// @ts-expect-error
|
2019-04-19 20:39:54 -04:00
|
|
|
Deno.core.print = 1;
|
|
|
|
} catch {}
|
2020-05-26 10:02:16 -04:00
|
|
|
// @ts-expect-error
|
2019-04-19 20:39:54 -04:00
|
|
|
assert(print === Deno.core.print);
|
|
|
|
try {
|
2020-05-26 10:02:16 -04:00
|
|
|
// @ts-expect-error
|
2019-04-19 20:39:54 -04:00
|
|
|
delete Deno.core.print;
|
|
|
|
} catch {}
|
2020-05-26 10:02:16 -04:00
|
|
|
// @ts-expect-error
|
2019-04-19 20:39:54 -04:00
|
|
|
assert(print === Deno.core.print);
|
|
|
|
});
|
2019-08-31 15:16:30 -04:00
|
|
|
|
2020-03-04 11:31:14 -05:00
|
|
|
unitTest(async function windowQueueMicrotask(): Promise<void> {
|
2019-08-31 15:16:30 -04:00
|
|
|
let resolve1: () => void | undefined;
|
|
|
|
let resolve2: () => void | undefined;
|
|
|
|
let microtaskDone = false;
|
2019-11-13 13:42:34 -05:00
|
|
|
const p1 = new Promise((res): void => {
|
|
|
|
resolve1 = (): void => {
|
|
|
|
microtaskDone = true;
|
|
|
|
res();
|
|
|
|
};
|
|
|
|
});
|
|
|
|
const p2 = new Promise((res): void => {
|
|
|
|
resolve2 = (): void => {
|
|
|
|
assert(microtaskDone);
|
|
|
|
res();
|
|
|
|
};
|
|
|
|
});
|
2019-08-31 15:16:30 -04:00
|
|
|
window.queueMicrotask(resolve1!);
|
|
|
|
setTimeout(resolve2!, 0);
|
|
|
|
await p1;
|
|
|
|
await p2;
|
|
|
|
});
|