diff --git a/build/replacements.mjs b/build/replacements.mjs index 2b69d27cf..e5d97ecc7 100644 --- a/build/replacements.mjs +++ b/build/replacements.mjs @@ -146,6 +146,8 @@ const streamsRequireInternal = ["require\\('internal/(.+)'\\)", "require('../int const streamsRequirePrimordials = ['= primordials', "= require('../ours/primordials')"] +const stringDecoderRequirePackage = ["require\\('string_decoder'\\)", "require('string_decoder/')"] + const testCommonKnownGlobals = [ 'let knownGlobals = \\[(\\n\\s+)', ` @@ -312,7 +314,8 @@ export const replacements = { ], 'lib/internal/streams/readable.js': [ removefromWebReadableMethod, - removetoWebReadableMethod + removetoWebReadableMethod, + stringDecoderRequirePackage ], 'lib/internal/streams/.+': [ internalStreamsRequireErrors, diff --git a/eslint.config.mjs b/eslint.config.mjs index cf74cc0a2..afbc78ed5 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -21,7 +21,7 @@ export default [ 'space-before-function-paren': 0, curly: [2, 'all'], 'local/no-big-int': 'error', + 'no-undef': 'warn', }, }, ] - diff --git a/lib/internal/streams/readable.js b/lib/internal/streams/readable.js index 5b494ba3d..c6fcc64ca 100644 --- a/lib/internal/streams/readable.js +++ b/lib/internal/streams/readable.js @@ -65,7 +65,7 @@ const { } = require('../../ours/errors') const { validateObject } = require('../validators') const kPaused = Symbol('kPaused') -const { StringDecoder } = require('string_decoder') +const { StringDecoder } = require('string_decoder/') const from = require('./from') ObjectSetPrototypeOf(Readable.prototype, Stream.prototype) ObjectSetPrototypeOf(Readable, Stream) diff --git a/lib/internal/streams/utils.js b/lib/internal/streams/utils.js index 9ced0485a..f0d7884e4 100644 --- a/lib/internal/streams/utils.js +++ b/lib/internal/streams/utils.js @@ -30,7 +30,6 @@ function isReadableNodeStream(obj, strict = false) { ) // Writable has .pipe. ) } - function isWritableNodeStream(obj) { var _obj$_writableState return !!( @@ -45,7 +44,6 @@ function isWritableNodeStream(obj) { ) // Duplex ) } - function isDuplexNodeStream(obj) { return !!( obj && diff --git a/lib/ours/errors.js b/lib/ours/errors.js index 97866d14f..13cd59d8a 100644 --- a/lib/ours/errors.js +++ b/lib/ours/errors.js @@ -311,7 +311,8 @@ E( received = addNumericalSeparator(String(input)) } else if (typeof input === 'bigint') { received = String(input) - if (input > 2n ** 32n || input < -(2n ** 32n)) { + const limit = BigInt(2) ** BigInt(32) + if (input > limit || input < -limit) { received = addNumericalSeparator(received) } received += 'n' diff --git a/lib/ours/primordials.js b/lib/ours/primordials.js index 00b820533..e985b6d97 100644 --- a/lib/ours/primordials.js +++ b/lib/ours/primordials.js @@ -102,6 +102,6 @@ module.exports = { TypedArrayPrototypeSet(self, buf, len) { return self.set(buf, len) }, - Boolean: Boolean, + Boolean, Uint8Array } diff --git a/lib/ours/util.js b/lib/ours/util.js index 9896a1cec..71e7579b5 100644 --- a/lib/ours/util.js +++ b/lib/ours/util.js @@ -24,7 +24,9 @@ const validateAbortSignal = (signal, name) => { } } const validateFunction = (value, name) => { - if (typeof value !== 'function') throw new ERR_INVALID_ARG_TYPE(name, 'Function', value) + if (typeof value !== 'function') { + throw new ERR_INVALID_ARG_TYPE(name, 'Function', value) + } } // This is a simplified version of AggregateError diff --git a/package.json b/package.json index df13bfb39..f7d23e104 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "./lib/ours/index.js": "./lib/ours/browser.js" }, "scripts": { - "build": "node build/build.mjs", + "build": "node build/build.mjs 18.19.0", "postbuild": "prettier -w lib test", "test": "tap --rcfile=./tap.yml test/parallel/test-*.js test/ours/test-*.js", "test:prepare": "node test/browser/runner-prepare.mjs", diff --git a/src/primordials.js b/src/primordials.js index 9e1b25b4b..cfe7b02e5 100644 --- a/src/primordials.js +++ b/src/primordials.js @@ -103,6 +103,6 @@ module.exports = { TypedArrayPrototypeSet(self, buf, len) { return self.set(buf, len) }, - Boolean: Boolean, + Boolean, Uint8Array } diff --git a/src/util.js b/src/util.js index 8039b2c91..08a1641f5 100644 --- a/src/util.js +++ b/src/util.js @@ -20,17 +20,15 @@ const isBlob = /* eslint-enable indent */ const validateAbortSignal = (signal, name) => { - if (signal !== undefined && - (signal === null || - typeof signal !== 'object' || - !('aborted' in signal))) { - throw new ERR_INVALID_ARG_TYPE(name, 'AbortSignal', signal); + if (signal !== undefined && (signal === null || typeof signal !== 'object' || !('aborted' in signal))) { + throw new ERR_INVALID_ARG_TYPE(name, 'AbortSignal', signal) } -}; +} const validateFunction = (value, name) => { - if (typeof value !== 'function') - throw new ERR_INVALID_ARG_TYPE(name, 'Function', value); -}; + if (typeof value !== 'function') { + throw new ERR_INVALID_ARG_TYPE(name, 'Function', value) + } +} // This is a simplified version of AggregateError class AggregateError extends Error { @@ -153,45 +151,53 @@ module.exports = { deprecate(fn, message) { return fn }, - addAbortListener: require('events').addAbortListener || function addAbortListener(signal, listener) { - if (signal === undefined) { - throw new ERR_INVALID_ARG_TYPE('signal', 'AbortSignal', signal); - } - validateAbortSignal(signal, 'signal'); - validateFunction(listener, 'listener'); - - let removeEventListener; - if (signal.aborted) { - queueMicrotask(() => listener()); - } else { - signal.addEventListener('abort', listener, { __proto__: null, once: true, [kResistStopPropagation]: true }); - removeEventListener = () => { - signal.removeEventListener('abort', listener); - }; - } - return { - __proto__: null, - [SymbolDispose]() { - removeEventListener?.(); - }, - }; - }, - AbortSignalAny: AbortSignal.any || function AbortSignalAny(signals) { - // Fast path if there is only one signal. - if (signals.length === 1) { - return signals[0] + addAbortListener: + require('events').addAbortListener || + function addAbortListener(signal, listener) { + if (signal === undefined) { + throw new ERR_INVALID_ARG_TYPE('signal', 'AbortSignal', signal) + } + validateAbortSignal(signal, 'signal') + validateFunction(listener, 'listener') + + let removeEventListener + if (signal.aborted) { + queueMicrotask(() => listener()) + } else { + signal.addEventListener('abort', listener, { __proto__: null, once: true, [kResistStopPropagation]: true }) + removeEventListener = () => { + signal.removeEventListener('abort', listener) + } + } + return { + __proto__: null, + [SymbolDispose]() { + removeEventListener?.() + } + } + }, + AbortSignalAny: + AbortSignal.any || + function AbortSignalAny(signals) { + // Fast path if there is only one signal. + if (signals.length === 1) { + return signals[0] + } + const ac = new AbortController() + const abort = () => ac.abort() + signals.forEach((signal) => { + validateAbortSignal(signal, 'signals') + signal.addEventListener('abort', abort, { once: true }) + }) + ac.signal.addEventListener( + 'abort', + () => { + signals.forEach((signal) => signal.removeEventListener('abort', abort)) + }, + { once: true } + ) + return ac.signal } - const ac = new AbortController() - const abort = () => ac.abort() - signals.forEach(signal => { - validateAbortSignal(signal, 'signals') - signal.addEventListener('abort', abort, { once: true }) - }) - ac.signal.addEventListener('abort', () => { - signals.forEach(signal => signal.removeEventListener('abort', abort)) - }, { once: true }) - return ac.signal - } } module.exports.promisify.custom = Symbol.for('nodejs.util.promisify.custom') diff --git a/test/browser/test-stream2-readable-wrap.js b/test/browser/test-stream2-readable-wrap.js index 82fef9927..89098a180 100644 --- a/test/browser/test-stream2-readable-wrap.js +++ b/test/browser/test-stream2-readable-wrap.js @@ -47,7 +47,6 @@ module.exports = function (test) { old.emit('data', item) // console.log('after emit', chunks, flowing); } - if (chunks <= 0) { oldEnded = true // console.log('old end', chunks, flowing); diff --git a/test/common/fixtures.mjs b/test/common/fixtures.mjs index d6f7f6c09..372fabf88 100644 --- a/test/common/fixtures.mjs +++ b/test/common/fixtures.mjs @@ -1,17 +1,5 @@ -import fixtures from './fixtures.js'; +import fixtures from './fixtures.js' -const { - fixturesDir, - path, - fileURL, - readSync, - readKey, -} = fixtures; +const { fixturesDir, path, fileURL, readSync, readKey } = fixtures -export { - fixturesDir, - path, - fileURL, - readSync, - readKey, -}; +export { fixturesDir, path, fileURL, readSync, readKey } diff --git a/test/common/index.js b/test/common/index.js index c54a8bca3..3e9b4c3ea 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -866,7 +866,6 @@ const common = { get enoughTestMem() { return require('os').totalmem() > 0x70000000 /* 1.75 Gb */ }, - get hasFipsCrypto() { return hasCrypto && require('crypto').getFips() }, diff --git a/test/common/index.mjs b/test/common/index.mjs index ca2994f6e..0cfd4bedf 100644 --- a/test/common/index.mjs +++ b/test/common/index.mjs @@ -1,7 +1,7 @@ -import { createRequire } from 'module'; +import { createRequire } from 'module' -const require = createRequire(import.meta.url); -const common = require('./index.js'); +const require = createRequire(import.meta.url) +const common = require('./index.js') const { allowGlobals, @@ -50,10 +50,10 @@ const { skipIfDumbTerminal, skipIfEslintMissing, skipIfInspectorDisabled, - spawnPromisified, -} = common; + spawnPromisified +} = common -const getPort = () => common.PORT; +const getPort = () => common.PORT export { allowGlobals, @@ -104,5 +104,5 @@ export { skipIfDumbTerminal, skipIfEslintMissing, skipIfInspectorDisabled, - spawnPromisified, -}; + spawnPromisified +} diff --git a/test/parallel/test-stream-asIndexedPairs.mjs b/test/parallel/test-stream-asIndexedPairs.mjs index a103920ee..35919114a 100644 --- a/test/parallel/test-stream-asIndexedPairs.mjs +++ b/test/parallel/test-stream-asIndexedPairs.mjs @@ -1,64 +1,82 @@ -import '../common/index.mjs'; -import { Readable }from '../../lib/ours/index.js'; -import { deepStrictEqual, rejects, throws } from 'assert'; -import tap from 'tap'; +import '../common/index.mjs' +import { Readable } from '../../lib/ours/index.js' +import { deepStrictEqual, rejects, throws } from 'assert' +import tap from 'tap' { // asIndexedPairs with a synchronous stream - const pairs = await Readable.from([1, 2, 3]).asIndexedPairs().toArray(); - deepStrictEqual(pairs, [[0, 1], [1, 2], [2, 3]]); - const empty = await Readable.from([]).asIndexedPairs().toArray(); - deepStrictEqual(empty, []); + const pairs = await Readable.from([1, 2, 3]).asIndexedPairs().toArray() + deepStrictEqual(pairs, [ + [0, 1], + [1, 2], + [2, 3] + ]) + const empty = await Readable.from([]).asIndexedPairs().toArray() + deepStrictEqual(empty, []) } { // asIndexedPairs works an asynchronous streams - const asyncFrom = (...args) => Readable.from(...args).map(async (x) => x); - const pairs = await asyncFrom([1, 2, 3]).asIndexedPairs().toArray(); - deepStrictEqual(pairs, [[0, 1], [1, 2], [2, 3]]); - const empty = await asyncFrom([]).asIndexedPairs().toArray(); - deepStrictEqual(empty, []); + const asyncFrom = (...args) => Readable.from(...args).map(async (x) => x) + const pairs = await asyncFrom([1, 2, 3]).asIndexedPairs().toArray() + deepStrictEqual(pairs, [ + [0, 1], + [1, 2], + [2, 3] + ]) + const empty = await asyncFrom([]).asIndexedPairs().toArray() + deepStrictEqual(empty, []) } { // Does not enumerate an infinite stream - const infinite = () => Readable.from(async function* () { - while (true) yield 1; - }()); - const pairs = await infinite().asIndexedPairs().take(3).toArray(); - deepStrictEqual(pairs, [[0, 1], [1, 1], [2, 1]]); - const empty = await infinite().asIndexedPairs().take(0).toArray(); - deepStrictEqual(empty, []); + const infinite = () => + Readable.from( + (async function* () { + while (true) yield 1 + })() + ) + const pairs = await infinite().asIndexedPairs().take(3).toArray() + deepStrictEqual(pairs, [ + [0, 1], + [1, 1], + [2, 1] + ]) + const empty = await infinite().asIndexedPairs().take(0).toArray() + deepStrictEqual(empty, []) } { // AbortSignal - await rejects(async () => { - const ac = new AbortController(); - const { signal } = ac; - const p = Readable.from([1, 2, 3]).asIndexedPairs({ signal }).toArray(); - ac.abort(); - await p; - }, { name: 'AbortError' }); + await rejects( + async () => { + const ac = new AbortController() + const { signal } = ac + const p = Readable.from([1, 2, 3]).asIndexedPairs({ signal }).toArray() + ac.abort() + await p + }, + { name: 'AbortError' } + ) await rejects(async () => { - const signal = AbortSignal.abort(); - await Readable.from([1, 2, 3]).asIndexedPairs({ signal }).toArray(); - }, /AbortError/); + const signal = AbortSignal.abort() + await Readable.from([1, 2, 3]).asIndexedPairs({ signal }).toArray() + }, /AbortError/) } { // Error cases - throws(() => Readable.from([1]).asIndexedPairs(1), /ERR_INVALID_ARG_TYPE/); - throws(() => Readable.from([1]).asIndexedPairs({ signal: true }), /ERR_INVALID_ARG_TYPE/); + throws(() => Readable.from([1]).asIndexedPairs(1), /ERR_INVALID_ARG_TYPE/) + throws(() => Readable.from([1]).asIndexedPairs({ signal: true }), /ERR_INVALID_ARG_TYPE/) } - /* replacement start */ - process.on('beforeExit', (code) => { - if(code === 0) { - tap.pass('test succeeded'); - } else { - tap.fail(`test failed - exited code ${code}`); - } - }); - /* replacement end */ +/* replacement start */ +process.on('beforeExit', (code) => { + if (code === 0) { + tap.pass('test succeeded') + } else { + tap.fail(`test failed - exited code ${code}`) + } +}) +/* replacement end */ diff --git a/test/parallel/test-stream-iterator-helpers-test262-tests.mjs b/test/parallel/test-stream-iterator-helpers-test262-tests.mjs index 5a17c5f7f..6bddd4291 100644 --- a/test/parallel/test-stream-iterator-helpers-test262-tests.mjs +++ b/test/parallel/test-stream-iterator-helpers-test262-tests.mjs @@ -1,7 +1,7 @@ -import { mustCall } from '../common/index.mjs'; -import { Readable }from '../../lib/ours/index.js'; -import assert from 'assert'; -import tap from 'tap'; +import { mustCall } from '../common/index.mjs' +import { Readable } from '../../lib/ours/index.js' +import assert from 'assert' +import tap from 'tap' // These tests are manually ported from the draft PR for the test262 test suite // Authored by Rick Waldron in https://github.com/tc39/test262/pull/2818/files @@ -46,132 +46,129 @@ import tap from 'tap'; // * Ecma International Standards hereafter means Ecma International Standards // as well as Ecma Technical Reports - // Note all the tests that check AsyncIterator's prototype itself and things // that happen before stream conversion were not ported. { // asIndexedPairs/is-function - assert.strictEqual(typeof Readable.prototype.asIndexedPairs, 'function'); + assert.strictEqual(typeof Readable.prototype.asIndexedPairs, 'function') // asIndexedPairs/indexed-pairs.js - const iterator = Readable.from([0, 1]); - const indexedPairs = iterator.asIndexedPairs(); + const iterator = Readable.from([0, 1]) + const indexedPairs = iterator.asIndexedPairs() for await (const [i, v] of indexedPairs) { - assert.strictEqual(i, v); + assert.strictEqual(i, v) } // asIndexedPairs/length.js - assert.strictEqual(Readable.prototype.asIndexedPairs.length, 0); - const descriptor = Object.getOwnPropertyDescriptor( - Readable.prototype, - 'asIndexedPairs' - ); - assert.strictEqual(descriptor.enumerable, false); - assert.strictEqual(descriptor.configurable, true); - assert.strictEqual(descriptor.writable, true); + assert.strictEqual(Readable.prototype.asIndexedPairs.length, 0) + const descriptor = Object.getOwnPropertyDescriptor(Readable.prototype, 'asIndexedPairs') + assert.strictEqual(descriptor.enumerable, false) + assert.strictEqual(descriptor.configurable, true) + assert.strictEqual(descriptor.writable, true) } { // drop/length - assert.strictEqual(Readable.prototype.drop.length, 1); - const descriptor = Object.getOwnPropertyDescriptor( - Readable.prototype, - 'drop' - ); - assert.strictEqual(descriptor.enumerable, false); - assert.strictEqual(descriptor.configurable, true); - assert.strictEqual(descriptor.writable, true); + assert.strictEqual(Readable.prototype.drop.length, 1) + const descriptor = Object.getOwnPropertyDescriptor(Readable.prototype, 'drop') + assert.strictEqual(descriptor.enumerable, false) + assert.strictEqual(descriptor.configurable, true) + assert.strictEqual(descriptor.writable, true) // drop/limit-equals-total - const iterator = Readable.from([1, 2]).drop(2); - const result = await iterator[Symbol.asyncIterator]().next(); - assert.deepStrictEqual(result, { done: true, value: undefined }); + const iterator = Readable.from([1, 2]).drop(2) + const result = await iterator[Symbol.asyncIterator]().next() + assert.deepStrictEqual(result, { done: true, value: undefined }) // drop/limit-greater-than-total.js - const iterator2 = Readable.from([1, 2]).drop(3); - const result2 = await iterator2[Symbol.asyncIterator]().next(); - assert.deepStrictEqual(result2, { done: true, value: undefined }); + const iterator2 = Readable.from([1, 2]).drop(3) + const result2 = await iterator2[Symbol.asyncIterator]().next() + assert.deepStrictEqual(result2, { done: true, value: undefined }) // drop/limit-less-than-total.js - const iterator3 = Readable.from([1, 2]).drop(1); - const result3 = await iterator3[Symbol.asyncIterator]().next(); - assert.deepStrictEqual(result3, { done: false, value: 2 }); + const iterator3 = Readable.from([1, 2]).drop(1) + const result3 = await iterator3[Symbol.asyncIterator]().next() + assert.deepStrictEqual(result3, { done: false, value: 2 }) // drop/limit-rangeerror - assert.throws(() => Readable.from([1]).drop(-1), RangeError); + assert.throws(() => Readable.from([1]).drop(-1), RangeError) assert.throws(() => { Readable.from([1]).drop({ valueOf() { - throw new Error('boom'); + throw new Error('boom') } - }); - }, /boom/); + }) + }, /boom/) // drop/limit-tointeger - const two = await Readable.from([1, 2]).drop({ valueOf: () => 1 }).toArray(); - assert.deepStrictEqual(two, [2]); + const two = await Readable.from([1, 2]) + .drop({ valueOf: () => 1 }) + .toArray() + assert.deepStrictEqual(two, [2]) // drop/name - assert.strictEqual(Readable.prototype.drop.name, 'drop'); + assert.strictEqual(Readable.prototype.drop.name, 'drop') // drop/non-constructible - assert.throws(() => new Readable.prototype.drop(1), TypeError); + assert.throws(() => new Readable.prototype.drop(1), TypeError) // drop/proto - const proto = Object.getPrototypeOf(Readable.prototype.drop); - assert.strictEqual(proto, Function.prototype); + const proto = Object.getPrototypeOf(Readable.prototype.drop) + assert.strictEqual(proto, Function.prototype) } { // every/abrupt-iterator-close - const stream = Readable.from([1, 2, 3]); - const e = new Error(); - await assert.rejects(stream.every(mustCall(() => { - throw e; - }, 1)), e); + const stream = Readable.from([1, 2, 3]) + const e = new Error() + await assert.rejects( + stream.every( + mustCall(() => { + throw e + }, 1) + ), + e + ) } { // every/callable-fn - await assert.rejects(Readable.from([1, 2]).every({}), TypeError); + await assert.rejects(Readable.from([1, 2]).every({}), TypeError) } { // every/callable - Readable.prototype.every.call(Readable.from([]), () => {}); + Readable.prototype.every.call(Readable.from([]), () => {}) // eslint-disable-next-line array-callback-return - Readable.from([]).every(() => {}); + Readable.from([]).every(() => {}) assert.throws(() => { - const r = Readable.from([]); - new r.every(() => {}); - }, TypeError); + const r = Readable.from([]) + new r.every(() => {}) + }, TypeError) } { // every/false - const iterator = Readable.from([1, 2, 3]); - const result = await iterator.every((v) => v === 1); - assert.strictEqual(result, false); + const iterator = Readable.from([1, 2, 3]) + const result = await iterator.every((v) => v === 1) + assert.strictEqual(result, false) } { // every/every - const iterator = Readable.from([1, 2, 3]); - const result = await iterator.every((v) => true); - assert.strictEqual(result, true); + const iterator = Readable.from([1, 2, 3]) + const result = await iterator.every((v) => true) + assert.strictEqual(result, true) } { // every/is-function - assert.strictEqual(typeof Readable.prototype.every, 'function'); + assert.strictEqual(typeof Readable.prototype.every, 'function') } { // every/length - assert.strictEqual(Readable.prototype.every.length, 1); + assert.strictEqual(Readable.prototype.every.length, 1) // every/name - assert.strictEqual(Readable.prototype.every.name, 'every'); + assert.strictEqual(Readable.prototype.every.name, 'every') // every/propdesc - const descriptor = Object.getOwnPropertyDescriptor( - Readable.prototype, - 'every' - ); - assert.strictEqual(descriptor.enumerable, false); - assert.strictEqual(descriptor.configurable, true); - assert.strictEqual(descriptor.writable, true); + const descriptor = Object.getOwnPropertyDescriptor(Readable.prototype, 'every') + assert.strictEqual(descriptor.enumerable, false) + assert.strictEqual(descriptor.configurable, true) + assert.strictEqual(descriptor.writable, true) } - /* replacement start */ - process.on('beforeExit', (code) => { - if(code === 0) { - tap.pass('test succeeded'); - } else { - tap.fail(`test failed - exited code ${code}`); - } - }); - /* replacement end */ +/* replacement start */ +process.on('beforeExit', (code) => { + if (code === 0) { + tap.pass('test succeeded') + } else { + tap.fail(`test failed - exited code ${code}`) + } +}) +/* replacement end */ diff --git a/test/parallel/test-stream-pipe-flow-after-unpipe.js b/test/parallel/test-stream-pipe-flow-after-unpipe.js index 882e4a823..760bdcbc9 100644 --- a/test/parallel/test-stream-pipe-flow-after-unpipe.js +++ b/test/parallel/test-stream-pipe-flow-after-unpipe.js @@ -31,7 +31,6 @@ rs.on( if (chunks >= 20) rs.pause() // Finish this test. }) ) - rs.pipe(ws) /* replacement start */ diff --git a/test/parallel/test-stream-pipe-multiple-pipes.js b/test/parallel/test-stream-pipe-multiple-pipes.js index 18a1e5a4b..39bde03ac 100644 --- a/test/parallel/test-stream-pipe-multiple-pipes.js +++ b/test/parallel/test-stream-pipe-multiple-pipes.js @@ -41,7 +41,6 @@ process.nextTick( readable.resume() // Make sure the 'end' event gets emitted. }) ) - readable.on( 'end', common.mustCall(() => { diff --git a/test/parallel/test-stream-readable-no-unneeded-readable.js b/test/parallel/test-stream-readable-no-unneeded-readable.js index a2cd06941..67f71b89c 100644 --- a/test/parallel/test-stream-readable-no-unneeded-readable.js +++ b/test/parallel/test-stream-readable-no-unneeded-readable.js @@ -24,7 +24,6 @@ function test(r) { }) } }) - r.once('end', function () { wrapper.push(null) }) diff --git a/test/parallel/test-stream-reduce.js b/test/parallel/test-stream-reduce.js index b0a7ccd77..079e2a44c 100644 --- a/test/parallel/test-stream-reduce.js +++ b/test/parallel/test-stream-reduce.js @@ -93,7 +93,6 @@ function sum(p, c) { if (c === 3) { await new Promise(() => {}) // Explicitly do not pass signal here } - return Promise.resolve() }, 0, @@ -120,7 +119,6 @@ function sum(p, c) { if (c === 3) { await new Promise(() => {}) // Explicitly do not pass signal here } - return Promise.resolve() }, 0, @@ -153,7 +151,6 @@ function sum(p, c) { if (c === 3) { await new Promise(() => {}) // Explicitly do not pass signal here } - return Promise.resolve() }, 0, diff --git a/test/parallel/test-stream-some-find-every.mjs b/test/parallel/test-stream-some-find-every.mjs index c6168fbd6..f68c45e3e 100644 --- a/test/parallel/test-stream-some-find-every.mjs +++ b/test/parallel/test-stream-some-find-every.mjs @@ -1,183 +1,215 @@ -import * as common from '../common/index.mjs'; -import { setTimeout } from 'timers/promises'; -import { Readable }from '../../lib/ours/index.js'; -import assert from 'assert'; -import tap from 'tap'; - +import * as common from '../common/index.mjs' +import { setTimeout } from 'timers/promises' +import { Readable } from '../../lib/ours/index.js' +import assert from 'assert' +import tap from 'tap' function oneTo5() { - return Readable.from([1, 2, 3, 4, 5]); + return Readable.from([1, 2, 3, 4, 5]) } function oneTo5Async() { return oneTo5().map(async (x) => { - await Promise.resolve(); - return x; - }); + await Promise.resolve() + return x + }) } { // Some, find, and every work with a synchronous stream and predicate - assert.strictEqual(await oneTo5().some((x) => x > 3), true); - assert.strictEqual(await oneTo5().every((x) => x > 3), false); - assert.strictEqual(await oneTo5().find((x) => x > 3), 4); - assert.strictEqual(await oneTo5().some((x) => x > 6), false); - assert.strictEqual(await oneTo5().every((x) => x < 6), true); - assert.strictEqual(await oneTo5().find((x) => x > 6), undefined); - assert.strictEqual(await Readable.from([]).some(() => true), false); - assert.strictEqual(await Readable.from([]).every(() => true), true); - assert.strictEqual(await Readable.from([]).find(() => true), undefined); + assert.strictEqual(await oneTo5().some((x) => x > 3), true) + assert.strictEqual(await oneTo5().every((x) => x > 3), false) + assert.strictEqual(await oneTo5().find((x) => x > 3), 4) + assert.strictEqual(await oneTo5().some((x) => x > 6), false) + assert.strictEqual(await oneTo5().every((x) => x < 6), true) + assert.strictEqual(await oneTo5().find((x) => x > 6), undefined) + assert.strictEqual(await Readable.from([]).some(() => true), false) + assert.strictEqual(await Readable.from([]).every(() => true), true) + assert.strictEqual(await Readable.from([]).find(() => true), undefined) } { // Some, find, and every work with an asynchronous stream and synchronous predicate - assert.strictEqual(await oneTo5Async().some((x) => x > 3), true); - assert.strictEqual(await oneTo5Async().every((x) => x > 3), false); - assert.strictEqual(await oneTo5Async().find((x) => x > 3), 4); - assert.strictEqual(await oneTo5Async().some((x) => x > 6), false); - assert.strictEqual(await oneTo5Async().every((x) => x < 6), true); - assert.strictEqual(await oneTo5Async().find((x) => x > 6), undefined); + assert.strictEqual(await oneTo5Async().some((x) => x > 3), true) + assert.strictEqual(await oneTo5Async().every((x) => x > 3), false) + assert.strictEqual(await oneTo5Async().find((x) => x > 3), 4) + assert.strictEqual(await oneTo5Async().some((x) => x > 6), false) + assert.strictEqual(await oneTo5Async().every((x) => x < 6), true) + assert.strictEqual(await oneTo5Async().find((x) => x > 6), undefined) } { // Some, find, and every work on synchronous streams with an asynchronous predicate - assert.strictEqual(await oneTo5().some(async (x) => x > 3), true); - assert.strictEqual(await oneTo5().every(async (x) => x > 3), false); - assert.strictEqual(await oneTo5().find(async (x) => x > 3), 4); - assert.strictEqual(await oneTo5().some(async (x) => x > 6), false); - assert.strictEqual(await oneTo5().every(async (x) => x < 6), true); - assert.strictEqual(await oneTo5().find(async (x) => x > 6), undefined); + assert.strictEqual(await oneTo5().some(async (x) => x > 3), true) + assert.strictEqual(await oneTo5().every(async (x) => x > 3), false) + assert.strictEqual(await oneTo5().find(async (x) => x > 3), 4) + assert.strictEqual(await oneTo5().some(async (x) => x > 6), false) + assert.strictEqual(await oneTo5().every(async (x) => x < 6), true) + assert.strictEqual(await oneTo5().find(async (x) => x > 6), undefined) } { // Some, find, and every work on asynchronous streams with an asynchronous predicate - assert.strictEqual(await oneTo5Async().some(async (x) => x > 3), true); - assert.strictEqual(await oneTo5Async().every(async (x) => x > 3), false); - assert.strictEqual(await oneTo5Async().find(async (x) => x > 3), 4); - assert.strictEqual(await oneTo5Async().some(async (x) => x > 6), false); - assert.strictEqual(await oneTo5Async().every(async (x) => x < 6), true); - assert.strictEqual(await oneTo5Async().find(async (x) => x > 6), undefined); + assert.strictEqual(await oneTo5Async().some(async (x) => x > 3), true) + assert.strictEqual(await oneTo5Async().every(async (x) => x > 3), false) + assert.strictEqual(await oneTo5Async().find(async (x) => x > 3), 4) + assert.strictEqual(await oneTo5Async().some(async (x) => x > 6), false) + assert.strictEqual(await oneTo5Async().every(async (x) => x < 6), true) + assert.strictEqual(await oneTo5Async().find(async (x) => x > 6), undefined) } { async function checkDestroyed(stream) { - await setTimeout(); - assert.strictEqual(stream.destroyed, true); + await setTimeout() + assert.strictEqual(stream.destroyed, true) } { // Some, find, and every short circuit - const someStream = oneTo5(); - await someStream.some(common.mustCall((x) => x > 2, 3)); - await checkDestroyed(someStream); + const someStream = oneTo5() + await someStream.some(common.mustCall((x) => x > 2, 3)) + await checkDestroyed(someStream) - const everyStream = oneTo5(); - await everyStream.every(common.mustCall((x) => x < 3, 3)); - await checkDestroyed(everyStream); + const everyStream = oneTo5() + await everyStream.every(common.mustCall((x) => x < 3, 3)) + await checkDestroyed(everyStream) - const findStream = oneTo5(); - await findStream.find(common.mustCall((x) => x > 1, 2)); - await checkDestroyed(findStream); + const findStream = oneTo5() + await findStream.find(common.mustCall((x) => x > 1, 2)) + await checkDestroyed(findStream) // When short circuit isn't possible the whole stream is iterated - await oneTo5().some(common.mustCall(() => false, 5)); - await oneTo5().every(common.mustCall(() => true, 5)); - await oneTo5().find(common.mustCall(() => false, 5)); + await oneTo5().some(common.mustCall(() => false, 5)) + await oneTo5().every(common.mustCall(() => true, 5)) + await oneTo5().find(common.mustCall(() => false, 5)) } { // Some, find, and every short circuit async stream/predicate - const someStream = oneTo5Async(); - await someStream.some(common.mustCall(async (x) => x > 2, 3)); - await checkDestroyed(someStream); + const someStream = oneTo5Async() + await someStream.some(common.mustCall(async (x) => x > 2, 3)) + await checkDestroyed(someStream) - const everyStream = oneTo5Async(); - await everyStream.every(common.mustCall(async (x) => x < 3, 3)); - await checkDestroyed(everyStream); + const everyStream = oneTo5Async() + await everyStream.every(common.mustCall(async (x) => x < 3, 3)) + await checkDestroyed(everyStream) - const findStream = oneTo5Async(); - await findStream.find(common.mustCall(async (x) => x > 1, 2)); - await checkDestroyed(findStream); + const findStream = oneTo5Async() + await findStream.find(common.mustCall(async (x) => x > 1, 2)) + await checkDestroyed(findStream) // When short circuit isn't possible the whole stream is iterated - await oneTo5Async().some(common.mustCall(async () => false, 5)); - await oneTo5Async().every(common.mustCall(async () => true, 5)); - await oneTo5Async().find(common.mustCall(async () => false, 5)); + await oneTo5Async().some(common.mustCall(async () => false, 5)) + await oneTo5Async().every(common.mustCall(async () => true, 5)) + await oneTo5Async().find(common.mustCall(async () => false, 5)) } } { // Concurrency doesn't affect which value is found. - const found = await Readable.from([1, 2]).find(async (val) => { - if (val === 1) { - await setTimeout(100); - } - return true; - }, { concurrency: 2 }); - assert.strictEqual(found, 1); + const found = await Readable.from([1, 2]).find( + async (val) => { + if (val === 1) { + await setTimeout(100) + } + return true + }, + { concurrency: 2 } + ) + assert.strictEqual(found, 1) } { // Support for AbortSignal for (const op of ['some', 'every', 'find']) { { - const ac = new AbortController(); - assert.rejects(Readable.from([1, 2, 3])[op]( - () => new Promise(() => { }), - { signal: ac.signal } - ), { - name: 'AbortError', - }, `${op} should abort correctly with sync abort`).then(common.mustCall()); - ac.abort(); + const ac = new AbortController() + assert + .rejects( + Readable.from([1, 2, 3])[op](() => new Promise(() => {}), { signal: ac.signal }), + { + name: 'AbortError' + }, + `${op} should abort correctly with sync abort` + ) + .then(common.mustCall()) + ac.abort() } { // Support for pre-aborted AbortSignal - assert.rejects(Readable.from([1, 2, 3])[op]( - () => new Promise(() => { }), - { signal: AbortSignal.abort() } - ), { - name: 'AbortError', - }, `${op} should abort with pre-aborted abort controller`).then(common.mustCall()); + assert + .rejects( + Readable.from([1, 2, 3])[op](() => new Promise(() => {}), { signal: AbortSignal.abort() }), + { + name: 'AbortError' + }, + `${op} should abort with pre-aborted abort controller` + ) + .then(common.mustCall()) } } } { // Error cases for (const op of ['some', 'every', 'find']) { - assert.rejects(async () => { - await Readable.from([1])[op](1); - }, /ERR_INVALID_ARG_TYPE/, `${op} should throw for invalid function`).then(common.mustCall()); - assert.rejects(async () => { - await Readable.from([1])[op]((x) => x, { - concurrency: 'Foo' - }); - }, /ERR_OUT_OF_RANGE/, `${op} should throw for invalid concurrency`).then(common.mustCall()); - assert.rejects(async () => { - await Readable.from([1])[op]((x) => x, 1); - }, /ERR_INVALID_ARG_TYPE/, `${op} should throw for invalid concurrency`).then(common.mustCall()); - assert.rejects(async () => { - await Readable.from([1])[op]((x) => x, { - signal: true - }); - }, /ERR_INVALID_ARG_TYPE/, `${op} should throw for invalid signal`).then(common.mustCall()); + assert + .rejects( + async () => { + await Readable.from([1])[op](1) + }, + /ERR_INVALID_ARG_TYPE/, + `${op} should throw for invalid function` + ) + .then(common.mustCall()) + assert + .rejects( + async () => { + await Readable.from([1])[op]((x) => x, { + concurrency: 'Foo' + }) + }, + /ERR_OUT_OF_RANGE/, + `${op} should throw for invalid concurrency` + ) + .then(common.mustCall()) + assert + .rejects( + async () => { + await Readable.from([1])[op]((x) => x, 1) + }, + /ERR_INVALID_ARG_TYPE/, + `${op} should throw for invalid concurrency` + ) + .then(common.mustCall()) + assert + .rejects( + async () => { + await Readable.from([1])[op]((x) => x, { + signal: true + }) + }, + /ERR_INVALID_ARG_TYPE/, + `${op} should throw for invalid signal` + ) + .then(common.mustCall()) } } { for (const op of ['some', 'every', 'find']) { - const stream = oneTo5(); + const stream = oneTo5() Object.defineProperty(stream, 'map', { - value: common.mustNotCall(), - }); + value: common.mustNotCall() + }) // Check that map isn't getting called. - stream[op](() => {}); + stream[op](() => {}) } } - /* replacement start */ - process.on('beforeExit', (code) => { - if(code === 0) { - tap.pass('test succeeded'); - } else { - tap.fail(`test failed - exited code ${code}`); - } - }); - /* replacement end */ +/* replacement start */ +process.on('beforeExit', (code) => { + if (code === 0) { + tap.pass('test succeeded') + } else { + tap.fail(`test failed - exited code ${code}`) + } +}) +/* replacement end */ diff --git a/test/parallel/test-stream-toArray.js b/test/parallel/test-stream-toArray.js index 2c8094035..f4f87f0c9 100644 --- a/test/parallel/test-stream-toArray.js +++ b/test/parallel/test-stream-toArray.js @@ -80,7 +80,6 @@ const assert = require('assert') if (x === 3) { await new Promise(() => {}) // Explicitly do not pass signal here } - return Promise.resolve(x) }) await stream.toArray({ diff --git a/test/parallel/test-stream2-unpipe-drain.js b/test/parallel/test-stream2-unpipe-drain.js index ccae8d202..c183e69c5 100644 --- a/test/parallel/test-stream2-unpipe-drain.js +++ b/test/parallel/test-stream2-unpipe-drain.js @@ -35,7 +35,6 @@ class TestWriter extends stream.Writable { // Super slow write stream (callback never called) } } - const dest = new TestWriter() class TestReader extends stream.Readable { constructor() {