From 07a43f718ffa284f468e4c8b366b0661c7b3d228 Mon Sep 17 00:00:00 2001 From: hidaviddong Date: Tue, 27 Aug 2024 00:41:45 +0800 Subject: [PATCH 1/3] test: refactor test-whatwg-webstreams-encoding to be shorter --- .../test-whatwg-webstreams-encoding.js | 54 +++++-------------- 1 file changed, 12 insertions(+), 42 deletions(-) diff --git a/test/parallel/test-whatwg-webstreams-encoding.js b/test/parallel/test-whatwg-webstreams-encoding.js index b2b18df73bf1fe..2b55c9d581f6f8 100644 --- a/test/parallel/test-whatwg-webstreams-encoding.js +++ b/test/parallel/test-whatwg-webstreams-encoding.js @@ -45,32 +45,12 @@ const kEuro = Buffer.from([0xe2, 0x82, 0xac]).toString(); assert.strictEqual(tds.encoding, 'utf-8'); assert.strictEqual(tds.fatal, false); assert.strictEqual(tds.ignoreBOM, false); - - assert.throws( - () => Reflect.get(TextDecoderStream.prototype, 'encoding', {}), { - name: 'TypeError', - message: /Cannot read private member/, - }); - assert.throws( - () => Reflect.get(TextDecoderStream.prototype, 'fatal', {}), { - name: 'TypeError', - message: /Cannot read private member/, - }); - assert.throws( - () => Reflect.get(TextDecoderStream.prototype, 'ignoreBOM', {}), { - name: 'TypeError', - message: /Cannot read private member/, - }); - assert.throws( - () => Reflect.get(TextDecoderStream.prototype, 'readable', {}), { - name: 'TypeError', - message: /Cannot read private member/, - }); - assert.throws( - () => Reflect.get(TextDecoderStream.prototype, 'writable', {}), { - name: 'TypeError', - message: /Cannot read private member/, - }); + ['encoding', 'fatal', 'ignoreBOM', 'readable', 'writable'].forEach((getter) => { + assert.throws( + () => Reflect.get(TextDecoderStream.prototype, getter, {}), + { name: 'TypeError', message: /Cannot read private member/ } + ) + }); } { @@ -91,20 +71,10 @@ const kEuro = Buffer.from([0xe2, 0x82, 0xac]).toString(); ]).then(common.mustCall()); assert.strictEqual(tds.encoding, 'utf-8'); - - assert.throws( - () => Reflect.get(TextEncoderStream.prototype, 'encoding', {}), { - name: 'TypeError', - message: /Cannot read private member/, - }); - assert.throws( - () => Reflect.get(TextEncoderStream.prototype, 'readable', {}), { - name: 'TypeError', - message: /Cannot read private member/, - }); - assert.throws( - () => Reflect.get(TextEncoderStream.prototype, 'writable', {}), { - name: 'TypeError', - message: /Cannot read private member/, - }); + ['encoding', 'readable', 'writable'].forEach((getter) => { + assert.throws( + () => Reflect.get(TextDecoderStream.prototype, getter, {}), + { name: 'TypeError', message: /Cannot read private member/ } + ) + }); } From bcb414d9c7455addfc731e5a45d26a97c5022d95 Mon Sep 17 00:00:00 2001 From: daviddong Date: Tue, 27 Aug 2024 12:12:57 +0800 Subject: [PATCH 2/3] fix: add missing semicolon --- test/parallel/test-whatwg-webstreams-encoding.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-whatwg-webstreams-encoding.js b/test/parallel/test-whatwg-webstreams-encoding.js index 2b55c9d581f6f8..f5e88a1a95d115 100644 --- a/test/parallel/test-whatwg-webstreams-encoding.js +++ b/test/parallel/test-whatwg-webstreams-encoding.js @@ -49,7 +49,7 @@ const kEuro = Buffer.from([0xe2, 0x82, 0xac]).toString(); assert.throws( () => Reflect.get(TextDecoderStream.prototype, getter, {}), { name: 'TypeError', message: /Cannot read private member/ } - ) + ); }); } @@ -75,6 +75,6 @@ const kEuro = Buffer.from([0xe2, 0x82, 0xac]).toString(); assert.throws( () => Reflect.get(TextDecoderStream.prototype, getter, {}), { name: 'TypeError', message: /Cannot read private member/ } - ) + ); }); } From 97380745ad6bf502e823bc4dd27b6ea75e9a289a Mon Sep 17 00:00:00 2001 From: Haoyu Dong Date: Thu, 29 Aug 2024 22:11:38 +0800 Subject: [PATCH 3/3] fix: add stack trace in forEach loop --- test/parallel/test-whatwg-webstreams-encoding.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-whatwg-webstreams-encoding.js b/test/parallel/test-whatwg-webstreams-encoding.js index f5e88a1a95d115..24d9bce7cc5212 100644 --- a/test/parallel/test-whatwg-webstreams-encoding.js +++ b/test/parallel/test-whatwg-webstreams-encoding.js @@ -47,8 +47,11 @@ const kEuro = Buffer.from([0xe2, 0x82, 0xac]).toString(); assert.strictEqual(tds.ignoreBOM, false); ['encoding', 'fatal', 'ignoreBOM', 'readable', 'writable'].forEach((getter) => { assert.throws( - () => Reflect.get(TextDecoderStream.prototype, getter, {}), - { name: 'TypeError', message: /Cannot read private member/ } + () => Reflect.get(TextDecoderStream.prototype, getter, {}), { + name: 'TypeError', + message: /Cannot read private member/, + stack: new RegExp(`at get ${getter}`) + } ); }); } @@ -73,8 +76,11 @@ const kEuro = Buffer.from([0xe2, 0x82, 0xac]).toString(); assert.strictEqual(tds.encoding, 'utf-8'); ['encoding', 'readable', 'writable'].forEach((getter) => { assert.throws( - () => Reflect.get(TextDecoderStream.prototype, getter, {}), - { name: 'TypeError', message: /Cannot read private member/ } + () => Reflect.get(TextDecoderStream.prototype, getter, {}), { + name: 'TypeError', + message: /Cannot read private member/, + stack: new RegExp(`at get ${getter}`) + } ); }); }