Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions node/global_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import "./global.ts";
import {
assert,
assertEquals,
assertNotEquals,
assertStrictEquals,
} from "../testing/asserts.ts";
Expand Down Expand Up @@ -86,3 +87,30 @@ Deno.test("clearImmediate is correctly defined", () => {
assertStrictEquals(globalThis.clearImmediate, timers.clearImmediate);
assertStrictEquals(window.clearImmediate, timers.clearImmediate);
});

// https://github.com/denoland/deno_std/issues/2097
Deno.test("global.ts evaluates synchronously", async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test to prevent the regression 👍

const tempPath = await Deno.makeTempFile({ suffix: ".ts" });
try {
await Deno.writeTextFile(
tempPath,
`\
import "data:application/javascript,import '${
new URL("global.ts", import.meta.url).href
}'; console.log(globalThis.async ? 'async' : 'sync')";
import "data:application/javascript,globalThis.async = true";`,
);
const process = Deno.run({
cmd: [Deno.execPath(), "run", "--no-check", tempPath],
stdin: "null",
stdout: "piped",
stderr: "null",
});
assertEquals((await process.status()).code, 0);
const stdout = new TextDecoder().decode(await process.output());
assertEquals(stdout.trim(), "sync");
process.close();
} finally {
await Deno.remove(tempPath).catch(() => {});
}
});
23 changes: 10 additions & 13 deletions node/internal/util/debuglog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,16 @@ export function debuglog(
return logger;
}

let state = "";

if (Deno.permissions) {
state = (await Deno.permissions.query({
name: "env",
variable: "NODE_DEBUG",
})).state;
}

if (state === "granted") {
initializeDebugEnv(Deno.env.get("NODE_DEBUG") ?? "");
} else {
initializeDebugEnv("");
let debugEnv;
try {
debugEnv = Deno.env.get("NODE_DEBUG") ?? "";
} catch (error) {
if (error instanceof Deno.errors.PermissionDenied) {
debugEnv = "";
} else {
throw error;
}
}
initializeDebugEnv(debugEnv);

export default { debuglog };