Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro committed Jan 1, 2025
1 parent 4a93608 commit 96c1339
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 39 deletions.
6 changes: 4 additions & 2 deletions src/bun.js/bindings/BunProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,10 @@ extern "C" void Process__dispatchOnBeforeExit(Zig::GlobalObject* globalObject, u
Bun__VirtualMachine__exitDuringUncaughtException(bunVM(vm));
auto fired = process->wrapped().emit(Identifier::fromString(vm, "beforeExit"_s), arguments);
if (fired) {
auto nextTickQueue = jsCast<JSNextTickQueue*>(globalObject->m_nextTickQueue.get());
nextTickQueue->drain(vm, globalObject);
if (auto ntq = globalObject->m_nextTickQueue) {
auto nextTickQueue = jsDynamicCast<JSNextTickQueue*>(ntq.get());
if (nextTickQueue) nextTickQueue->drain(vm, globalObject);
}
}
}

Expand Down
68 changes: 31 additions & 37 deletions test/js/node/process/process.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { spawnSync, which } from "bun";
import { describe, expect, it } from "bun:test";
import { existsSync, readFileSync, writeFileSync } from "fs";
import { bunEnv, bunExe, isWindows, tmpdirSync } from "harness";
import { basename, join, resolve } from "path";
import path, { basename, join, resolve } from "path";
import { familySync } from "detect-libc";

expect.extend({
Expand Down Expand Up @@ -236,12 +236,16 @@ it("process.uptime()", () => {
});

it("process.umask()", () => {
let notNumbers = [265n, "string", true, false, null, {}, [], () => {}, Symbol("symbol"), BigInt(1)];
for (let notNumber of notNumbers) {
expect(() => {
process.umask(notNumber);
}).toThrow('The "mask" argument must be of type number');
}
expect(() => process.umask(265n)).toThrow('The "mask" argument must be of type number. Received type bigint (265n)');
expect(() => process.umask("string")).toThrow(`The argument 'mask' must be a 32-bit unsigned integer or an octal string. Received "string"`); // prettier-ignore
expect(() => process.umask(true)).toThrow('The "mask" argument must be of type number. Received type boolean (true)');
expect(() => process.umask(false)).toThrow('The "mask" argument must be of type number. Received type boolean (false)'); // prettier-ignore
expect(() => process.umask(null)).toThrow('The "mask" argument must be of type number. Received null');
expect(() => process.umask({})).toThrow('The "mask" argument must be of type number. Received an instance of Object');
expect(() => process.umask([])).toThrow('The "mask" argument must be of type number. Received an instance of Array');
expect(() => process.umask(() => {})).toThrow('The "mask" argument must be of type number. Received function ');
expect(() => process.umask(Symbol("symbol"))).toThrow('The "mask" argument must be of type number. Received type symbol (Symbol(symbol))'); // prettier-ignore
expect(() => process.umask(BigInt(1))).toThrow('The "mask" argument must be of type number. Received type bigint (1n)'); // prettier-ignore

let rangeErrors = [NaN, -1.4, Infinity, -Infinity, -1, 1.3, 4294967296];
for (let rangeError of rangeErrors) {
Expand Down Expand Up @@ -310,20 +314,6 @@ it("process.config", () => {
});
});

it("process.emitWarning", () => {
process.emitWarning("-- Testing process.emitWarning --");
var called = 0;
process.on("warning", err => {
called++;
expect(err.message).toBe("-- Testing process.on('warning') --");
});
process.emitWarning("-- Testing process.on('warning') --");
expect(called).toBe(1);
expect(process.off("warning")).toBe(process);
process.emitWarning("-- Testing process.on('warning') --");
expect(called).toBe(1);
});

it("process.execArgv", () => {
expect(process.execArgv instanceof Array).toBe(true);
});
Expand All @@ -342,11 +332,21 @@ it("process.argv in testing", () => {

describe("process.exitCode", () => {
it("validates int", () => {
expect(() => (process.exitCode = "potato")).toThrow(`exitCode must be an integer`);
expect(() => (process.exitCode = 1.2)).toThrow("exitCode must be an integer");
expect(() => (process.exitCode = NaN)).toThrow("exitCode must be an integer");
expect(() => (process.exitCode = Infinity)).toThrow("exitCode must be an integer");
expect(() => (process.exitCode = -Infinity)).toThrow("exitCode must be an integer");
expect(() => (process.exitCode = "potato")).toThrow(
`The "code" argument must be of type number. Received type string ("potato")`,
);
expect(() => (process.exitCode = 1.2)).toThrow(
`The value of \"code\" is out of range. It must be an integer. Received 1.2`,
);
expect(() => (process.exitCode = NaN)).toThrow(
`The value of \"code\" is out of range. It must be an integer. Received NaN`,
);
expect(() => (process.exitCode = Infinity)).toThrow(
`The value of \"code\" is out of range. It must be an integer. Received Infinity`,
);
expect(() => (process.exitCode = -Infinity)).toThrow(
`The value of \"code\" is out of range. It must be an integer. Received -Infinity`,
);
});

it("works with implicit process.exit", () => {
Expand Down Expand Up @@ -412,7 +412,7 @@ describe("process.onBeforeExit", () => {
stdio: ["inherit", "pipe", "pipe"],
});
expect(proc.exitCode).toBe(1);
expect(proc.stderr.toString("utf8")).toInclude("error: boom");
expect(proc.stderr.toString("utf8")).toInclude("Error: boom");
expect(proc.stdout.toString("utf8")).toBeEmpty();
});
});
Expand All @@ -425,7 +425,7 @@ describe("process.onExit", () => {
stdio: ["inherit", "pipe", "pipe"],
});
expect(proc.exitCode).toBe(1);
expect(proc.stderr.toString("utf8")).toInclude("error: boom");
expect(proc.stderr.toString("utf8")).toInclude("Error: boom");
expect(proc.stdout.toString("utf8")).toBeEmpty();
});
});
Expand Down Expand Up @@ -458,13 +458,13 @@ describe("process.cpuUsage", () => {
user: -1,
system: 100,
}),
).toThrow("The 'user' property must be a number between 0 and 2^53");
).toThrow("The property 'prevValue.user' is invalid. Received -1");
expect(() =>
process.cpuUsage({
user: 100,
system: -1,
}),
).toThrow("The 'system' property must be a number between 0 and 2^53");
).toThrow("The property 'prevValue.system' is invalid. Received -1");
});

// Skipped on Windows because it seems UV returns { user: 15000, system: 0 } constantly
Expand Down Expand Up @@ -684,13 +684,7 @@ it("dlopen accepts file: URLs", () => {
});

it("process.constrainedMemory()", () => {
if (process.platform === "linux") {
// On Linux, it returns 0 if the kernel doesn't support it
expect(process.constrainedMemory() >= 0).toBe(true);
} else {
// On unsupported platforms, it returns undefined
expect(process.constrainedMemory()).toBeUndefined();
}
expect(process.constrainedMemory() >= 0).toBe(true);
});

it("process.report", () => {
Expand Down

0 comments on commit 96c1339

Please sign in to comment.