Skip to content

Commit

Permalink
test: migrate tests to use node:test module for better test structure
Browse files Browse the repository at this point in the history
  • 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.
54 changes: 32 additions & 22 deletions test/parallel/test-zlib-empty-buffer.js
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());
});

0 comments on commit bda6cfd

Please sign in to comment.