test: fix textdecoder test for small-icu builds

The `Shift_JIS` encoding may not be available, e.g. when Node.js is
configured with `--with-intl=small-icu`.

PR-URL: https://github.com/nodejs/node/pull/45225
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Kohei Ueno <kohei.ueno119@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Steven R Loomis <srloomis@us.ibm.com>
This commit is contained in:
Richard Lau 2022-10-30 19:52:37 +00:00 committed by GitHub
parent 77c0448ede
commit e43ecd5fec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -201,8 +201,13 @@ if (common.hasIntl) {
}
if (common.hasIntl) {
const decoder = new TextDecoder('Shift_JIS');
const chunk = new Uint8Array([-1]);
const str = decoder.decode(chunk);
assert.strictEqual(str, '\ufffd');
try {
const decoder = new TextDecoder('Shift_JIS');
const chunk = new Uint8Array([-1]);
const str = decoder.decode(chunk);
assert.strictEqual(str, '\ufffd');
} catch (e) {
// Encoding may not be available, e.g. small-icu builds
assert.strictEqual(e.code, 'ERR_ENCODING_NOT_SUPPORTED');
}
}