-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: migrate tests to use node:test module for better test structure
- Loading branch information
Mert Can Altin
committed
Nov 27, 2024
1 parent
585f7bc
commit bda6cfd
Showing
1 changed file
with
32 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,36 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const zlib = require('zlib'); | ||
const { inspect, promisify } = require('util'); | ||
const assert = require('assert'); | ||
|
||
require('../common'); | ||
|
||
const { test } = require('node:test'); | ||
const zlib = require('node:zlib'); | ||
const { inspect, promisify } = require('node:util'); | ||
const assert = require('node:assert'); | ||
|
||
const emptyBuffer = Buffer.alloc(0); | ||
|
||
(async function() { | ||
for (const [ compress, decompress, method ] of [ | ||
[ zlib.deflateRawSync, zlib.inflateRawSync, 'raw sync' ], | ||
[ zlib.deflateSync, zlib.inflateSync, 'deflate sync' ], | ||
[ zlib.gzipSync, zlib.gunzipSync, 'gzip sync' ], | ||
[ zlib.brotliCompressSync, zlib.brotliDecompressSync, 'br sync' ], | ||
[ promisify(zlib.deflateRaw), promisify(zlib.inflateRaw), 'raw' ], | ||
[ promisify(zlib.deflate), promisify(zlib.inflate), 'deflate' ], | ||
[ promisify(zlib.gzip), promisify(zlib.gunzip), 'gzip' ], | ||
[ promisify(zlib.brotliCompress), promisify(zlib.brotliDecompress), 'br' ], | ||
]) { | ||
const compressed = await compress(emptyBuffer); | ||
const decompressed = await decompress(compressed); | ||
assert.deepStrictEqual( | ||
emptyBuffer, decompressed, | ||
`Expected ${inspect(compressed)} to match ${inspect(decompressed)} ` + | ||
`to match for ${method}`); | ||
test('zlib compression and decompression with various methods', async (t) => { | ||
const methods = [ | ||
[zlib.deflateRawSync, zlib.inflateRawSync, 'raw sync'], | ||
[zlib.deflateSync, zlib.inflateSync, 'deflate sync'], | ||
[zlib.gzipSync, zlib.gunzipSync, 'gzip sync'], | ||
[zlib.brotliCompressSync, zlib.brotliDecompressSync, 'br sync'], | ||
[promisify(zlib.deflateRaw), promisify(zlib.inflateRaw), 'raw'], | ||
[promisify(zlib.deflate), promisify(zlib.inflate), 'deflate'], | ||
[promisify(zlib.gzip), promisify(zlib.gunzip), 'gzip'], | ||
[promisify(zlib.brotliCompress), promisify(zlib.brotliDecompress), 'br'], | ||
]; | ||
|
||
for (const [compress, decompress, method] of methods) { | ||
await t.test(`should handle ${method} compression and decompression`, async () => { | ||
const compressed = await compress(emptyBuffer); | ||
const decompressed = await decompress(compressed); | ||
|
||
assert.deepStrictEqual( | ||
emptyBuffer, | ||
decompressed, | ||
`Expected ${inspect(compressed)} to match ${inspect(decompressed)} for ${method}` | ||
); | ||
}); | ||
} | ||
})().then(common.mustCall()); | ||
}); |