From 66e36e5b3ccf506bbc5fa305c773e9f23970ed5c Mon Sep 17 00:00:00 2001 From: Satya Rohith Date: Tue, 25 Jun 2024 12:45:16 +0530 Subject: [PATCH 1/2] test(node_compat): enable more stream-writable tests --- 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..90ffd2482aa9c5 100644 --- a/tests/node_compat/config.jsonc +++ b/tests/node_compat/config.jsonc @@ -575,6 +575,10 @@ "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-final-async.js", + "test-stream-writable-final-destroy.js", + "test-stream-writable-final-throw.js", "test-stream-writable-change-default-encoding.js", "test-stream-writable-clear-buffer.js", "test-stream-writable-constructor-set-methods.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()); +} From 0220a235361c2db4030ad3748f9993fe3594fda0 Mon Sep 17 00:00:00 2001 From: Satya Rohith Date: Tue, 25 Jun 2024 13:00:20 +0530 Subject: [PATCH 2/2] fix order --- tests/node_compat/config.jsonc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/node_compat/config.jsonc b/tests/node_compat/config.jsonc index 90ffd2482aa9c5..638af89c845b2f 100644 --- a/tests/node_compat/config.jsonc +++ b/tests/node_compat/config.jsonc @@ -576,9 +576,6 @@ "test-stream-unshift-empty-chunk.js", "test-stream-unshift-read-race.js", "test-stream-writable-aborted.js", - "test-stream-writable-final-async.js", - "test-stream-writable-final-destroy.js", - "test-stream-writable-final-throw.js", "test-stream-writable-change-default-encoding.js", "test-stream-writable-clear-buffer.js", "test-stream-writable-constructor-set-methods.js", @@ -587,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",