summaryrefslogtreecommitdiff
path: root/test/parallel
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2021-07-10 20:56:56 -0700
committerJames M Snell <jasnell@gmail.com>2021-07-14 10:52:59 -0700
commit09ad64d66de6222e5d029ef40a93287b7f5d8275 (patch)
tree080bdd3aeeb9873b5909fea2f98a07f40f470d8b /test/parallel
parent25e2f177cb3598e2452bcafed16fbd96fe33da94 (diff)
downloadnode-new-09ad64d66de6222e5d029ef40a93287b7f5d8275.tar.gz
stream: add CompressionStream and DecompressionStream
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/39348 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test/parallel')
-rw-r--r--test/parallel/test-whatwg-webstreams-compression.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/parallel/test-whatwg-webstreams-compression.js b/test/parallel/test-whatwg-webstreams-compression.js
new file mode 100644
index 0000000000..6d3d6253bd
--- /dev/null
+++ b/test/parallel/test-whatwg-webstreams-compression.js
@@ -0,0 +1,59 @@
+// Flags: --no-warnings
+'use strict';
+
+const common = require('../common');
+
+const {
+ CompressionStream,
+ DecompressionStream,
+} = require('stream/web');
+
+const assert = require('assert');
+const dec = new TextDecoder();
+
+async function test(format) {
+ const gzip = new CompressionStream(format);
+ const gunzip = new DecompressionStream(format);
+
+ gzip.readable.pipeTo(gunzip.writable).then(common.mustCall());
+
+ const reader = gunzip.readable.getReader();
+ const writer = gzip.writable.getWriter();
+
+ await Promise.all([
+ reader.read().then(({ value, done }) => {
+ assert.strictEqual(dec.decode(value), 'hello');
+ }),
+ reader.read().then(({ done }) => assert(done)),
+ writer.write('hello'),
+ writer.close(),
+ ]);
+}
+
+Promise.all(['gzip', 'deflate'].map((i) => test(i))).then(common.mustCall());
+
+[1, 'hello', false, {}].forEach((i) => {
+ assert.throws(() => new CompressionStream(i), {
+ code: 'ERR_INVALID_ARG_VALUE',
+ });
+ assert.throws(() => new DecompressionStream(i), {
+ code: 'ERR_INVALID_ARG_VALUE',
+ });
+});
+
+assert.throws(
+ () => Reflect.get(CompressionStream.prototype, 'readable', {}), {
+ code: 'ERR_INVALID_THIS',
+ });
+assert.throws(
+ () => Reflect.get(CompressionStream.prototype, 'writable', {}), {
+ code: 'ERR_INVALID_THIS',
+ });
+assert.throws(
+ () => Reflect.get(DecompressionStream.prototype, 'readable', {}), {
+ code: 'ERR_INVALID_THIS',
+ });
+assert.throws(
+ () => Reflect.get(DecompressionStream.prototype, 'writable', {}), {
+ code: 'ERR_INVALID_THIS',
+ });