test: enforce strict mode in test-zlib-const

Instead of checking that assignments fail silently in sloppy mode, check
that they throw in strict mode.

PR-URL: https://github.com/nodejs/node/pull/56689
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Rich Trott 2025-01-23 20:38:49 -08:00 committed by GitHub
parent 869ea331f3
commit 08eeddfa83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
/* eslint-disable strict */ 'use strict';
require('../common'); require('../common');
const assert = require('assert'); const assert = require('assert');
@ -9,27 +9,17 @@ assert.strictEqual(zlib.constants.Z_OK, 0,
'Expected Z_OK to be 0;', 'Expected Z_OK to be 0;',
`got ${zlib.constants.Z_OK}`, `got ${zlib.constants.Z_OK}`,
].join(' ')); ].join(' '));
zlib.constants.Z_OK = 1;
assert.strictEqual(zlib.constants.Z_OK, 0, assert.throws(() => { zlib.constants.Z_OK = 1; },
[ TypeError, 'zlib.constants.Z_OK should be immutable');
'Z_OK should be immutable.',
`Expected to get 0, got ${zlib.constants.Z_OK}`,
].join(' '));
assert.strictEqual(zlib.codes.Z_OK, 0, assert.strictEqual(zlib.codes.Z_OK, 0,
`Expected Z_OK to be 0; got ${zlib.codes.Z_OK}`); `Expected Z_OK to be 0; got ${zlib.codes.Z_OK}`);
zlib.codes.Z_OK = 1; assert.throws(() => { zlib.codes.Z_OK = 1; },
assert.strictEqual(zlib.codes.Z_OK, 0, TypeError, 'zlib.codes.Z_OK should be immutable');
[
'Z_OK should be immutable.', assert.throws(() => { zlib.codes = { Z_OK: 1 }; },
`Expected to get 0, got ${zlib.codes.Z_OK}`, TypeError, 'zlib.codes should be immutable');
].join(' '));
zlib.codes = { Z_OK: 1 };
assert.strictEqual(zlib.codes.Z_OK, 0,
[
'Z_OK should be immutable.',
`Expected to get 0, got ${zlib.codes.Z_OK}`,
].join(' '));
assert.ok(Object.isFrozen(zlib.codes), assert.ok(Object.isFrozen(zlib.codes),
[ [