From 8eb9353b037f1b494f70ba6dd446471672a7034a Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 12 Sep 2024 01:05:47 -0400 Subject: [PATCH] test: remove need to make fs call for zlib test PR-URL: https://github.com/nodejs/node/pull/54814 Reviewed-By: James M Snell Reviewed-By: Matteo Collina --- test/parallel/test-zlib-flush.js | 54 +++++++++++++++++--------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/test/parallel/test-zlib-flush.js b/test/parallel/test-zlib-flush.js index 557775d5091..ba3f8019fd8 100644 --- a/test/parallel/test-zlib-flush.js +++ b/test/parallel/test-zlib-flush.js @@ -1,36 +1,38 @@ 'use strict'; + require('../common'); -const assert = require('assert'); -const zlib = require('zlib'); -const fixtures = require('../common/fixtures'); -const file = fixtures.readSync('person.jpg'); -const chunkSize = 16; -const opts = { level: 0 }; -const deflater = zlib.createDeflate(opts); +const assert = require('node:assert'); +const zlib = require('node:zlib'); +const { test } = require('node:test'); -const chunk = file.slice(0, chunkSize); -const expectedNone = Buffer.from([0x78, 0x01]); -const blkhdr = Buffer.from([0x00, 0x10, 0x00, 0xef, 0xff]); -const adler32 = Buffer.from([0x00, 0x00, 0x00, 0xff, 0xff]); -const expectedFull = Buffer.concat([blkhdr, chunk, adler32]); -let actualNone; -let actualFull; +test('zlib flush', async () => { + const { promise, resolve } = Promise.withResolvers(); -deflater.write(chunk, function() { - deflater.flush(zlib.constants.Z_NO_FLUSH, function() { - actualNone = deflater.read(); - deflater.flush(function() { - const bufs = []; - let buf; - while ((buf = deflater.read()) !== null) - bufs.push(buf); - actualFull = Buffer.concat(bufs); + const opts = { level: 0 }; + const deflater = zlib.createDeflate(opts); + const chunk = Buffer.from('/9j/4AAQSkZJRgABAQEASA==', 'base64'); + const expectedNone = Buffer.from([0x78, 0x01]); + const blkhdr = Buffer.from([0x00, 0x10, 0x00, 0xef, 0xff]); + const adler32 = Buffer.from([0x00, 0x00, 0x00, 0xff, 0xff]); + const expectedFull = Buffer.concat([blkhdr, chunk, adler32]); + let actualNone; + let actualFull; + + deflater.write(chunk, function() { + deflater.flush(zlib.constants.Z_NO_FLUSH, function() { + actualNone = deflater.read(); + deflater.flush(function() { + const bufs = []; + let buf; + while ((buf = deflater.read()) !== null) + bufs.push(buf); + actualFull = Buffer.concat(bufs); + resolve(); + }); }); }); -}); - -process.once('exit', function() { + await promise; assert.deepStrictEqual(actualNone, expectedNone); assert.deepStrictEqual(actualFull, expectedFull); });