GeezerVison is showing github.com — test: ensure assertions are reached on more tests · nodejs/node@5ee02c7
File treeExpand file treeCollapse file tree Open diff view settings Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/eslint.config_partial.mjs +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -203,7 +203,7 @@ export default [ | 203 | 203 | `test/parallel/test-{${ | 204 | 204 | // 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…' | 205 | 205 | Array.from({ length: 13 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',') | 206 | | - },n*,${ | | 206 | + },n*,r*,${ | 207 | 207 | // 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…' | 208 | 208 | Array.from({ length: 8 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',') | 209 | 209 | }}.{js,mjs,cjs}`, | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-readable-from-iterator-closing.js +10-14Lines changed: 10 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | const { mustCall, mustNotCall } = require('../common'); | 4 | 4 | const { Readable } = require('stream'); | 5 | | -const { strictEqual } = require('assert'); | | 5 | +const assert = require('assert'); | 6 | 6 |
| 7 | 7 | async function asyncSupport() { | 8 | 8 | const finallyMustCall = mustCall(); | @@ -20,7 +20,7 @@ async function asyncSupport() { | 20 | 20 |
| 21 | 21 | for await (const chunk of stream) { | 22 | 22 | bodyMustCall(); | 23 | | - strictEqual(chunk, 'a'); | | 23 | + assert.strictEqual(chunk, 'a'); | 24 | 24 | break; | 25 | 25 | } | 26 | 26 | } | @@ -41,7 +41,7 @@ async function syncSupport() { | 41 | 41 |
| 42 | 42 | for await (const chunk of stream) { | 43 | 43 | bodyMustCall(); | 44 | | - strictEqual(chunk, 'a'); | | 44 | + assert.strictEqual(chunk, 'a'); | 45 | 45 | break; | 46 | 46 | } | 47 | 47 | } | @@ -66,7 +66,7 @@ async function syncPromiseSupport() { | 66 | 66 |
| 67 | 67 | for await (const chunk of stream) { | 68 | 68 | bodyMustCall(); | 69 | | - strictEqual(chunk, 'a'); | | 69 | + assert.strictEqual(chunk, 'a'); | 70 | 70 | break; | 71 | 71 | } | 72 | 72 | } | @@ -130,7 +130,6 @@ async function noReturnAfterThrow() { | 130 | 130 |
| 131 | 131 | async function closeStreamWhileNextIsPending() { | 132 | 132 | const finallyMustCall = mustCall(); | 133 | | - const dataMustCall = mustCall(); | 134 | 133 |
| 135 | 134 | let resolveDestroy; | 136 | 135 | const destroyed = | @@ -153,10 +152,9 @@ async function closeStreamWhileNextIsPending() { | 153 | 152 |
| 154 | 153 | const stream = Readable.from(infiniteGenerate()); | 155 | 154 |
| 156 | | - stream.on('data', (data) => { | 157 | | - dataMustCall(); | 158 | | - strictEqual(data, 'a'); | 159 | | - }); | | 155 | + stream.on('data', mustCall((data) => { | | 156 | + assert.strictEqual(data, 'a'); | | 157 | + })); | 160 | 158 |
| 161 | 159 | yielded.then(() => { | 162 | 160 | stream.destroy(); | @@ -166,7 +164,6 @@ async function closeStreamWhileNextIsPending() { | 166 | 164 |
| 167 | 165 | async function closeAfterNullYielded() { | 168 | 166 | const finallyMustCall = mustCall(); | 169 | | - const dataMustCall = mustCall(3); | 170 | 167 |
| 171 | 168 | function* generate() { | 172 | 169 | try { | @@ -180,10 +177,9 @@ async function closeAfterNullYielded() { | 180 | 177 |
| 181 | 178 | const stream = Readable.from(generate()); | 182 | 179 |
| 183 | | - stream.on('data', (chunk) => { | 184 | | - dataMustCall(); | 185 | | - strictEqual(chunk, 'a'); | 186 | | - }); | | 180 | + stream.on('data', mustCall((chunk) => { | | 181 | + assert.strictEqual(chunk, 'a'); | | 182 | + }, 3)); | 187 | 183 | } | 188 | 184 |
| 189 | 185 | Promise.all([ | |
Collapse file Copy file name to clipboard +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 | const { mustCall } = require('../common'); | 3 | 3 | const { Readable, Duplex } = require('stream'); | 4 | | -const { strictEqual } = require('assert'); | | 4 | +const assert = require('assert'); | 5 | 5 |
| 6 | 6 | function start(controller) { | 7 | 7 | controller.enqueue(new Uint8Array(1)); | @@ -10,7 +10,7 @@ function start(controller) { | 10 | 10 |
| 11 | 11 | Readable.fromWeb(new ReadableStream({ start })) | 12 | 12 | .on('data', mustCall((d) => { | 13 | | - strictEqual(d.length, 1); | | 13 | + assert.strictEqual(d.length, 1); | 14 | 14 | })) | 15 | 15 | .on('end', mustCall()) | 16 | 16 | .resume(); | @@ -20,7 +20,7 @@ Duplex.fromWeb({ | 20 | 20 | writable: new WritableStream({ write(chunk) {} }) | 21 | 21 | }) | 22 | 22 | .on('data', mustCall((d) => { | 23 | | - strictEqual(d.length, 1); | | 23 | + assert.strictEqual(d.length, 1); | 24 | 24 | })) | 25 | 25 | .on('end', mustCall()) | 26 | 26 | .resume(); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-readable-from.js +23-23Lines changed: 23 additions & 23 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | const { mustCall } = require('../common'); | 4 | 4 | const { once } = require('events'); | 5 | 5 | const { Readable } = require('stream'); | 6 | | -const { strictEqual, throws } = require('assert'); | | 6 | +const assert = require('assert'); | 7 | 7 | const common = require('../common'); | 8 | 8 |
| 9 | 9 | { | 10 | | - throws(() => { | | 10 | + assert.throws(() => { | 11 | 11 | Readable.from(null); | 12 | 12 | }, /ERR_INVALID_ARG_TYPE/); | 13 | 13 | } | @@ -24,7 +24,7 @@ async function toReadableBasicSupport() { | 24 | 24 | const expected = ['a', 'b', 'c']; | 25 | 25 |
| 26 | 26 | for await (const chunk of stream) { | 27 | | - strictEqual(chunk, expected.shift()); | | 27 | + assert.strictEqual(chunk, expected.shift()); | 28 | 28 | } | 29 | 29 | } | 30 | 30 |
| @@ -40,7 +40,7 @@ async function toReadableSyncIterator() { | 40 | 40 | const expected = ['a', 'b', 'c']; | 41 | 41 |
| 42 | 42 | for await (const chunk of stream) { | 43 | | - strictEqual(chunk, expected.shift()); | | 43 | + assert.strictEqual(chunk, expected.shift()); | 44 | 44 | } | 45 | 45 | } | 46 | 46 |
| @@ -56,7 +56,7 @@ async function toReadablePromises() { | 56 | 56 | const expected = ['a', 'b', 'c']; | 57 | 57 |
| 58 | 58 | for await (const chunk of stream) { | 59 | | - strictEqual(chunk, expected.shift()); | | 59 | + assert.strictEqual(chunk, expected.shift()); | 60 | 60 | } | 61 | 61 | } | 62 | 62 |
| @@ -66,7 +66,7 @@ async function toReadableString() { | 66 | 66 | const expected = ['abc']; | 67 | 67 |
| 68 | 68 | for await (const chunk of stream) { | 69 | | - strictEqual(chunk, expected.shift()); | | 69 | + assert.strictEqual(chunk, expected.shift()); | 70 | 70 | } | 71 | 71 | } | 72 | 72 |
| @@ -76,7 +76,7 @@ async function toReadableBuffer() { | 76 | 76 | const expected = ['abc']; | 77 | 77 |
| 78 | 78 | for await (const chunk of stream) { | 79 | | - strictEqual(chunk.toString(), expected.shift()); | | 79 | + assert.strictEqual(chunk.toString(), expected.shift()); | 80 | 80 | } | 81 | 81 | } | 82 | 82 |
| @@ -92,14 +92,14 @@ async function toReadableOnData() { | 92 | 92 | let iterations = 0; | 93 | 93 | const expected = ['a', 'b', 'c']; | 94 | 94 |
| 95 | | - stream.on('data', (chunk) => { | | 95 | + stream.on('data', common.mustCallAtLeast((chunk) => { | 96 | 96 | iterations++; | 97 | | - strictEqual(chunk, expected.shift()); | 98 | | - }); | | 97 | + assert.strictEqual(chunk, expected.shift()); | | 98 | + })); | 99 | 99 |
| 100 | 100 | await once(stream, 'end'); | 101 | 101 |
| 102 | | - strictEqual(iterations, 3); | | 102 | + assert.strictEqual(iterations, 3); | 103 | 103 | } | 104 | 104 |
| 105 | 105 | async function toReadableOnDataNonObject() { | @@ -114,15 +114,15 @@ async function toReadableOnDataNonObject() { | 114 | 114 | let iterations = 0; | 115 | 115 | const expected = ['a', 'b', 'c']; | 116 | 116 |
| 117 | | - stream.on('data', (chunk) => { | | 117 | + stream.on('data', common.mustCallAtLeast((chunk) => { | 118 | 118 | iterations++; | 119 | | - strictEqual(chunk instanceof Buffer, true); | 120 | | - strictEqual(chunk.toString(), expected.shift()); | 121 | | - }); | | 119 | + assert.strictEqual(chunk instanceof Buffer, true); | | 120 | + assert.strictEqual(chunk.toString(), expected.shift()); | | 121 | + })); | 122 | 122 |
| 123 | 123 | await once(stream, 'end'); | 124 | 124 |
| 125 | | - strictEqual(iterations, 3); | | 125 | + assert.strictEqual(iterations, 3); | 126 | 126 | } | 127 | 127 |
| 128 | 128 | async function destroysTheStreamWhenThrowing() { | @@ -135,8 +135,8 @@ async function destroysTheStreamWhenThrowing() { | 135 | 135 | stream.read(); | 136 | 136 |
| 137 | 137 | const [err] = await once(stream, 'error'); | 138 | | - strictEqual(err.message, 'kaboom'); | 139 | | - strictEqual(stream.destroyed, true); | | 138 | + assert.strictEqual(err.message, 'kaboom'); | | 139 | + assert.strictEqual(stream.destroyed, true); | 140 | 140 |
| 141 | 141 | } | 142 | 142 |
| @@ -162,7 +162,7 @@ async function asTransformStream() { | 162 | 162 | const expected = ['A', 'B', 'C']; | 163 | 163 |
| 164 | 164 | for await (const chunk of stream) { | 165 | | - strictEqual(chunk, expected.shift()); | | 165 | + assert.strictEqual(chunk, expected.shift()); | 166 | 166 | } | 167 | 167 | } | 168 | 168 |
| @@ -179,18 +179,18 @@ async function endWithError() { | 179 | 179 |
| 180 | 180 | try { | 181 | 181 | for await (const chunk of stream) { | 182 | | - strictEqual(chunk, expected.shift()); | | 182 | + assert.strictEqual(chunk, expected.shift()); | 183 | 183 | } | 184 | 184 | throw new Error(); | 185 | 185 | } catch (err) { | 186 | | - strictEqual(expected.length, 0); | 187 | | - strictEqual(err, 'Boum'); | | 186 | + assert.strictEqual(expected.length, 0); | | 187 | + assert.strictEqual(err, 'Boum'); | 188 | 188 | } | 189 | 189 | } | 190 | 190 |
| 191 | 191 | async function destroyingStreamWithErrorThrowsInGenerator() { | 192 | 192 | const validateError = common.mustCall((e) => { | 193 | | - strictEqual(e, 'Boum'); | | 193 | + assert.strictEqual(e, 'Boum'); | 194 | 194 | }); | 195 | 195 | async function* generate() { | 196 | 196 | try { | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-readline-interface.js +8-8Lines changed: 8 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -284,10 +284,10 @@ function assertCursorRowsAndCols(rli, rows, cols) { | 284 | 284 | const expectedLines = ['foo', 'bar', 'baz', 'bar', 'bat', 'bat']; | 285 | 285 | // ['foo', 'baz', 'bar', bat']; | 286 | 286 | let callCount = 0; | 287 | | - rli.on('line', (line) => { | | 287 | + rli.on('line', common.mustCallAtLeast((line) => { | 288 | 288 | assert.strictEqual(line, expectedLines[callCount]); | 289 | 289 | callCount++; | 290 | | - }); | | 290 | + })); | 291 | 291 | fi.emit('data', `${expectedLines.join('\n')}\n`); | 292 | 292 | assert.strictEqual(callCount, expectedLines.length); | 293 | 293 | fi.emit('keypress', '.', { name: 'up' }); // 'bat' | @@ -360,10 +360,10 @@ function assertCursorRowsAndCols(rli, rows, cols) { | 360 | 360 | }); | 361 | 361 | const expectedLines = ['foo', 'bar', 'baz', 'bar', 'bat', 'bat']; | 362 | 362 | let callCount = 0; | 363 | | - rli.on('line', (line) => { | | 363 | + rli.on('line', common.mustCallAtLeast((line) => { | 364 | 364 | assert.strictEqual(line, expectedLines[callCount]); | 365 | 365 | callCount++; | 366 | | - }); | | 366 | + })); | 367 | 367 | fi.emit('data', `${expectedLines.join('\n')}\n`); | 368 | 368 | assert.strictEqual(callCount, expectedLines.length); | 369 | 369 | fi.emit('keypress', '.', { name: 'up' }); // 'bat' | @@ -968,10 +968,10 @@ for (let i = 0; i < 12; i++) { | 968 | 968 | { | 969 | 969 | const [rli, fi] = getInterface({ terminal }); | 970 | 970 | let called = false; | 971 | | - rli.on('line', (line) => { | | 971 | + rli.on('line', common.mustCallAtLeast((line) => { | 972 | 972 | called = true; | 973 | 973 | assert.strictEqual(line, 'a'); | 974 | | - }); | | 974 | + })); | 975 | 975 | fi.emit('data', 'a'); | 976 | 976 | assert.ok(!called); | 977 | 977 | fi.emit('data', '\n'); | @@ -1020,10 +1020,10 @@ for (let i = 0; i < 12; i++) { | 1020 | 1020 | const buf = Buffer.from('☮', 'utf8'); | 1021 | 1021 | const [rli, fi] = getInterface({ terminal }); | 1022 | 1022 | let callCount = 0; | 1023 | | - rli.on('line', (line) => { | | 1023 | + rli.on('line', common.mustCallAtLeast((line) => { | 1024 | 1024 | callCount++; | 1025 | 1025 | assert.strictEqual(line, buf.toString('utf8')); | 1026 | | - }); | | 1026 | + })); | 1027 | 1027 | for (const i of buf) { | 1028 | 1028 | fi.emit('data', Buffer.from([i])); | 1029 | 1029 | } | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-readline-keys.js +9-9Lines changed: 9 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -49,9 +49,9 @@ function addTest(sequences, expectedKeys) { | 49 | 49 | // (addKeyIntervalTest(..)(noop)))() | 50 | 50 | // where noop is a terminal function(() => {}). | 51 | 51 |
| 52 | | -const addKeyIntervalTest = (sequences, expectedKeys, interval = 550, | 53 | | - assertDelay = 550) => { | 54 | | - const fn = common.mustCall((next) => () => { | | 52 | +function addKeyIntervalTest(sequences, expectedKeys, interval = 550, | | 53 | + assertDelay = 550) { | | 54 | + const fn = common.mustCall((next) => common.mustCall(() => { | 55 | 55 |
| 56 | 56 | if (!Array.isArray(sequences)) { | 57 | 57 | sequences = [ sequences ]; | @@ -66,21 +66,21 @@ const addKeyIntervalTest = (sequences, expectedKeys, interval = 550, | 66 | 66 | const keys = []; | 67 | 67 | fi.on('keypress', (s, k) => keys.push(k)); | 68 | 68 |
| 69 | | - const emitKeys = ([head, ...tail]) => { | | 69 | + const emitKeys = common.mustCallAtLeast(([head, ...tail]) => { | 70 | 70 | if (head) { | 71 | 71 | fi.write(head); | 72 | 72 | setTimeout(() => emitKeys(tail), interval); | 73 | 73 | } else { | 74 | | - setTimeout(() => { | | 74 | + setTimeout(common.mustCall(() => { | 75 | 75 | next(); | 76 | 76 | assert.deepStrictEqual(keys, expectedKeys); | 77 | | - }, assertDelay); | | 77 | + }), assertDelay); | 78 | 78 | } | 79 | | - }; | | 79 | + }); | 80 | 80 | emitKeys(sequences); | 81 | | - }); | | 81 | + })); | 82 | 82 | return fn; | 83 | | -}; | | 83 | +} | 84 | 84 |
| 85 | 85 | // Regular alphanumerics | 86 | 86 | addTest('io.JS', [ | |
|