1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-01 16:51:13 -05:00
denoland-deno/tests/testdata/npm/compare_globals/main.ts
Matt Mastracci f5e46c9bf2
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.

This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.

While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).

And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.

For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 20:22:13 +00:00

52 lines
2 KiB
TypeScript

/// <reference types="npm:@types/node" />
import * as globals from "npm:@denotest/globals";
console.log(globals.global === globals.globalThis);
// @ts-expect-error even though these are the same object, they have different types
console.log(globals.globalThis === globalThis);
console.log(globals.process.execArgv);
type AssertTrue<T extends true> = never;
type _TestNoProcessGlobal = AssertTrue<
typeof globalThis extends { process: any } ? false : true
>;
type _TestHasNodeJsGlobal = NodeJS.Architecture;
const controller = new AbortController();
controller.abort("reason"); // in the NodeJS declaration it doesn't have a reason
// Some globals are not the same between Node and Deno.
// @ts-expect-error incompatible types between Node and Deno
console.log(globalThis.setTimeout === globals.getSetTimeout());
// Super edge case where some Node code deletes a global where the
// Node code has its own global and the Deno code has the same global,
// but it's different. Basically if some Node code deletes
// one of these globals then we don't want it to suddenly inherit
// the Deno global (or touch the Deno global at all).
console.log(typeof globalThis.setTimeout);
console.log(typeof globals.getSetTimeout());
globals.deleteSetTimeout();
console.log(typeof globalThis.setTimeout);
console.log(typeof globals.getSetTimeout());
// In Deno, the process global is not defined, but in Node it is.
console.log("process" in globalThis);
console.log(
Object.getOwnPropertyDescriptor(globalThis, "process") !== undefined,
);
globals.checkProcessGlobal();
// In Deno, the window global is defined, but in Node it is not.
console.log("window" in globalThis);
console.log(
Object.getOwnPropertyDescriptor(globalThis, "window") !== undefined,
);
globals.checkWindowGlobal();
// "Non-managed" globals are shared between Node and Deno.
(globalThis as any).foo = "bar";
console.log((globalThis as any).foo);
console.log(globals.getFoo());
console.log(Reflect.ownKeys(globalThis).includes("console")); // non-enumerable keys are included