summaryrefslogtreecommitdiff
path: root/std/node/global_test.ts
diff options
context:
space:
mode:
authorSteven Guerrero <stephenguerrero43@gmail.com>2020-11-19 07:23:42 -0500
committerGitHub <noreply@github.com>2020-11-19 07:23:42 -0500
commit315d889afa38e976b106a3769cab206db31d5ce8 (patch)
treeb3243c90f6678cb6d2909bc9f6acceb412b21a6f /std/node/global_test.ts
parente3c3fc58cbc5053866928d33ffe25340c2bacc02 (diff)
fix(std/node): correct typings for global, globalThis, window (#8363)
Diffstat (limited to 'std/node/global_test.ts')
-rw-r--r--std/node/global_test.ts52
1 files changed, 52 insertions, 0 deletions
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);
+});