|
1 | 1 | 'use strict';
|
2 |
| -const common = require('../common'); |
3 |
| - |
4 |
| -if (!common.hasCrypto) { |
5 |
| - common.skip('missing crypto'); |
6 |
| -} |
7 |
| - |
| 2 | +const { hasCrypto } = require('../common'); |
| 3 | +const { test } = require('node:test'); |
8 | 4 | const assert = require('assert');
|
9 | 5 |
|
| 6 | +// Turn off no-restricted-properties because we are testing deepEqual! |
| 7 | +/* eslint-disable no-restricted-properties */ |
| 8 | + |
10 | 9 | // Disable colored output to prevent color codes from breaking assertion
|
11 | 10 | // message comparisons. This should only be an issue when process.stdout
|
12 | 11 | // is a TTY.
|
13 | 12 | if (process.stdout.isTTY)
|
14 | 13 | process.env.NODE_DISABLE_COLORS = '1';
|
15 | 14 |
|
16 |
| -// Turn off no-restricted-properties because we are testing deepEqual! |
17 |
| -/* eslint-disable no-restricted-properties */ |
| 15 | +test('', { skip: !hasCrypto }, () => { |
| 16 | + // See https://github.com/nodejs/node/issues/10258 |
| 17 | + { |
| 18 | + const date = new Date('2016'); |
| 19 | + function FakeDate() {} |
| 20 | + FakeDate.prototype = Date.prototype; |
| 21 | + const fake = new FakeDate(); |
18 | 22 |
|
19 |
| -// See https://github.com/nodejs/node/issues/10258 |
20 |
| -{ |
21 |
| - const date = new Date('2016'); |
22 |
| - function FakeDate() {} |
23 |
| - FakeDate.prototype = Date.prototype; |
24 |
| - const fake = new FakeDate(); |
| 23 | + assert.notDeepEqual(date, fake); |
| 24 | + assert.notDeepEqual(fake, date); |
25 | 25 |
|
26 |
| - assert.notDeepEqual(date, fake); |
27 |
| - assert.notDeepEqual(fake, date); |
| 26 | + // For deepStrictEqual we check the runtime type, |
| 27 | + // then reveal the fakeness of the fake date |
| 28 | + assert.throws( |
| 29 | + () => assert.deepStrictEqual(date, fake), |
| 30 | + { |
| 31 | + message: 'Expected values to be strictly deep-equal:\n' + |
| 32 | + '+ actual - expected\n\n+ 2016-01-01T00:00:00.000Z\n- Date {}' |
| 33 | + } |
| 34 | + ); |
| 35 | + assert.throws( |
| 36 | + () => assert.deepStrictEqual(fake, date), |
| 37 | + { |
| 38 | + message: 'Expected values to be strictly deep-equal:\n' + |
| 39 | + '+ actual - expected\n\n+ Date {}\n- 2016-01-01T00:00:00.000Z' |
| 40 | + } |
| 41 | + ); |
| 42 | + } |
28 | 43 |
|
29 |
| - // For deepStrictEqual we check the runtime type, |
30 |
| - // then reveal the fakeness of the fake date |
31 |
| - assert.throws( |
32 |
| - () => assert.deepStrictEqual(date, fake), |
33 |
| - { |
34 |
| - message: 'Expected values to be strictly deep-equal:\n' + |
35 |
| - '+ actual - expected\n\n+ 2016-01-01T00:00:00.000Z\n- Date {}' |
36 |
| - } |
37 |
| - ); |
38 |
| - assert.throws( |
39 |
| - () => assert.deepStrictEqual(fake, date), |
40 |
| - { |
41 |
| - message: 'Expected values to be strictly deep-equal:\n' + |
42 |
| - '+ actual - expected\n\n+ Date {}\n- 2016-01-01T00:00:00.000Z' |
| 44 | + { // At the moment global has its own type tag |
| 45 | + const fakeGlobal = {}; |
| 46 | + Object.setPrototypeOf(fakeGlobal, Object.getPrototypeOf(global)); |
| 47 | + for (const prop of Object.keys(global)) { |
| 48 | + fakeGlobal[prop] = global[prop]; |
43 | 49 | }
|
44 |
| - ); |
45 |
| -} |
46 |
| - |
47 |
| -{ // At the moment global has its own type tag |
48 |
| - const fakeGlobal = {}; |
49 |
| - Object.setPrototypeOf(fakeGlobal, Object.getPrototypeOf(global)); |
50 |
| - for (const prop of Object.keys(global)) { |
51 |
| - fakeGlobal[prop] = global[prop]; |
| 50 | + assert.notDeepEqual(fakeGlobal, global); |
| 51 | + // Message will be truncated anyway, don't validate |
| 52 | + assert.throws(() => assert.deepStrictEqual(fakeGlobal, global), |
| 53 | + assert.AssertionError); |
52 | 54 | }
|
53 |
| - assert.notDeepEqual(fakeGlobal, global); |
54 |
| - // Message will be truncated anyway, don't validate |
55 |
| - assert.throws(() => assert.deepStrictEqual(fakeGlobal, global), |
56 |
| - assert.AssertionError); |
57 |
| -} |
58 | 55 |
|
59 |
| -{ // At the moment process has its own type tag |
60 |
| - const fakeProcess = {}; |
61 |
| - Object.setPrototypeOf(fakeProcess, Object.getPrototypeOf(process)); |
62 |
| - for (const prop of Object.keys(process)) { |
63 |
| - fakeProcess[prop] = process[prop]; |
| 56 | + { // At the moment process has its own type tag |
| 57 | + const fakeProcess = {}; |
| 58 | + Object.setPrototypeOf(fakeProcess, Object.getPrototypeOf(process)); |
| 59 | + for (const prop of Object.keys(process)) { |
| 60 | + fakeProcess[prop] = process[prop]; |
| 61 | + } |
| 62 | + assert.notDeepEqual(fakeProcess, process); |
| 63 | + // Message will be truncated anyway, don't validate |
| 64 | + assert.throws(() => assert.deepStrictEqual(fakeProcess, process), |
| 65 | + assert.AssertionError); |
64 | 66 | }
|
65 |
| - assert.notDeepEqual(fakeProcess, process); |
66 |
| - // Message will be truncated anyway, don't validate |
67 |
| - assert.throws(() => assert.deepStrictEqual(fakeProcess, process), |
68 |
| - assert.AssertionError); |
69 |
| -} |
| 67 | +}); |
70 | 68 | /* eslint-enable */
|
0 commit comments