-
Notifications
You must be signed in to change notification settings - Fork 5.1k
assert.fail: match Node 26 single-argument behavior #33567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
robobun
wants to merge
7
commits into
main
Choose a base branch
from
farm/9ccd746e/assert-fail-node26
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d6d468e
assert.fail: match Node 26 single-argument behavior
robobun 736f669
test: move assert.fail tests into assert.test.cjs
robobun 36668c9
test: add assert.fail node 26 regression tests
robobun 246348d
[autofix.ci] apply automated fixes
autofix-ci[bot] f997fa4
assert.fail: handle undefined message, cross-realm errors; drop legac…
robobun 27d1b2c
assert.fail: keep generatedMessage for falsy non-Error messages
robobun b0e29b3
ci: retrigger gate build
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import { describe, expect, it } from "bun:test"; | ||
| import { bunEnv, bunExe } from "harness"; | ||
| import assert from "node:assert"; | ||
| import vm from "node:vm"; | ||
|
|
||
| // node v26 removed the end-of-life DEP0094 multi-argument behaviour of | ||
| // assert.fail: only the first argument is used (as the message, or thrown if | ||
| // it is an Error), operator is always "fail", actual/expected are undefined. | ||
| describe("assert.fail", () => { | ||
| const capture = (fn: () => void) => { | ||
| try { | ||
| fn(); | ||
| } catch (e: any) { | ||
| return { | ||
| message: e.message, | ||
| actual: e.actual, | ||
| expected: e.expected, | ||
| operator: e.operator, | ||
| generatedMessage: e.generatedMessage, | ||
| }; | ||
| } | ||
| throw new Error("assert.fail did not throw"); | ||
| }; | ||
|
|
||
| it("with no arguments uses the default generated message", () => { | ||
| expect(capture(() => assert.fail())).toEqual({ | ||
| message: "Failed", | ||
| actual: undefined, | ||
| expected: undefined, | ||
| operator: "fail", | ||
| generatedMessage: true, | ||
| }); | ||
| }); | ||
|
|
||
| it("with an explicit undefined message uses the default generated message", () => { | ||
| expect(capture(() => assert.fail(undefined))).toEqual({ | ||
| message: "Failed", | ||
| actual: undefined, | ||
| expected: undefined, | ||
| operator: "fail", | ||
| generatedMessage: true, | ||
| }); | ||
| }); | ||
|
|
||
| it("treats a falsy non-Error message as generated (matches AssertionError)", () => { | ||
| expect(capture(() => assert.fail(""))).toEqual({ | ||
| message: "", | ||
| actual: undefined, | ||
| expected: undefined, | ||
| operator: "fail", | ||
| generatedMessage: true, | ||
| }); | ||
| }); | ||
|
|
||
| it("uses the first argument as the message", () => { | ||
| expect(capture(() => assert.fail("boom"))).toEqual({ | ||
| message: "boom", | ||
| actual: undefined, | ||
| expected: undefined, | ||
| operator: "fail", | ||
| generatedMessage: false, | ||
| }); | ||
| }); | ||
|
|
||
| it("ignores extra arguments (no legacy actual/expected synthesis)", () => { | ||
| expect(capture(() => (assert.fail as any)(1, 2))).toEqual({ | ||
| message: "1", | ||
| actual: undefined, | ||
| expected: undefined, | ||
| operator: "fail", | ||
| generatedMessage: false, | ||
| }); | ||
| expect(capture(() => (assert.fail as any)(1, 2, undefined, "=="))).toEqual({ | ||
| message: "1", | ||
| actual: undefined, | ||
| expected: undefined, | ||
| operator: "fail", | ||
| generatedMessage: false, | ||
| }); | ||
| expect(capture(() => (assert.fail as any)("a", "b", "m"))).toEqual({ | ||
| message: "a", | ||
| actual: undefined, | ||
| expected: undefined, | ||
| operator: "fail", | ||
| generatedMessage: false, | ||
| }); | ||
| }); | ||
|
|
||
| it("throws the first argument when it is an Error", () => { | ||
| const err = new Error("custom"); | ||
| try { | ||
| assert.fail(err); | ||
| } catch (e) { | ||
| expect(e).toBe(err); | ||
| return; | ||
| } | ||
| throw new Error("assert.fail did not throw"); | ||
| }); | ||
|
|
||
| it("throws a cross-realm Error instance directly", () => { | ||
| const err = vm.runInNewContext("new Error('cross-realm')"); | ||
| try { | ||
| assert.fail(err); | ||
| } catch (e) { | ||
| expect(e).toBe(err); | ||
| return; | ||
| } | ||
| throw new Error("assert.fail did not throw"); | ||
| }); | ||
|
|
||
| it("does not emit a DEP0094 deprecation warning for multi-argument calls", async () => { | ||
| await using proc = Bun.spawn({ | ||
| cmd: [ | ||
| bunExe(), | ||
| "-e", | ||
| `const assert = require("node:assert"); | ||
| process.on("warning", w => { console.error("ROBOBUN_PROCESS_WARNING", w.name, w.code); process.exit(2); }); | ||
| try { assert.fail(1, 2); } catch {} | ||
| setImmediate(() => process.exit(0));`, | ||
| ], | ||
| env: bunEnv, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
| expect(stderr).not.toContain("DEP0094"); | ||
| expect(stderr).not.toContain("ROBOBUN_PROCESS_WARNING"); | ||
| expect(stdout).toBe(""); | ||
| expect(exitCode).toBe(0); | ||
| }); | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
70 changes: 0 additions & 70 deletions
70
test/js/node/test/parallel/test-assert-fail-deprecation.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.