From 8cdb36650d0107069b465fe7c613c3c163a4eebc Mon Sep 17 00:00:00 2001 From: Mattias Buelens Date: Thu, 12 Nov 2020 00:54:41 +0100 Subject: [PATCH] Add regression test for #66 --- test/unit/readable-stream/regression.spec.js | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/unit/readable-stream/regression.spec.js diff --git a/test/unit/readable-stream/regression.spec.js b/test/unit/readable-stream/regression.spec.js new file mode 100644 index 0000000..bc2d98c --- /dev/null +++ b/test/unit/readable-stream/regression.spec.js @@ -0,0 +1,27 @@ +const { TransformStream } = require('../../../'); + +describe('ReadableStream regressions', () => { + // https://github.com/MattiasBuelens/web-streams-polyfill/issues/66 + it('#66', async () => { + const { readable, writable } = new TransformStream(); + + const producer = (async () => { + const writer = writable.getWriter(); + await writer.write('hello'); + // The async iterator releases its reader lock in the "close steps" of its pending read, which rejects the + // reader's closed promise. However, ReadableStreamClose then tries to resolve that same closed promise. + // This *should* be ignored (since the promise is already rejected), but instead would cause a TypeError. + await writer.close(); + })(); + + const consumer = (async () => { + const results = []; + for await (const chunk of readable) { + results.push(chunk); + } + expect(results).toEqual(['hello']); + })(); + + await Promise.all([producer, consumer]); + }); +});