1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-05 13:59:01 -05:00
denoland-deno/tests/testdata/npm/compare_globals/main.ts
Bartek Iwańczuk b1c6142f74
BREAKING: DENO_FUTURE=1 by default, or welcome to Deno 2.0 (#25213)
This commit effectively turns Deno into Deno 2.0.

This is done by forcing `DENO_FUTURE=1` env var, that was available in
the past few months to try Deno 2 changes.

This commit contains several breaking changes scheduled for Deno 2:
- all deprecated JavaScript APIs are not available any more, mostly
`Deno.*` APIs
- `window` global is removed
- FFI, WebGPU and FS APIs are now stable and don't require
`--unstable-*` flags
- import assertions are no longer supported
- "bring your own node modules" is enabled by default

This is the first commit in a series that are scheduled before the Deno
2 release.

Follow up work is tracked in
https://github.com/denoland/deno/issues/25241.

---------

Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
Co-authored-by: Nayeem Rahman <nayeemrmn99@gmail.com>
Co-authored-by: Nathan Whitaker <nathan@deno.com>
2024-08-30 13:58:58 -04:00

62 lines
2.3 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("setTimeout 1", 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("setTimeout 2", typeof globalThis.setTimeout);
console.log("setTimeout 3", typeof globals.getSetTimeout());
globals.deleteSetTimeout();
console.log("setTimeout 4", typeof globalThis.setTimeout);
console.log("setTimeout 5", typeof globals.getSetTimeout());
// In Deno, the process global is not defined, but in Node it is.
console.log("process 1", "process" in globalThis);
console.log(
"process 2",
Object.getOwnPropertyDescriptor(globalThis, "process") !== undefined,
);
globals.checkProcessGlobal();
// In Deno 2 and Node.js, the window global is not defined.
console.log("window 1", "window" in globalThis);
console.log(
"window 2",
Object.getOwnPropertyDescriptor(globalThis, "window") !== undefined,
);
globals.checkWindowGlobal();
// In Deno 2 self global is defined, but in Node it is not.
console.log("self 1", "self" in globalThis);
console.log(
"self 2",
Object.getOwnPropertyDescriptor(globalThis, "self") !== undefined,
);
globals.checkSelfGlobal();
// "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