| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9aa4c88 commit 590e050
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,7 @@ jobs: | |||
| 17 | 17 | - 22.x | |
| 18 | 18 | - 24.x | |
| 19 | 19 | - 25.x | |
| 20 | + - 26.x | ||
| 20 | 21 | runs-on: ${{ matrix.runner }} | |
| 21 | 22 | steps: | |
| 22 | 23 | - name: Harden Runner | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,16 +7,17 @@ import { | |||
| 7 | 7 | match, | |
| 8 | 8 | } from 'node:assert/strict'; | |
| 9 | 9 | ||
| 10 | - const assert = Object.assign((value, message) => ok(value, message), { | ||
| 11 | - ok: (value, message) => ok(value, message), | ||
| 12 | - strictEqual: (actual, expected, message) => | ||
| 13 | - strictEqual(actual, expected, message), | ||
| 14 | - notStrictEqual: (actual, expected, message) => | ||
| 15 | - notStrictEqual(actual, expected, message), | ||
| 16 | - deepStrictEqual: (actual, expected, message) => | ||
| 17 | - deepStrictEqual(actual, expected, message), | ||
| 18 | - throws: (fn, error, message) => throws(fn, error, message), | ||
| 19 | - match: (string, regex, message) => match(string, regex, message), | ||
| 10 | + // Forward with rest arguments rather than named parameters: an omitted trailing | ||
| 11 | + // message has to stay omitted. Node.js 26 reads the message as a variadic tuple, | ||
| 12 | + // so an explicitly passed `undefined` is a message of the wrong type there and | ||
| 13 | + // the assertion fails with ERR_INVALID_ARG_TYPE instead of the value comparison. | ||
| 14 | + const assert = Object.assign((...args) => ok(...args), { | ||
| 15 | + ok: (...args) => ok(...args), | ||
| 16 | + strictEqual: (...args) => strictEqual(...args), | ||
| 17 | + notStrictEqual: (...args) => notStrictEqual(...args), | ||
| 18 | + deepStrictEqual: (...args) => deepStrictEqual(...args), | ||
| 19 | + throws: (...args) => throws(...args), | ||
| 20 | + match: (...args) => match(...args), | ||
| 20 | 21 | }); | |
| 21 | 22 | ||
| 22 | 23 | Object.assign(globalThis, { assert }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,3 +105,49 @@ if (!threw) throw new Error('assert.match must throw when input is not a string' | |||
| 105 | 105 | threw = false; | |
| 106 | 106 | try { assert.match('hello', 'hello'); } catch { threw = true; } | |
| 107 | 107 | if (!threw) throw new Error('assert.match must throw when pattern is not a RegExp'); | |
| 108 | + | ||
| 109 | + // The message is optional on every method. A failure without one must still | ||
| 110 | + // report the comparison, and a failure with one must report that message. | ||
| 111 | + function failureOf(label, fn) { | ||
| 112 | + try { | ||
| 113 | + fn(); | ||
| 114 | + } catch (error) { | ||
| 115 | + return error; | ||
| 116 | + } | ||
| 117 | + throw new Error(`${label} was expected to throw`); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + const optionalMessage = [ | ||
| 121 | + ['assert', () => assert(false), (m) => assert(false, m)], | ||
| 122 | + ['assert.ok', () => assert.ok(false), (m) => assert.ok(false, m)], | ||
| 123 | + ['assert.strictEqual', () => assert.strictEqual(1, 2), (m) => assert.strictEqual(1, 2, m)], | ||
| 124 | + ['assert.notStrictEqual', () => assert.notStrictEqual(1, 1), (m) => assert.notStrictEqual(1, 1, m)], | ||
| 125 | + [ | ||
| 126 | + 'assert.deepStrictEqual', | ||
| 127 | + () => assert.deepStrictEqual({ a: 1 }, { a: 2 }), | ||
| 128 | + (m) => assert.deepStrictEqual({ a: 1 }, { a: 2 }, m), | ||
| 129 | + ], | ||
| 130 | + ['assert.match', () => assert.match('hello', /world/), (m) => assert.match('hello', /world/, m)], | ||
| 131 | + ['assert.throws', () => assert.throws(() => {}, /oops/), (m) => assert.throws(() => {}, /oops/, m)], | ||
| 132 | + ]; | ||
| 133 | + | ||
| 134 | + const customMessage = 'a message the caller chose'; | ||
| 135 | + | ||
| 136 | + for (const [label, withoutMessage, withMessage] of optionalMessage) { | ||
| 137 | + // Only a substring check: the strict assert methods append their own value | ||
| 138 | + // comparison to a caller supplied message. | ||
| 139 | + const described = failureOf(label, () => withMessage(customMessage)); | ||
| 140 | + if (!described.message.includes(customMessage)) { | ||
| 141 | + throw new Error( | ||
| 142 | + `${label} must fail with the message it was given but failed with "${described.message}"`, | ||
| 143 | + ); | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + const bare = failureOf(label, withoutMessage); | ||
| 147 | + if (bare.name !== described.name) { | ||
| 148 | + throw new Error( | ||
| 149 | + `${label} must fail the same way with and without a message, but without one it failed ` + | ||
| 150 | + `with "${bare.name}: ${bare.message}" instead of ${described.name}`, | ||
| 151 | + ); | ||
| 152 | + } | ||
| 153 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments