Skip to content

Commit a628455

Browse files
Trottgibfahn
authored andcommitted
test: add block scoping to test-assert-deep
Add block scoping to test-assert-deep.js to reduce likelihood of one test case having side effects that affect another test case. PR-URL: #16532 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
1 parent 8c0c456 commit a628455

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

test/parallel/test-assert-deep.js

+41-35
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,22 @@ assert.throws(() => assert.deepStrictEqual(arr, buf),
3434
re`${arr} deepStrictEqual ${buf}`);
3535
assert.doesNotThrow(() => assert.deepEqual(arr, buf));
3636

37-
const buf2 = Buffer.from(arr);
38-
buf2.prop = 1;
37+
{
38+
const buf2 = Buffer.from(arr);
39+
buf2.prop = 1;
3940

40-
assert.throws(() => assert.deepStrictEqual(buf2, buf),
41-
re`${buf2} deepStrictEqual ${buf}`);
42-
assert.doesNotThrow(() => assert.deepEqual(buf2, buf));
41+
assert.throws(() => assert.deepStrictEqual(buf2, buf),
42+
re`${buf2} deepStrictEqual ${buf}`);
43+
assert.doesNotThrow(() => assert.deepEqual(buf2, buf));
44+
}
4345

44-
const arr2 = new Uint8Array([120, 121, 122, 10]);
45-
arr2.prop = 5;
46-
assert.throws(() => assert.deepStrictEqual(arr, arr2),
47-
re`${arr} deepStrictEqual ${arr2}`);
48-
assert.doesNotThrow(() => assert.deepEqual(arr, arr2));
46+
{
47+
const arr2 = new Uint8Array([120, 121, 122, 10]);
48+
arr2.prop = 5;
49+
assert.throws(() => assert.deepStrictEqual(arr, arr2),
50+
re`${arr} deepStrictEqual ${arr2}`);
51+
assert.doesNotThrow(() => assert.deepEqual(arr, arr2));
52+
}
4953

5054
const date = new Date('2016');
5155

@@ -85,31 +89,33 @@ assert.throws(() => assert.deepStrictEqual(re1, re2),
8589

8690
// For these weird cases, deepEqual should pass (at least for now),
8791
// but deepStrictEqual should throw.
88-
const similar = new Set([
89-
{ 0: '1' }, // Object
90-
{ 0: 1 }, // Object
91-
new String('1'), // Object
92-
['1'], // Array
93-
[1], // Array
94-
date2, // Date with this[0] = '1'
95-
re2, // RegExp with this[0] = '1'
96-
new Int8Array([1]), // Int8Array
97-
new Uint8Array([1]), // Uint8Array
98-
new Int16Array([1]), // Int16Array
99-
new Uint16Array([1]), // Uint16Array
100-
new Int32Array([1]), // Int32Array
101-
new Uint32Array([1]), // Uint32Array
102-
Buffer.from([1]),
103-
// Arguments {'0': '1'} is not here
104-
// See https://github.com/nodejs/node-v0.x-archive/pull/7178
105-
]);
106-
107-
for (const a of similar) {
108-
for (const b of similar) {
109-
if (a !== b) {
110-
assert.deepEqual(a, b);
111-
assert.throws(() => assert.deepStrictEqual(a, b),
112-
re`${a} deepStrictEqual ${b}`);
92+
{
93+
const similar = new Set([
94+
{ 0: '1' }, // Object
95+
{ 0: 1 }, // Object
96+
new String('1'), // Object
97+
['1'], // Array
98+
[1], // Array
99+
date2, // Date with this[0] = '1'
100+
re2, // RegExp with this[0] = '1'
101+
new Int8Array([1]), // Int8Array
102+
new Uint8Array([1]), // Uint8Array
103+
new Int16Array([1]), // Int16Array
104+
new Uint16Array([1]), // Uint16Array
105+
new Int32Array([1]), // Int32Array
106+
new Uint32Array([1]), // Uint32Array
107+
Buffer.from([1]),
108+
// Arguments {'0': '1'} is not here
109+
// See https://github.com/nodejs/node-v0.x-archive/pull/7178
110+
]);
111+
112+
for (const a of similar) {
113+
for (const b of similar) {
114+
if (a !== b) {
115+
assert.deepEqual(a, b);
116+
assert.throws(() => assert.deepStrictEqual(a, b),
117+
re`${a} deepStrictEqual ${b}`);
118+
}
113119
}
114120
}
115121
}

0 commit comments

Comments
 (0)