From deceb2623898d2303c9ffa9143861b16b00f11af Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 20 Dec 2018 14:29:13 +0800 Subject: [PATCH] test: split test-whatwg-encoding-textdecoder-fatal.js Split `test-whatwg-encoding-textdecoder-fatal.js` into - `test-whatwg-encoding-custom-textdecoder-fatal.js` which is a customized version of the WPT that tests for Node.js-specific error codes. - `test-whatwg-encoding-custom-textdecoder-invalid-arg` which tests `ERR_INVALID_ARG_TYPE` PR-URL: https://github.com/nodejs/node/pull/25155 Reviewed-By: James M Snell --- ...hatwg-encoding-custom-textdecoder-fatal.js} | 14 ++------------ ...-encoding-custom-textdecoder-invalid-arg.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 12 deletions(-) rename test/parallel/{test-whatwg-encoding-textdecoder-fatal.js => test-whatwg-encoding-custom-textdecoder-fatal.js} (92%) create mode 100644 test/parallel/test-whatwg-encoding-custom-textdecoder-invalid-arg.js diff --git a/test/parallel/test-whatwg-encoding-textdecoder-fatal.js b/test/parallel/test-whatwg-encoding-custom-textdecoder-fatal.js similarity index 92% rename from test/parallel/test-whatwg-encoding-textdecoder-fatal.js rename to test/parallel/test-whatwg-encoding-custom-textdecoder-fatal.js index aa945b61b10e72..c5e4b9684b190f 100644 --- a/test/parallel/test-whatwg-encoding-textdecoder-fatal.js +++ b/test/parallel/test-whatwg-encoding-custom-textdecoder-fatal.js @@ -1,6 +1,7 @@ 'use strict'; // From: https://github.com/w3c/web-platform-tests/blob/39a67e2fff/encoding/textdecoder-fatal.html +// With the twist that we specifically test for Node.js error codes const common = require('../common'); @@ -82,21 +83,10 @@ bad.forEach((t) => { ); }); +// TODO(joyeecheung): remove this when WPT is ported { assert('fatal' in new TextDecoder()); assert.strictEqual(typeof new TextDecoder().fatal, 'boolean'); assert(!new TextDecoder().fatal); assert(new TextDecoder('utf-8', { fatal: true }).fatal); } - -{ - const notArrayBufferViewExamples = [false, {}, 1, '', new Error()]; - notArrayBufferViewExamples.forEach((invalidInputType) => { - common.expectsError(() => { - new TextDecoder(undefined, null).decode(invalidInputType); - }, { - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError - }); - }); -} diff --git a/test/parallel/test-whatwg-encoding-custom-textdecoder-invalid-arg.js b/test/parallel/test-whatwg-encoding-custom-textdecoder-invalid-arg.js new file mode 100644 index 00000000000000..a2b56ad9577271 --- /dev/null +++ b/test/parallel/test-whatwg-encoding-custom-textdecoder-invalid-arg.js @@ -0,0 +1,18 @@ +'use strict'; + +// This tests that ERR_INVALID_ARG_TYPE are thrown when +// invalid arguments are passed to TextDecoder. + +const common = require('../common'); + +{ + const notArrayBufferViewExamples = [false, {}, 1, '', new Error()]; + notArrayBufferViewExamples.forEach((invalidInputType) => { + common.expectsError(() => { + new TextDecoder(undefined, null).decode(invalidInputType); + }, { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError + }); + }); +}