Skip to content

Commit bd1cca1

Browse files
committed
refactor(harden): Adapt make-hardener test
1 parent de30ffa commit bd1cca1

File tree

1 file changed

+35
-36
lines changed

1 file changed

+35
-36
lines changed

packages/harden/test/make-hardener.test.js

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,65 @@
11
// @ts-nocheck
22

33
import test from 'ava';
4-
import { makeHardener } from '../src/make-hardener.js';
5-
import { assert } from '../src/error/assert.js';
4+
import { makeHardener } from '../make-hardener.js';
65

7-
const { quote: q } = assert;
6+
const { stringify: q } = JSON;
87

98
test('makeHardener', t => {
10-
const h = makeHardener();
9+
const h = makeHardener({ traversePrototypes: true });
1110
const o = { a: {} };
1211
t.is(h(o), o);
13-
t.truthy(Object.isFrozen(o));
14-
t.truthy(Object.isFrozen(o.a));
12+
t.true(Object.isFrozen(o));
13+
t.true(Object.isFrozen(o.a));
1514
});
1615

1716
test('harden the same thing twice', t => {
18-
const h = makeHardener();
17+
const h = makeHardener({ traversePrototypes: true });
1918
const o = { a: {} };
2019
t.is(h(o), o);
2120
t.is(h(o), o);
22-
t.truthy(Object.isFrozen(o));
23-
t.truthy(Object.isFrozen(o.a));
21+
t.true(Object.isFrozen(o));
22+
t.true(Object.isFrozen(o.a));
2423
});
2524

2625
test('harden objects with cycles', t => {
27-
const h = makeHardener();
26+
const h = makeHardener({ traversePrototypes: true });
2827
const o = { a: {} };
2928
o.a.foo = o;
3029
t.is(h(o), o);
31-
t.truthy(Object.isFrozen(o));
32-
t.truthy(Object.isFrozen(o.a));
30+
t.true(Object.isFrozen(o));
31+
t.true(Object.isFrozen(o.a));
3332
});
3433

3534
test('harden overlapping objects', t => {
36-
const h = makeHardener();
35+
const h = makeHardener({ traversePrototypes: true });
3736
const o1 = { a: {} };
3837
const o2 = { a: o1.a };
3938
t.is(h(o1), o1);
40-
t.truthy(Object.isFrozen(o1));
41-
t.truthy(Object.isFrozen(o1.a));
39+
t.true(Object.isFrozen(o1));
40+
t.true(Object.isFrozen(o1.a));
4241
t.falsy(Object.isFrozen(o2));
4342
t.is(h(o2), o2);
44-
t.truthy(Object.isFrozen(o2));
43+
t.true(Object.isFrozen(o2));
4544
});
4645

4746
test('harden up prototype chain', t => {
48-
const h = makeHardener();
47+
const h = makeHardener({ traversePrototypes: true });
4948
const a = { a: 1 };
5049
const b = { b: 1, __proto__: a };
5150
const c = { c: 1, __proto__: b };
5251

5352
h(c);
54-
t.truthy(Object.isFrozen(a));
53+
t.true(Object.isFrozen(a));
5554
});
5655

5756
test('harden tolerates objects with null prototypes', t => {
58-
const h = makeHardener();
57+
const h = makeHardener({ traversePrototypes: true });
5958
const o = { a: 1 };
6059
Object.setPrototypeOf(o, null);
6160
t.is(h(o), o);
62-
t.truthy(Object.isFrozen(o));
63-
t.truthy(Object.isFrozen(o.a));
61+
t.true(Object.isFrozen(o));
62+
t.true(Object.isFrozen(o.a));
6463
});
6564

