From f5e46c9bf2f50d66a953fa133161fc829cecff06 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Sat, 10 Feb 2024 13:22:13 -0700 Subject: 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. --- tests/testdata/npm/compare_globals/main.out | 28 ++++++++++++++++ tests/testdata/npm/compare_globals/main.ts | 52 +++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tests/testdata/npm/compare_globals/main.out create mode 100644 tests/testdata/npm/compare_globals/main.ts (limited to 'tests/testdata/npm/compare_globals') diff --git a/tests/testdata/npm/compare_globals/main.out b/tests/testdata/npm/compare_globals/main.out new file mode 100644 index 000000000..0e366fae7 --- /dev/null +++ b/tests/testdata/npm/compare_globals/main.out @@ -0,0 +1,28 @@ +[UNORDERED_START] +Download http://localhost:4545/npm/registry/@types/node +Download http://localhost:4545/npm/registry/@denotest/globals +[UNORDERED_END] +[UNORDERED_START] +Download http://localhost:4545/npm/registry/@denotest/globals/1.0.0.tgz +Download http://localhost:4545/npm/registry/@types/node/node-18.8.2.tgz +[UNORDERED_END] +Check file:///[WILDCARD]/npm/compare_globals/main.ts +true +true +[] +false +function +function +function +undefined +false +false +true +true +true +true +false +false +bar +bar +true diff --git a/tests/testdata/npm/compare_globals/main.ts b/tests/testdata/npm/compare_globals/main.ts new file mode 100644 index 000000000..6f7b9ef8e --- /dev/null +++ b/tests/testdata/npm/compare_globals/main.ts @@ -0,0 +1,52 @@ +/// + +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 = 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 -- cgit v1.2.3