|
| 1 | +// Copyright 2018-2025 the Deno authors. MIT license. |
| 2 | +import { assertEquals } from "@std/assert/equals"; |
| 3 | +import { checkWindows } from "./_os.ts"; |
| 4 | +import { disposableStack, stubProperty } from "./_testing.ts"; |
| 5 | + |
| 6 | +// deno-lint-ignore no-explicit-any |
| 7 | +const global = globalThis as any; |
| 8 | + |
| 9 | +Deno.test("checkWindows() returns `true` on Windows on various runtimes", async (t) => { |
| 10 | + await t.step("Deno", () => { |
| 11 | + using stack = disposableStack(); |
| 12 | + stack.use(stubProperty(global, "Deno", { build: { os: "windows" } })); |
| 13 | + stack.use(stubProperty(global, "navigator", undefined)); |
| 14 | + stack.use(stubProperty(global, "process", undefined)); |
| 15 | + |
| 16 | + assertEquals(checkWindows(), true); |
| 17 | + }); |
| 18 | + |
| 19 | + await t.step("Browser etc.", () => { |
| 20 | + using stack = disposableStack(); |
| 21 | + stack.use(stubProperty(global, "Deno", undefined)); |
| 22 | + stack.use(stubProperty(global, "navigator", { platform: "Win32" })); |
| 23 | + stack.use(stubProperty(global, "process", undefined)); |
| 24 | + |
| 25 | + assertEquals(checkWindows(), true); |
| 26 | + }); |
| 27 | + |
| 28 | + await t.step("NodeJS etc.", () => { |
| 29 | + using stack = disposableStack(); |
| 30 | + stack.use(stubProperty(global, "Deno", undefined)); |
| 31 | + stack.use(stubProperty(global, "navigator", undefined)); |
| 32 | + stack.use(stubProperty(global, "process", { platform: "win32" })); |
| 33 | + |
| 34 | + assertEquals(checkWindows(), true); |
| 35 | + }); |
| 36 | +}); |
| 37 | + |
| 38 | +Deno.test("checkWindows() returns `false` on Linux on various runtimes", async (t) => { |
| 39 | + await t.step("Deno", () => { |
| 40 | + using stack = disposableStack(); |
| 41 | + stack.use(stubProperty(global, "Deno", { build: { os: "linux" } })); |
| 42 | + stack.use(stubProperty(global, "navigator", undefined)); |
| 43 | + stack.use(stubProperty(global, "process", undefined)); |
| 44 | + |
| 45 | + assertEquals(checkWindows(), false); |
| 46 | + }); |
| 47 | + |
| 48 | + await t.step("Browser etc.", () => { |
| 49 | + using stack = disposableStack(); |
| 50 | + stack.use(stubProperty(global, "Deno", undefined)); |
| 51 | + stack.use(stubProperty(global, "navigator", { platform: "Linux x86_64" })); |
| 52 | + stack.use(stubProperty(global, "process", undefined)); |
| 53 | + |
| 54 | + assertEquals(checkWindows(), false); |
| 55 | + }); |
| 56 | + |
| 57 | + await t.step("NodeJS etc.", () => { |
| 58 | + using stack = disposableStack(); |
| 59 | + stack.use(stubProperty(global, "Deno", undefined)); |
| 60 | + stack.use(stubProperty(global, "navigator", undefined)); |
| 61 | + stack.use(stubProperty(global, "process", { platform: "linux" })); |
| 62 | + |
| 63 | + assertEquals(checkWindows(), false); |
| 64 | + }); |
| 65 | +}); |
0 commit comments