6665
test('harden typed arrays', t => {
@@ -79,11 +78,11 @@ test('harden typed arrays', t => {
7978
];
8079

8180
for (const TypedArray of typedArrayConstructors) {
82-
const h = makeHardener();
81+
const h = makeHardener({ traversePrototypes: true });
8382
const a = new TypedArray(1);
8483

8584
t.is(h(a), a, `harden ${TypedArray}`);
86-
t.truthy(Object.isSealed(a));
85+
t.true(Object.isSealed(a));
8786
const descriptor = Object.getOwnPropertyDescriptor(a, '0');
8887
t.is(descriptor.value, a[0]);
8988
// Failed in Node.js 14 and earlier due to an engine bug:
@@ -107,7 +106,7 @@ test('harden typed arrays', t => {
107106
});
108107

109108
test('harden typed arrays and their expandos', t => {
110-
const h = makeHardener();
109+
const h = makeHardener({ traversePrototypes: true });
111110
const a = new Uint8Array(1);
112111
const b = new Uint8Array(1);
113112

@@ -218,29 +217,29 @@ test('harden typed arrays and their expandos', t => {
218217
{ a: { b: { c: 10 } } },
219218
`hardened typed array expando ${q(key)} value shape`,
220219
);
221-
t.truthy(
220+
t.true(
222221
Object.isFrozen(descriptor.value),
223222
`hardened typed array expando ${q(key)} value is frozen`,
224223
);
225-
t.truthy(
224+
t.true(
226225
Object.isFrozen(descriptor.value.a),
227226
`hardened typed array expando ${q(key)} value property is frozen`,
228227
);
229-
t.truthy(
228+
t.true(
230229
Object.isFrozen(descriptor.value.a.b),
231230
`hardened typed array expando ${q(key)} value subproperty is frozen`,
232231
);
233-
t.truthy(
232+
t.true(
234233
Object.isFrozen(descriptor.value.a.b.c),
235234
`hardened typed array expando ${q(key)} value sub-subproperty is frozen`,
236235
);
237236
}
238237

239-
t.truthy(Object.isSealed(a), 'hardened typed array is sealed');
238+
t.true(Object.isSealed(a), 'hardened typed array is sealed');
240239
});
241240

242241
test('hardening makes writable properties readonly even if non-configurable', t => {
243-
const h = makeHardener();
242+
const h = makeHardener({ traversePrototypes: true });
244243
const o = {};
245244
Object.defineProperty(o, 'x', {
246245
value: 10,
@@ -259,7 +258,7 @@ test('hardening makes writable properties readonly even if non-configurable', t
259258
});
260259

261260
test('harden a typed array with a writable non-configurable expando', t => {
262-
const h = makeHardener();
261+
const h = makeHardener({ traversePrototypes: true });
263262
const a = new Uint8Array(1);
264263
Object.defineProperty(a, 'x', {
265264
value: 'A',
@@ -269,7 +268,7 @@ test('harden a typed array with a writable non-configurable expando', t => {
269268
});
270269

271270
t.is(h(a), a);
272-
t.truthy(Object.isSealed(a));
271+
t.true(Object.isSealed(a));
273272

274273
t.deepEqual(
275274
{
@@ -283,14 +282,14 @@ test('harden a typed array with a writable non-configurable expando', t => {
283282
});
284283

285284
test('harden a typed array subclass', t => {
286-
const h = makeHardener();
285+
const h = makeHardener({ traversePrototypes: true });
287286

288287
class Ooint8Array extends Uint8Array {
289288
oo = 'ghosts';
290289
}
291290
h(Ooint8Array);
292-
t.truthy(Object.isFrozen(Ooint8Array.prototype));
293-
t.truthy(Object.isFrozen(Object.getPrototypeOf(Ooint8Array.prototype)));
291+
t.true(Object.isFrozen(Ooint8Array.prototype));
292+
t.true(Object.isFrozen(Object.getPrototypeOf(Ooint8Array.prototype)));
294293

295294
const a = new Ooint8Array(1);
296295
t.is(h(a), a);
@@ -301,7 +300,7 @@ test('harden a typed array subclass', t => {
301300
configurable: false,
302301
enumerable: true,
303302
});
304-
t.truthy(Object.isSealed(a));
303+
t.true(Object.isSealed(a));
305304
});
306305

307306
test('harden depends on invariant: typed arrays have no storage for integer indexes beyond length', t => {

0 commit comments

Comments
 (0)