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 bc41acf

Browse filesBrowse files
committed
test: ensure assertions are reached on more tests
PR-URL: #60500 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
1 parent 6ddee4a commit bc41acf
Copy full SHA for bc41acf
Expand file treeCollapse file tree

14 files changed

+109
-153
lines changed
Open diff view settings
Collapse file

‎test/eslint.config_partial.mjs‎

Copy file name to clipboardExpand all lines: test/eslint.config_partial.mjs
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ export default [
191191
'wasm-allocation',
192192
'wpt',
193193
].join(',')}}/**/*.{js,mjs,cjs}`,
194+
`test/parallel/test-{${
195+
// 0x61 is code for 'a', this generates a string enumerating latin letters: 'z*,y*,…'
196+
Array.from({ length: 2 }, (_, i) => String.fromCharCode(0x61 + 25 - i, 42)).join(',')
197+
}}.{js,mjs,cjs}`,
194198
],
195199
rules: {
196200
'node-core/must-call-assert': 'error',
Collapse file

‎test/parallel/test-zlib-brotli-16GB.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-zlib-brotli-16GB.js
+2-2Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎test/parallel/test-zlib-brotli-kmaxlength-rangeerror.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-zlib-brotli-kmaxlength-rangeerror.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33

44
// This test ensures that zlib throws a RangeError if the final buffer needs to
55
// be larger than kMaxLength and concatenation fails.
@@ -18,9 +18,9 @@ buffer.kMaxLength = oldkMaxLength;
1818
const encoded = Buffer.from('G38A+CXCIrFAIAM=', 'base64');
1919

2020
// Async
21-
zlib.brotliDecompress(encoded, function(err) {
21+
zlib.brotliDecompress(encoded, common.mustCall((err) => {
2222
assert.ok(err instanceof RangeError);
23-
});
23+
}));
2424

2525
// Sync
2626
assert.throws(function() {
Collapse file

‎test/parallel/test-zlib-from-concatenated-gzip.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-zlib-from-concatenated-gzip.js
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ const pmmResultBuffers = [];
4747

4848
fs.createReadStream(pmmFileGz)
4949
.pipe(zlib.createGunzip())
50-
.on('error', (err) => {
51-
assert.ifError(err);
52-
})
50+
.on('error', common.mustNotCall())
5351
.on('data', (data) => pmmResultBuffers.push(data))
5452
.on('finish', common.mustCall(() => {
5553
// Result should match original random garbage
@@ -61,9 +59,7 @@ fs.createReadStream(pmmFileGz)
6159
const resultBuffers = [];
6260

6361
const unzip = zlib.createGunzip()
64-
.on('error', (err) => {
65-
assert.ifError(err);
66-
})
62+
.on('error', common.mustNotCall())
6763
.on('data', (data) => resultBuffers.push(data))
6864
.on('finish', common.mustCall(() => {
6965
assert.strictEqual(
Collapse file

‎test/parallel/test-zlib-kmaxlength-rangeerror.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-zlib-kmaxlength-rangeerror.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33

44
// This test ensures that zlib throws a RangeError if the final buffer needs to
55
// be larger than kMaxLength and concatenation fails.
@@ -18,9 +18,9 @@ buffer.kMaxLength = oldkMaxLength;
1818
const encoded = Buffer.from('H4sIAAAAAAAAA0tMHFgAAIw2K/GAAAAA', 'base64');
1919

2020
// Async
21-
zlib.gunzip(encoded, function(err) {
21+
zlib.gunzip(encoded, common.mustCall((err) => {
2222
assert.ok(err instanceof RangeError);
23-
});
23+
}));
2424

2525
// Sync
2626
assert.throws(function() {
Collapse file

‎test/parallel/test-zlib-maxOutputLength.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-zlib-maxOutputLength.js
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ assert.throws(function() {
1717
}, RangeError);
1818

1919
// Async
20-
zlib.brotliDecompress(encoded, { maxOutputLength: 256 }, function(err) {
21-
assert.strictEqual(err, null);
22-
});
20+
zlib.brotliDecompress(encoded, { maxOutputLength: 256 }, common.mustSucceed());
2321

2422
// Sync
2523
zlib.brotliDecompressSync(encoded, { maxOutputLength: 256 });
Collapse file

‎test/parallel/test-zlib-reset-before-write.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-zlib-reset-before-write.js
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ for (const fn of [
2121

2222
const output = [];
2323
inflate
24-
.on('error', (err) => {
25-
assert.ifError(err);
26-
})
24+
.on('error', common.mustNotCall())
2725
.on('data', (chunk) => output.push(chunk))
2826
.on('end', common.mustCall(
2927
() => assert.strictEqual(Buffer.concat(output).toString(), 'abc')));
Collapse file

‎test/parallel/test-zlib-truncated.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-zlib-truncated.js
+9-12Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22
// Tests zlib streams with truncated compressed input
33

4-
require('../common');
4+
const common = require('../common');
55
const assert = require('assert');
66
const zlib = require('zlib');
77

@@ -23,8 +23,7 @@ const errMessage = /unexpected end of file/;
2323
{ comp: 'deflate', decomp: 'inflate', decompSync: 'inflateSync' },
2424
{ comp: 'deflateRaw', decomp: 'inflateRaw', decompSync: 'inflateRawSync' },
2525
].forEach(function(methods) {
26-
zlib[methods.comp](inputString, function(err, compressed) {
27-
assert.ifError(err);
26+
zlib[methods.comp](inputString, common.mustSucceed((compressed) => {
2827
const truncated = compressed.slice(0, compressed.length / 2);
2928
const toUTF8 = (buffer) => buffer.toString('utf-8');
3029

@@ -33,20 +32,19 @@ const errMessage = /unexpected end of file/;
3332
assert.strictEqual(toUTF8(decompressed), inputString);
3433

3534
// async sanity
36-
zlib[methods.decomp](compressed, function(err, result) {
37-
assert.ifError(err);
35+
zlib[methods.decomp](compressed, common.mustSucceed((result) => {
3836
assert.strictEqual(toUTF8(result), inputString);
39-
});
37+
}));
4038

4139
// Sync truncated input test
4240
assert.throws(function() {
4341
zlib[methods.decompSync](truncated);
4442
}, errMessage);
4543

4644
// Async truncated input test
47-
zlib[methods.decomp](truncated, function(err, result) {
45+
zlib[methods.decomp](truncated, common.mustCall((err) => {
4846
assert.match(err.message, errMessage);
49-
});
47+
}));
5048

5149
const syncFlushOpt = { finishFlush: zlib.constants.Z_SYNC_FLUSH };
5250

@@ -55,10 +53,9 @@ const errMessage = /unexpected end of file/;
5553
assert.strictEqual(result, inputString.slice(0, result.length));
5654

5755
// Async truncated input test, finishFlush = Z_SYNC_FLUSH
58-
zlib[methods.decomp](truncated, syncFlushOpt, function(err, decompressed) {
59-
assert.ifError(err);
56+
zlib[methods.decomp](truncated, syncFlushOpt, common.mustSucceed((decompressed) => {
6057
const result = toUTF8(decompressed);
6158
assert.strictEqual(result, inputString.slice(0, result.length));
62-
});
63-
});
59+
}));
60+
}));
6461
});
Collapse file
+7-16Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
11
'use strict';
22
require('../common');
3-
const assert = require('assert').strict;
3+
const assert = require('assert');
44
const test = require('node:test');
55
const { DecompressionStream } = require('stream/web');
66

7-
async function expectTypeError(promise) {
8-
let threw = false;
9-
try {
10-
await promise;
11-
} catch (err) {
12-
threw = true;
13-
assert(err instanceof TypeError, `Expected TypeError, got ${err}`);
14-
}
15-
assert(threw, 'Expected promise to reject');
16-
}
17-
187
test('DecompressStream deflat emits error on trailing data', async () => {
198
const valid = new Uint8Array([120, 156, 75, 4, 0, 0, 98, 0, 98]); // deflate('a')
209
const empty = new Uint8Array(1);
2110
const invalid = new Uint8Array([...valid, ...empty]);
2211
const double = new Uint8Array([...valid, ...valid]);
2312

2413
for (const chunk of [[invalid], [valid, empty], [valid, valid], [valid, double]]) {
25-
await expectTypeError(
14+
await assert.rejects(
2615
Array.fromAsync(
2716
new Blob([chunk]).stream().pipeThrough(new DecompressionStream('deflate'))
28-
)
17+
),
18+
{ name: 'TypeError' },
2919
);
3020
}
3121
});
@@ -37,10 +27,11 @@ test('DecompressStream gzip emits error on trailing data', async () => {
3727
const invalid = new Uint8Array([...valid, ...empty]);
3828
const double = new Uint8Array([...valid, ...valid]);
3929
for (const chunk of [[invalid], [valid, empty], [valid, valid], [double]]) {
40-
await expectTypeError(
30+
await assert.rejects(
4131
Array.fromAsync(
4232
new Blob([chunk]).stream().pipeThrough(new DecompressionStream('gzip'))
43-
)
33+
),
34+
{ name: 'TypeError' },
4435
);
4536
}
4637
});
Collapse file
+20-28Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,30 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
44

55
const assert = require('node:assert');
66
const zlib = require('node:zlib');
7-
const { test } = require('node:test');
87

9-
test('zlib should unzip one byte chunks', async () => {
10-
const { promise, resolve } = Promise.withResolvers();
11-
const data = Buffer.concat([
12-
zlib.gzipSync('abc'),
13-
zlib.gzipSync('def'),
14-
]);
8+
const data = Buffer.concat([
9+
zlib.gzipSync('abc'),
10+
zlib.gzipSync('def'),
11+
]);
1512

16-
const resultBuffers = [];
13+
const resultBuffers = [];
1714

18-
const unzip = zlib.createUnzip()
19-
.on('error', (err) => {
20-
assert.ifError(err);
21-
})
22-
.on('data', (data) => resultBuffers.push(data))
23-
.on('finish', () => {
24-
const unzipped = Buffer.concat(resultBuffers).toString();
25-
assert.strictEqual(unzipped, 'abcdef',
26-
`'${unzipped}' should match 'abcdef' after zipping ` +
27-
'and unzipping');
28-
resolve();
29-
});
15+
const unzip = zlib.createUnzip()
16+
.on('error', common.mustNotCall())
17+
.on('data', (data) => resultBuffers.push(data))
18+
.on('finish', common.mustCall(() => {
19+
const unzipped = Buffer.concat(resultBuffers).toString();
20+
assert.strictEqual(unzipped, 'abcdef',
21+
`'${unzipped}' should match 'abcdef' after zipping ` +
22+
'and unzipping');
23+
}));
3024

31-
for (let i = 0; i < data.length; i++) {
32-
// Write each single byte individually.
33-
unzip.write(Buffer.from([data[i]]));
34-
}
25+
for (let i = 0; i < data.length; i++) {
26+
// Write each single byte individually.
27+
unzip.write(Buffer.from([data[i]]));
28+
}
3529

36-
unzip.end();
37-
await promise;
38-
});
30+
unzip.end();

0 commit comments

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