From 7737755eae2b8613f48bb9bcf066b1a6c76e1b3d Mon Sep 17 00:00:00 2001 From: Satya Rohith Date: Tue, 25 Jun 2024 15:06:40 +0530 Subject: [PATCH] test(node_compat): enable more stream-writable tests (#24328) --- tests/node_compat/config.jsonc | 4 +++ tests/node_compat/runner/TODO.md | 4 --- .../parallel/test-stream-writable-aborted.js | 33 +++++++++++++++++++ .../test-stream-writable-final-async.js | 32 ++++++++++++++++++ .../test-stream-writable-final-destroy.js | 28 ++++++++++++++++ .../test-stream-writable-final-throw.js | 30 +++++++++++++++++ 6 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 tests/node_compat/test/parallel/test-stream-writable-aborted.js create mode 100644 tests/node_compat/test/parallel/test-stream-writable-final-async.js create mode 100644 tests/node_compat/test/parallel/test-stream-writable-final-destroy.js create mode 100644 tests/node_compat/test/parallel/test-stream-writable-final-throw.js diff --git a/tests/node_compat/config.jsonc b/tests/node_compat/config.jsonc index 83d91eac18c84a..638af89c845b2f 100644 --- a/tests/node_compat/config.jsonc +++ b/tests/node_compat/config.jsonc @@ -575,6 +575,7 @@ "test-stream-unpipe-event.js", "test-stream-unshift-empty-chunk.js", "test-stream-unshift-read-race.js", + "test-stream-writable-aborted.js", "test-stream-writable-change-default-encoding.js", "test-stream-writable-clear-buffer.js", "test-stream-writable-constructor-set-methods.js", @@ -583,6 +584,9 @@ "test-stream-writable-end-cb-error.js", "test-stream-writable-end-multiple.js", "test-stream-writable-ended-state.js", + "test-stream-writable-final-async.js", + "test-stream-writable-final-destroy.js", + "test-stream-writable-final-throw.js", "test-stream-writable-finish-destroyed.js", "test-stream-writable-finished-state.js", "test-stream-writable-finished.js", diff --git a/tests/node_compat/runner/TODO.md b/tests/node_compat/runner/TODO.md index 24618dc88387b0..0a68b810f82580 100644 --- a/tests/node_compat/runner/TODO.md +++ b/tests/node_compat/runner/TODO.md @@ -2298,11 +2298,7 @@ NOTE: This file should not be manually edited. Please edit `tests/node_compat/co - [parallel/test-stream-wrap-drain.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-stream-wrap-drain.js) - [parallel/test-stream-wrap-encoding.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-stream-wrap-encoding.js) - [parallel/test-stream-wrap.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-stream-wrap.js) -- [parallel/test-stream-writable-aborted.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-stream-writable-aborted.js) - [parallel/test-stream-writable-end-cb-uncaught.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-stream-writable-end-cb-uncaught.js) -- [parallel/test-stream-writable-final-async.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-stream-writable-final-async.js) -- [parallel/test-stream-writable-final-destroy.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-stream-writable-final-destroy.js) -- [parallel/test-stream-writable-final-throw.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-stream-writable-final-throw.js) - [parallel/test-stream-writable-samecb-singletick.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-stream-writable-samecb-singletick.js) - [parallel/test-stream2-finish-pipe-error.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-stream2-finish-pipe-error.js) - [parallel/test-stream2-httpclient-response-end.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-stream2-httpclient-response-end.js) diff --git a/tests/node_compat/test/parallel/test-stream-writable-aborted.js b/tests/node_compat/test/parallel/test-stream-writable-aborted.js new file mode 100644 index 00000000000000..89dbcc4ee2fb2d --- /dev/null +++ b/tests/node_compat/test/parallel/test-stream-writable-aborted.js @@ -0,0 +1,33 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 18.12.1 +// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually. + +'use strict'; + +require('../common'); +const assert = require('assert'); +const { Writable } = require('stream'); + +{ + const writable = new Writable({ + write() { + } + }); + assert.strictEqual(writable.writableAborted, false); + writable.destroy(); + assert.strictEqual(writable.writableAborted, true); +} + +{ + const writable = new Writable({ + write() { + } + }); + assert.strictEqual(writable.writableAborted, false); + writable.end(); + writable.destroy(); + assert.strictEqual(writable.writableAborted, true); +} diff --git a/tests/node_compat/test/parallel/test-stream-writable-final-async.js b/tests/node_compat/test/parallel/test-stream-writable-final-async.js new file mode 100644 index 00000000000000..c8fe2057b591d1 --- /dev/null +++ b/tests/node_compat/test/parallel/test-stream-writable-final-async.js @@ -0,0 +1,32 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 18.12.1 +// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually. + +'use strict'; + +const common = require('../common'); +const { + Duplex, +} = require('stream'); +const { setTimeout } = require('timers/promises'); + +{ + class Foo extends Duplex { + async _final(callback) { + await setTimeout(common.platformTimeout(1)); + callback(); + } + + _read() {} + } + + const foo = new Foo(); + foo._write = common.mustCall((chunk, encoding, cb) => { + cb(); + }); + foo.end('test', common.mustCall()); + foo.on('error', common.mustNotCall()); +} diff --git a/tests/node_compat/test/parallel/test-stream-writable-final-destroy.js b/tests/node_compat/test/parallel/test-stream-writable-final-destroy.js new file mode 100644 index 00000000000000..958a36bfdf64ea --- /dev/null +++ b/tests/node_compat/test/parallel/test-stream-writable-final-destroy.js @@ -0,0 +1,28 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 18.12.1 +// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually. + +'use strict'; +const common = require('../common'); + +const { Writable } = require('stream'); + +{ + const w = new Writable({ + write(chunk, encoding, callback) { + callback(null); + }, + final(callback) { + queueMicrotask(callback); + } + }); + w.end(); + w.destroy(); + + w.on('prefinish', common.mustNotCall()); + w.on('finish', common.mustNotCall()); + w.on('close', common.mustCall()); +} diff --git a/tests/node_compat/test/parallel/test-stream-writable-final-throw.js b/tests/node_compat/test/parallel/test-stream-writable-final-throw.js new file mode 100644 index 00000000000000..ba7f87b238d17f --- /dev/null +++ b/tests/node_compat/test/parallel/test-stream-writable-final-throw.js @@ -0,0 +1,30 @@ +// deno-fmt-ignore-file +// deno-lint-ignore-file + +// Copyright Joyent and Node contributors. All rights reserved. MIT license. +// Taken from Node 18.12.1 +// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually. + +'use strict'; + +const common = require('../common'); +const { + Duplex, +} = require('stream'); + +{ + class Foo extends Duplex { + _final(callback) { + throw new Error('fhqwhgads'); + } + + _read() {} + } + + const foo = new Foo(); + foo._write = common.mustCall((chunk, encoding, cb) => { + cb(); + }); + foo.end('test', common.expectsError({ message: 'fhqwhgads' })); + foo.on('error', common.mustCall()); +}