| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -191,6 +191,10 @@ export default [ | |||
| 191 | 191 | 'wasm-allocation', | |
| 192 | 192 | 'wpt', | |
| 193 | 193 | ].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}`, | ||
| 194 | 198 | ], | |
| 195 | 199 | rules: { | |
| 196 | 200 | 'node-core/must-call-assert': 'error', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | ||
| 4 | 4 | // This test ensures that zlib throws a RangeError if the final buffer needs to | |
| 5 | 5 | // be larger than kMaxLength and concatenation fails. | |
@@ -18,9 +18,9 @@ buffer.kMaxLength = oldkMaxLength; | |||
| 18 | 18 | const encoded = Buffer.from('G38A+CXCIrFAIAM=', 'base64'); | |
| 19 | 19 | ||
| 20 | 20 | // Async | |
| 21 | - zlib.brotliDecompress(encoded, function(err) { | ||
| 21 | + zlib.brotliDecompress(encoded, common.mustCall((err) => { | ||
| 22 | 22 | assert.ok(err instanceof RangeError); | |
| 23 | - }); | ||
| 23 | + })); | ||
| 24 | 24 | ||
| 25 | 25 | // Sync | |
| 26 | 26 | assert.throws(function() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,9 +47,7 @@ const pmmResultBuffers = []; | |||
| 47 | 47 | ||
| 48 | 48 | fs.createReadStream(pmmFileGz) | |
| 49 | 49 | .pipe(zlib.createGunzip()) | |
| 50 | - .on('error', (err) => { | ||
| 51 | - assert.ifError(err); | ||
| 52 | - }) | ||
| 50 | + .on('error', common.mustNotCall()) | ||
| 53 | 51 | .on('data', (data) => pmmResultBuffers.push(data)) | |
| 54 | 52 | .on('finish', common.mustCall(() => { | |
| 55 | 53 | // Result should match original random garbage | |
@@ -61,9 +59,7 @@ fs.createReadStream(pmmFileGz) | |||
| 61 | 59 | const resultBuffers = []; | |
| 62 | 60 | ||
| 63 | 61 | const unzip = zlib.createGunzip() | |
| 64 | - .on('error', (err) => { | ||
| 65 | - assert.ifError(err); | ||
| 66 | - }) | ||
| 62 | + .on('error', common.mustNotCall()) | ||
| 67 | 63 | .on('data', (data) => resultBuffers.push(data)) | |
| 68 | 64 | .on('finish', common.mustCall(() => { | |
| 69 | 65 | assert.strictEqual( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | - require('../common'); | ||
| 2 | + const common = require('../common'); | ||
| 3 | 3 | ||
| 4 | 4 | // This test ensures that zlib throws a RangeError if the final buffer needs to | |
| 5 | 5 | // be larger than kMaxLength and concatenation fails. | |
@@ -18,9 +18,9 @@ buffer.kMaxLength = oldkMaxLength; | |||
| 18 | 18 | const encoded = Buffer.from('H4sIAAAAAAAAA0tMHFgAAIw2K/GAAAAA', 'base64'); | |
| 19 | 19 | ||
| 20 | 20 | // Async | |
| 21 | - zlib.gunzip(encoded, function(err) { | ||
| 21 | + zlib.gunzip(encoded, common.mustCall((err) => { | ||
| 22 | 22 | assert.ok(err instanceof RangeError); | |
| 23 | - }); | ||
| 23 | + })); | ||
| 24 | 24 | ||
| 25 | 25 | // Sync | |
| 26 | 26 | assert.throws(function() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,9 +17,7 @@ assert.throws(function() { | |||
| 17 | 17 | }, RangeError); | |
| 18 | 18 | ||
| 19 | 19 | // Async | |
| 20 | - zlib.brotliDecompress(encoded, { maxOutputLength: 256 }, function(err) { | ||
| 21 | - assert.strictEqual(err, null); | ||
| 22 | - }); | ||
| 20 | + zlib.brotliDecompress(encoded, { maxOutputLength: 256 }, common.mustSucceed()); | ||
| 23 | 21 | ||
| 24 | 22 | // Sync | |
| 25 | 23 | zlib.brotliDecompressSync(encoded, { maxOutputLength: 256 }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,9 +21,7 @@ for (const fn of [ | |||
| 21 | 21 | ||
| 22 | 22 | const output = []; | |
| 23 | 23 | inflate | |
| 24 | - .on('error', (err) => { | ||
| 25 | - assert.ifError(err); | ||
| 26 | - }) | ||
| 24 | + .on('error', common.mustNotCall()) | ||
| 27 | 25 | .on('data', (chunk) => output.push(chunk)) | |
| 28 | 26 | .on('end', common.mustCall( | |
| 29 | 27 | () => assert.strictEqual(Buffer.concat(output).toString(), 'abc'))); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,7 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | // Tests zlib streams with truncated compressed input | |
| 3 | 3 | ||
| 4 | - require('../common'); | ||
| 4 | + const common = require('../common'); | ||
| 5 | 5 | const assert = require('assert'); | |
| 6 | 6 | const zlib = require('zlib'); | |
| 7 | 7 | ||
@@ -23,8 +23,7 @@ const errMessage = /unexpected end of file/; | |||
| 23 | 23 | { comp: 'deflate', decomp: 'inflate', decompSync: 'inflateSync' }, | |
| 24 | 24 | { comp: 'deflateRaw', decomp: 'inflateRaw', decompSync: 'inflateRawSync' }, | |
| 25 | 25 | ].forEach(function(methods) { | |
| 26 | - zlib[methods.comp](inputString, function(err, compressed) { | ||
| 27 | - assert.ifError(err); | ||
| 26 | + zlib[methods.comp](inputString, common.mustSucceed((compressed) => { | ||
| 28 | 27 | const truncated = compressed.slice(0, compressed.length / 2); | |
| 29 | 28 | const toUTF8 = (buffer) => buffer.toString('utf-8'); | |
| 30 | 29 | ||
@@ -33,20 +32,19 @@ const errMessage = /unexpected end of file/; | |||
| 33 | 32 | assert.strictEqual(toUTF8(decompressed), inputString); | |
| 34 | 33 | ||
| 35 | 34 | // async sanity | |
| 36 | - zlib[methods.decomp](compressed, function(err, result) { | ||
| 37 | - assert.ifError(err); | ||
| 35 | + zlib[methods.decomp](compressed, common.mustSucceed((result) => { | ||
| 38 | 36 | assert.strictEqual(toUTF8(result), inputString); | |
| 39 | - }); | ||
| 37 | + })); | ||
| 40 | 38 | ||
| 41 | 39 | // Sync truncated input test | |
| 42 | 40 | assert.throws(function() { | |
| 43 | 41 | zlib[methods.decompSync](truncated); | |
| 44 | 42 | }, errMessage); | |
| 45 | 43 | ||
| 46 | 44 | // Async truncated input test | |
| 47 | - zlib[methods.decomp](truncated, function(err, result) { | ||
| 45 | + zlib[methods.decomp](truncated, common.mustCall((err) => { | ||
| 48 | 46 | assert.match(err.message, errMessage); | |
| 49 | - }); | ||
| 47 | + })); | ||
| 50 | 48 | ||
| 51 | 49 | const syncFlushOpt = { finishFlush: zlib.constants.Z_SYNC_FLUSH }; | |
| 52 | 50 | ||
@@ -55,10 +53,9 @@ const errMessage = /unexpected end of file/; | |||
| 55 | 53 | assert.strictEqual(result, inputString.slice(0, result.length)); | |
| 56 | 54 | ||
| 57 | 55 | // 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) => { | ||
| 60 | 57 | const result = toUTF8(decompressed); | |
| 61 | 58 | assert.strictEqual(result, inputString.slice(0, result.length)); | |
| 62 | - }); | ||
| 63 | - }); | ||
| 59 | + })); | ||
| 60 | + })); | ||
| 64 | 61 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,31 +1,21 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | require('../common'); | |
| 3 | - const assert = require('assert').strict; | ||
| 3 | + const assert = require('assert'); | ||
| 4 | 4 | const test = require('node:test'); | |
| 5 | 5 | const { DecompressionStream } = require('stream/web'); | |
| 6 | 6 | ||
| 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 | - | ||
| 18 | 7 | test('DecompressStream deflat emits error on trailing data', async () => { | |
| 19 | 8 | const valid = new Uint8Array([120, 156, 75, 4, 0, 0, 98, 0, 98]); // deflate('a') | |
| 20 | 9 | const empty = new Uint8Array(1); | |
| 21 | 10 | const invalid = new Uint8Array([...valid, ...empty]); | |
| 22 | 11 | const double = new Uint8Array([...valid, ...valid]); | |
| 23 | 12 | ||
| 24 | 13 | for (const chunk of [[invalid], [valid, empty], [valid, valid], [valid, double]]) { | |
| 25 | - await expectTypeError( | ||
| 14 | + await assert.rejects( | ||
| 26 | 15 | Array.fromAsync( | |
| 27 | 16 | new Blob([chunk]).stream().pipeThrough(new DecompressionStream('deflate')) | |
| 28 | - ) | ||
| 17 | + ), | ||
| 18 | + { name: 'TypeError' }, | ||
| 29 | 19 | ); | |
| 30 | 20 | } | |
| 31 | 21 | }); | |
@@ -37,10 +27,11 @@ test('DecompressStream gzip emits error on trailing data', async () => { | |||
| 37 | 27 | const invalid = new Uint8Array([...valid, ...empty]); | |
| 38 | 28 | const double = new Uint8Array([...valid, ...valid]); | |
| 39 | 29 | for (const chunk of [[invalid], [valid, empty], [valid, valid], [double]]) { | |
| 40 | - await expectTypeError( | ||
| 30 | + await assert.rejects( | ||
| 41 | 31 | Array.fromAsync( | |
| 42 | 32 | new Blob([chunk]).stream().pipeThrough(new DecompressionStream('gzip')) | |
| 43 | - ) | ||
| 33 | + ), | ||
| 34 | + { name: 'TypeError' }, | ||
| 44 | 35 | ); | |
| 45 | 36 | } | |
| 46 | 37 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,38 +1,30 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | - require('../common'); | ||
| 3 | + const common = require('../common'); | ||
| 4 | 4 | ||
| 5 | 5 | const assert = require('node:assert'); | |
| 6 | 6 | const zlib = require('node:zlib'); | |
| 7 | - const { test } = require('node:test'); | ||
| 8 | 7 | ||
| 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 | + ]); | ||
| 15 | 12 | ||
| 16 | - const resultBuffers = []; | ||
| 13 | + const resultBuffers = []; | ||
| 17 | 14 | ||
| 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 | + })); | ||
| 30 | 24 | ||
| 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 | + } | ||
| 35 | 29 | ||
| 36 | - unzip.end(); | ||
| 37 | - await promise; | ||
| 38 | - }); | ||
| 30 | + unzip.end(); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments