Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5ee02c7

Browse filesBrowse files
committed
test: ensure assertions are reached on more tests
PR-URL: #60763 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 141fb82 commit 5ee02c7
Copy full SHA for 5ee02c7

53 files changed

+283-300Lines changed: 283 additions & 300 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/eslint.config_partial.mjs‎

Copy file name to clipboardExpand all lines: test/eslint.config_partial.mjs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export default [
203203
`test/parallel/test-{${
204204
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'a*,b*,…'
205205
Array.from({ length: 13 }, (_, i) => String.fromCharCode(0x61 + i, 42)).join(',')
206-
},n*,${
206+
},n*,r*,${
207207
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
208208
Array.from({ length: 8 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')
209209
}}.{js,mjs,cjs}`,
Collapse file

‎test/parallel/test-readable-from-iterator-closing.js‎

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 numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const { mustCall, mustNotCall } = require('../common');
44
const { Readable } = require('stream');
5-
const { strictEqual } = require('assert');
5+
const assert = require('assert');
66

77
async function asyncSupport() {
88
const finallyMustCall = mustCall();
@@ -20,7 +20,7 @@ async function asyncSupport() {
2020

2121
for await (const chunk of stream) {
2222
bodyMustCall();
23-
strictEqual(chunk, 'a');
23+
assert.strictEqual(chunk, 'a');
2424
break;
2525
}
2626
}
@@ -41,7 +41,7 @@ async function syncSupport() {
4141

4242
for await (const chunk of stream) {
4343
bodyMustCall();
44-
strictEqual(chunk, 'a');
44+
assert.strictEqual(chunk, 'a');
4545
break;
4646
}
4747
}
@@ -66,7 +66,7 @@ async function syncPromiseSupport() {
6666

6767
for await (const chunk of stream) {
6868
bodyMustCall();
69-
strictEqual(chunk, 'a');
69+
assert.strictEqual(chunk, 'a');
7070
break;
7171
}
7272
}
@@ -130,7 +130,6 @@ async function noReturnAfterThrow() {
130130

131131
async function closeStreamWhileNextIsPending() {
132132
const finallyMustCall = mustCall();
133-
const dataMustCall = mustCall();
134133

135134
let resolveDestroy;
136135
const destroyed =
@@ -153,10 +152,9 @@ async function closeStreamWhileNextIsPending() {
153152

154153
const stream = Readable.from(infiniteGenerate());
155154

156-
stream.on('data', (data) => {
157-
dataMustCall();
158-
strictEqual(data, 'a');
159-
});
155+
stream.on('data', mustCall((data) => {
156+
assert.strictEqual(data, 'a');
157+
}));
160158

161159
yielded.then(() => {
162160
stream.destroy();
@@ -166,7 +164,6 @@ async function closeStreamWhileNextIsPending() {
166164

167165
async function closeAfterNullYielded() {
168166
const finallyMustCall = mustCall();
169-
const dataMustCall = mustCall(3);
170167

171168
function* generate() {
172169
try {
@@ -180,10 +177,9 @@ async function closeAfterNullYielded() {
180177

181178
const stream = Readable.from(generate());
182179

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));
187183
}
188184

189185
Promise.all([
Collapse file
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
const { mustCall } = require('../common');
33
const { Readable, Duplex } = require('stream');
4-
const { strictEqual } = require('assert');
4+
const assert = require('assert');
55

66
function start(controller) {
77
controller.enqueue(new Uint8Array(1));
@@ -10,7 +10,7 @@ function start(controller) {
1010

1111
Readable.fromWeb(new ReadableStream({ start }))
1212
.on('data', mustCall((d) => {
13-
strictEqual(d.length, 1);
13+
assert.strictEqual(d.length, 1);
1414
}))
1515
.on('end', mustCall())
1616
.resume();
@@ -20,7 +20,7 @@ Duplex.fromWeb({
2020
writable: new WritableStream({ write(chunk) {} })
2121
})
2222
.on('data', mustCall((d) => {
23-
strictEqual(d.length, 1);
23+
assert.strictEqual(d.length, 1);
2424
}))
2525
.on('end', mustCall())
2626
.resume();
Collapse file

‎test/parallel/test-readable-from.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-readable-from.js
+23-23Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
const { mustCall } = require('../common');
44
const { once } = require('events');
55
const { Readable } = require('stream');
6-
const { strictEqual, throws } = require('assert');
6+
const assert = require('assert');
77
const common = require('../common');
88

99
{
10-
throws(() => {
10+
assert.throws(() => {
1111
Readable.from(null);
1212
}, /ERR_INVALID_ARG_TYPE/);
1313
}
@@ -24,7 +24,7 @@ async function toReadableBasicSupport() {
2424
const expected = ['a', 'b', 'c'];
2525

2626
for await (const chunk of stream) {
27-
strictEqual(chunk, expected.shift());
27+
assert.strictEqual(chunk, expected.shift());
2828
}
2929
}
3030

@@ -40,7 +40,7 @@ async function toReadableSyncIterator() {
4040
const expected = ['a', 'b', 'c'];
4141

4242
for await (const chunk of stream) {
43-
strictEqual(chunk, expected.shift());
43+
assert.strictEqual(chunk, expected.shift());
4444
}
4545
}
4646

@@ -56,7 +56,7 @@ async function toReadablePromises() {
5656
const expected = ['a', 'b', 'c'];
5757

5858
for await (const chunk of stream) {
59-
strictEqual(chunk, expected.shift());
59+
assert.strictEqual(chunk, expected.shift());
6060
}
6161
}
6262

@@ -66,7 +66,7 @@ async function toReadableString() {
6666
const expected = ['abc'];
6767

6868
for await (const chunk of stream) {
69-
strictEqual(chunk, expected.shift());
69+
assert.strictEqual(chunk, expected.shift());
7070
}
7171
}
7272

@@ -76,7 +76,7 @@ async function toReadableBuffer() {
7676
const expected = ['abc'];
7777

7878
for await (const chunk of stream) {
79-
strictEqual(chunk.toString(), expected.shift());
79+
assert.strictEqual(chunk.toString(), expected.shift());
8080
}
8181
}
8282

@@ -92,14 +92,14 @@ async function toReadableOnData() {
9292
let iterations = 0;
9393
const expected = ['a', 'b', 'c'];
9494

95-
stream.on('data', (chunk) => {
95+
stream.on('data', common.mustCallAtLeast((chunk) => {
9696
iterations++;
97-
strictEqual(chunk, expected.shift());
98-
});
97+
assert.strictEqual(chunk, expected.shift());
98+
}));
9999

100100
await once(stream, 'end');
101101

102-
strictEqual(iterations, 3);
102+
assert.strictEqual(iterations, 3);
103103
}
104104

105105
async function toReadableOnDataNonObject() {
@@ -114,15 +114,15 @@ async function toReadableOnDataNonObject() {
114114
let iterations = 0;
115115
const expected = ['a', 'b', 'c'];
116116

117-
stream.on('data', (chunk) => {
117+
stream.on('data', common.mustCallAtLeast((chunk) => {
118118
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+
}));
122122

123123
await once(stream, 'end');
124124

125-
strictEqual(iterations, 3);
125+
assert.strictEqual(iterations, 3);
126126
}
127127

128128
async function destroysTheStreamWhenThrowing() {
@@ -135,8 +135,8 @@ async function destroysTheStreamWhenThrowing() {
135135
stream.read();
136136

137137
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);
140140

141141
}
142142

@@ -162,7 +162,7 @@ async function asTransformStream() {
162162
const expected = ['A', 'B', 'C'];
163163

164164
for await (const chunk of stream) {
165-
strictEqual(chunk, expected.shift());
165+
assert.strictEqual(chunk, expected.shift());
166166
}
167167
}
168168

@@ -179,18 +179,18 @@ async function endWithError() {
179179

180180
try {
181181
for await (const chunk of stream) {
182-
strictEqual(chunk, expected.shift());
182+
assert.strictEqual(chunk, expected.shift());
183183
}
184184
throw new Error();
185185
} catch (err) {
186-
strictEqual(expected.length, 0);
187-
strictEqual(err, 'Boum');
186+
assert.strictEqual(expected.length, 0);
187+
assert.strictEqual(err, 'Boum');
188188
}
189189
}
190190

191191
async function destroyingStreamWithErrorThrowsInGenerator() {
192192
const validateError = common.mustCall((e) => {
193-
strictEqual(e, 'Boum');
193+
assert.strictEqual(e, 'Boum');
194194
});
195195
async function* generate() {
196196
try {
Collapse file

‎test/parallel/test-readline-interface.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-readline-interface.js
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,10 @@ function assertCursorRowsAndCols(rli, rows, cols) {
284284
const expectedLines = ['foo', 'bar', 'baz', 'bar', 'bat', 'bat'];
285285
// ['foo', 'baz', 'bar', bat'];
286286
let callCount = 0;
287-
rli.on('line', (line) => {
287+
rli.on('line', common.mustCallAtLeast((line) => {
288288
assert.strictEqual(line, expectedLines[callCount]);
289289
callCount++;
290-
});
290+
}));
291291
fi.emit('data', `${expectedLines.join('\n')}\n`);
292292
assert.strictEqual(callCount, expectedLines.length);
293293
fi.emit('keypress', '.', { name: 'up' }); // 'bat'
@@ -360,10 +360,10 @@ function assertCursorRowsAndCols(rli, rows, cols) {
360360
});
361361
const expectedLines = ['foo', 'bar', 'baz', 'bar', 'bat', 'bat'];
362362
let callCount = 0;
363-
rli.on('line', (line) => {
363+
rli.on('line', common.mustCallAtLeast((line) => {
364364
assert.strictEqual(line, expectedLines[callCount]);
365365
callCount++;
366-
});
366+
}));
367367
fi.emit('data', `${expectedLines.join('\n')}\n`);
368368
assert.strictEqual(callCount, expectedLines.length);
369369
fi.emit('keypress', '.', { name: 'up' }); // 'bat'
@@ -968,10 +968,10 @@ for (let i = 0; i < 12; i++) {
968968
{
969969
const [rli, fi] = getInterface({ terminal });
970970
let called = false;
971-
rli.on('line', (line) => {
971+
rli.on('line', common.mustCallAtLeast((line) => {
972972
called = true;
973973
assert.strictEqual(line, 'a');
974-
});
974+
}));
975975
fi.emit('data', 'a');
976976
assert.ok(!called);
977977
fi.emit('data', '\n');
@@ -1020,10 +1020,10 @@ for (let i = 0; i < 12; i++) {
10201020
const buf = Buffer.from('☮', 'utf8');
10211021
const [rli, fi] = getInterface({ terminal });
10221022
let callCount = 0;
1023-
rli.on('line', (line) => {
1023+
rli.on('line', common.mustCallAtLeast((line) => {
10241024
callCount++;
10251025
assert.strictEqual(line, buf.toString('utf8'));
1026-
});
1026+
}));
10271027
for (const i of buf) {
10281028
fi.emit('data', Buffer.from([i]));
10291029
}
Collapse file

‎test/parallel/test-readline-keys.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-readline-keys.js
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ function addTest(sequences, expectedKeys) {
4949
// (addKeyIntervalTest(..)(noop)))()
5050
// where noop is a terminal function(() => {}).
5151

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(() => {
5555

5656
if (!Array.isArray(sequences)) {
5757
sequences = [ sequences ];
@@ -66,21 +66,21 @@ const addKeyIntervalTest = (sequences, expectedKeys, interval = 550,
6666
const keys = [];
6767
fi.on('keypress', (s, k) => keys.push(k));
6868

69-
const emitKeys = ([head, ...tail]) => {
69+
const emitKeys = common.mustCallAtLeast(([head, ...tail]) => {
7070
if (head) {
7171
fi.write(head);
7272
setTimeout(() => emitKeys(tail), interval);
7373
} else {
74-
setTimeout(() => {
74+
setTimeout(common.mustCall(() => {
7575
next();
7676
assert.deepStrictEqual(keys, expectedKeys);
77-
}, assertDelay);
77+
}), assertDelay);
7878
}
79-
};
79+
});
8080
emitKeys(sequences);
81-
});
81+
}));
8282
return fn;
83-
};
83+
}
8484

8585
// Regular alphanumerics
8686
addTest('io.JS', [

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.