mirror of
https://github.com/nodejs/node.git
synced 2025-05-11 11:17:18 +00:00

In 14.2 in the specification, `error` should be signal’s abort reason. The current behavior seems to assume that only an `AbortError` instance is given as signal’s abort reason. Refs: https://streams.spec.whatwg.org/#readable-stream-pipe-to Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com PR-URL: https://github.com/nodejs/node/pull/44418 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
25 lines
690 B
JavaScript
25 lines
690 B
JavaScript
// Flags: --expose-internals
|
|
'use strict';
|
|
|
|
require('../common');
|
|
const assert = require('node:assert');
|
|
const { AbortError } = require('internal/errors');
|
|
|
|
// Purpose: pass an AbortError instance, which isn't the DOMException, as an
|
|
// abort reason.
|
|
|
|
for (const message of [undefined, 'abc']) {
|
|
const rs = new ReadableStream();
|
|
const ws = new WritableStream();
|
|
const ac = new AbortController();
|
|
const reason = new AbortError(message);
|
|
ac.abort(reason);
|
|
|
|
assert.rejects(rs.pipeTo(ws, { signal: ac.signal }), (e) => {
|
|
assert(e instanceof DOMException);
|
|
assert.strictEqual(e.name, 'AbortError');
|
|
assert.strictEqual(e.message, reason.message);
|
|
return true;
|
|
});
|
|
}
|