From 043756d54004817e3dbee39c43f4cb8114fd1177 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Wed, 29 Jun 2022 14:08:22 +0800 Subject: [PATCH] test: fill DOMException names PR-URL: https://github.com/nodejs/node/pull/43615 Reviewed-By: Ben Noordhuis Reviewed-By: Antoine du Hamel Reviewed-By: Luigi Pinca Reviewed-By: Darshan Sen --- test/parallel/test-abortcontroller.js | 5 ++- .../test-filehandle-readablestream.js | 3 +- ...est-fs-promises-file-handle-read-worker.js | 1 + test/parallel/test-webcrypto-random.js | 7 +++-- .../test-whatwg-webstreams-transfer.js | 31 +++++++++++++------ 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/test/parallel/test-abortcontroller.js b/test/parallel/test-abortcontroller.js index aa7aa916e65d92..ed7af146e35967 100644 --- a/test/parallel/test-abortcontroller.js +++ b/test/parallel/test-abortcontroller.js @@ -245,7 +245,10 @@ const { setTimeout: sleep } = require('timers/promises'); { // Test abortSignal.throwIfAborted() - throws(() => AbortSignal.abort().throwIfAborted(), { code: 20 }); + throws(() => AbortSignal.abort().throwIfAborted(), { + code: 20, + name: 'AbortError', + }); // Does not throw because it's not aborted. const ac = new AbortController(); diff --git a/test/parallel/test-filehandle-readablestream.js b/test/parallel/test-filehandle-readablestream.js index 1a8a4b52162901..5f4ff0960b238c 100644 --- a/test/parallel/test-filehandle-readablestream.js +++ b/test/parallel/test-filehandle-readablestream.js @@ -80,7 +80,8 @@ const check = readFileSync(__filename, { encoding: 'utf8' }); const mc = new MessageChannel(); mc.port1.onmessage = common.mustNotCall(); assert.throws(() => mc.port2.postMessage(file, [file]), { - code: 25 // DataCloneError + code: 25, + name: 'DataCloneError', }); mc.port1.close(); await file.close(); diff --git a/test/parallel/test-fs-promises-file-handle-read-worker.js b/test/parallel/test-fs-promises-file-handle-read-worker.js index a1b7fbd2dfbe15..b6f262223e2777 100644 --- a/test/parallel/test-fs-promises-file-handle-read-worker.js +++ b/test/parallel/test-fs-promises-file-handle-read-worker.js @@ -29,6 +29,7 @@ if (isMainThread || !workerData) { }); }, { code: 25, + name: 'DataCloneError', }); } finally { await handle.close(); diff --git a/test/parallel/test-webcrypto-random.js b/test/parallel/test-webcrypto-random.js index 73089fe7b49094..4c5d54f640f8cf 100644 --- a/test/parallel/test-webcrypto-random.js +++ b/test/parallel/test-webcrypto-random.js @@ -63,8 +63,9 @@ for (const ctor of intTypedConstructors) { } if (kData !== undefined) { - assert.throws(() => webcrypto.getRandomValues(kData), { - code: 22 - }); + assert.throws( + () => webcrypto.getRandomValues(kData), + { name: 'QuotaExceededError', code: 22 }, + ); } } diff --git a/test/parallel/test-whatwg-webstreams-transfer.js b/test/parallel/test-whatwg-webstreams-transfer.js index 9699dc8dc794e8..1923cca13bcc6f 100644 --- a/test/parallel/test-whatwg-webstreams-transfer.js +++ b/test/parallel/test-whatwg-webstreams-transfer.js @@ -253,14 +253,16 @@ const theData = 'hello'; start(c) { controller = c; }, cancel: common.mustCall((error) => { - assert.strictEqual(error.code, 25); // DataCloneError + assert.strictEqual(error.code, 25); + assert.strictEqual(error.name, 'DataCloneError'); }), }); port1.onmessage = ({ data }) => { const reader = data.getReader(); assert.rejects(reader.read(), { - code: 25, // DataCloneError + code: 25, + name: 'DataCloneError', }); port1.close(); }; @@ -354,7 +356,10 @@ const theData = 'hello'; const source = { abort: common.mustCall((error) => { - process.nextTick(() => assert.strictEqual(error.code, 25)); + process.nextTick(() => { + assert.strictEqual(error.code, 25); + assert.strictEqual(error.name, 'DataCloneError'); + }); }) }; @@ -366,7 +371,8 @@ const theData = 'hello'; const m = new WebAssembly.Memory({ initial: 1 }); assert.rejects(writer.abort(m), { - code: 25 + code: 25, + name: 'DataCloneError', }); port1.close(); }); @@ -437,7 +443,10 @@ const theData = 'hello'; { const source = { cancel: common.mustCall((error) => { - process.nextTick(() => assert(error.code, 25)); + process.nextTick(() => { + assert.strictEqual(error.code, 25); + assert.strictEqual(error.name, 'DataCloneError'); + }); }), }; @@ -455,7 +464,8 @@ const theData = 'hello'; reader.closed.then(common.mustCall()); assert.rejects(cancel, { - code: 25 + code: 25, + name: 'DataCloneError', }); port1.close(); @@ -469,6 +479,7 @@ const theData = 'hello'; abort: common.mustCall((error) => { process.nextTick(() => { assert.strictEqual(error.code, 25); + assert.strictEqual(error.name, 'DataCloneError'); }); }), }; @@ -481,7 +492,7 @@ const theData = 'hello'; const m = new WebAssembly.Memory({ initial: 1 }); const writer = data.getWriter(); const write = writer.write(m); - assert.rejects(write, { code: 25 }); + assert.rejects(write, { code: 25, name: 'DataCloneError' }); port1.close(); }); @@ -492,12 +503,14 @@ const theData = 'hello'; const readable = new ReadableStream(); readable.getReader(); assert.throws(() => readable[kTransfer](), { - code: 25 + code: 25, + name: 'DataCloneError', }); const writable = new WritableStream(); writable.getWriter(); assert.throws(() => writable[kTransfer](), { - code: 25 + code: 25, + name: 'DataCloneError', }); }