From 315d889afa38e976b106a3769cab206db31d5ce8 Mon Sep 17 00:00:00 2001 From: Steven Guerrero Date: Thu, 19 Nov 2020 07:23:42 -0500 Subject: fix(std/node): correct typings for global, globalThis, window (#8363) --- std/node/global_test.ts | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 std/node/global_test.ts (limited to 'std/node/global_test.ts') diff --git a/std/node/global_test.ts b/std/node/global_test.ts new file mode 100644 index 000000000..9ce0b2132 --- /dev/null +++ b/std/node/global_test.ts @@ -0,0 +1,52 @@ +import "./global.ts"; +import { assert, assertStrictEquals } from "../testing/asserts.ts"; +import { Buffer as BufferModule } from "./buffer.ts"; +import processModule from "./process.ts"; + +// Definitions for this are quite delicate +// This ensures modifications to the global namespace don't break on TypeScript + +// TODO +// Deno lint marks globals defined by this module as undefined +// probably gonna change in the future + +Deno.test("global is correctly defined", () => { + // deno-lint-ignore no-undef + assertStrictEquals(global, globalThis); + // deno-lint-ignore no-undef + assertStrictEquals(global.Buffer, BufferModule); + // deno-lint-ignore no-undef + assertStrictEquals(global.process, process); +}); + +Deno.test("Buffer is correctly defined", () => { + //Check that Buffer is defined as a type as well + type x = Buffer; + // deno-lint-ignore no-undef + assertStrictEquals(Buffer, BufferModule); + // deno-lint-ignore no-undef + assert(Buffer.from); + // deno-lint-ignore no-undef + assertStrictEquals(global.Buffer, BufferModule); + // deno-lint-ignore no-undef + assert(global.Buffer.from); + assertStrictEquals(globalThis.Buffer, BufferModule); + assert(globalThis.Buffer.from); + assertStrictEquals(window.Buffer, BufferModule); + assert(window.Buffer.from); +}); + +Deno.test("process is correctly defined", () => { + // deno-lint-ignore no-undef + assertStrictEquals(process, processModule); + // deno-lint-ignore no-undef + assert(process.arch); + // deno-lint-ignore no-undef + assertStrictEquals(global.process, processModule); + // deno-lint-ignore no-undef + assert(global.process.arch); + assertStrictEquals(globalThis.process, processModule); + assert(globalThis.process.arch); + assertStrictEquals(window.process, processModule); + assert(window.process.arch); +}); -- cgit v1.2.3