2017-01-31 19:51:54 +00:00
|
|
|
'use strict';
|
2024-08-27 05:08:07 +00:00
|
|
|
const { hasCrypto } = require('../common');
|
|
|
|
const { test } = require('node:test');
|
2017-01-31 19:51:54 +00:00
|
|
|
const assert = require('assert');
|
|
|
|
|
2024-08-27 05:08:07 +00:00
|
|
|
// Turn off no-restricted-properties because we are testing deepEqual!
|
|
|
|
/* eslint-disable no-restricted-properties */
|
|
|
|
|
2018-05-13 13:28:25 +00:00
|
|
|
// Disable colored output to prevent color codes from breaking assertion
|
|
|
|
// message comparisons. This should only be an issue when process.stdout
|
|
|
|
// is a TTY.
|
|
|
|
if (process.stdout.isTTY)
|
|
|
|
process.env.NODE_DISABLE_COLORS = '1';
|
|
|
|
|
2024-08-27 05:08:07 +00:00
|
|
|
test('', { skip: !hasCrypto }, () => {
|
|
|
|
// See https://github.com/nodejs/node/issues/10258
|
|
|
|
{
|
|
|
|
const date = new Date('2016');
|
|
|
|
function FakeDate() {}
|
|
|
|
FakeDate.prototype = Date.prototype;
|
|
|
|
const fake = new FakeDate();
|
2017-01-31 19:51:54 +00:00
|
|
|
|
2024-08-27 05:08:07 +00:00
|
|
|
assert.notDeepEqual(date, fake);
|
|
|
|
assert.notDeepEqual(fake, date);
|
2017-01-31 19:51:54 +00:00
|
|
|
|
2024-08-27 05:08:07 +00:00
|
|
|
// For deepStrictEqual we check the runtime type,
|
|
|
|
// then reveal the fakeness of the fake date
|
|
|
|
assert.throws(
|
|
|
|
() => assert.deepStrictEqual(date, fake),
|
|
|
|
{
|
|
|
|
message: 'Expected values to be strictly deep-equal:\n' +
|
2024-10-17 16:02:54 +00:00
|
|
|
'+ actual - expected\n' +
|
|
|
|
'\n' +
|
|
|
|
'+ 2016-01-01T00:00:00.000Z\n' +
|
|
|
|
'- Date {}\n'
|
2024-08-27 05:08:07 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
assert.throws(
|
|
|
|
() => assert.deepStrictEqual(fake, date),
|
|
|
|
{
|
|
|
|
message: 'Expected values to be strictly deep-equal:\n' +
|
2024-10-17 16:02:54 +00:00
|
|
|
'+ actual - expected\n' +
|
|
|
|
'\n' +
|
|
|
|
'+ Date {}\n' +
|
|
|
|
'- 2016-01-01T00:00:00.000Z\n'
|
2024-08-27 05:08:07 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2017-01-31 19:51:54 +00:00
|
|
|
|
2024-08-27 05:08:07 +00:00
|
|
|
{ // At the moment global has its own type tag
|
|
|
|
const fakeGlobal = {};
|
|
|
|
Object.setPrototypeOf(fakeGlobal, Object.getPrototypeOf(global));
|
|
|
|
for (const prop of Object.keys(global)) {
|
|
|
|
fakeGlobal[prop] = global[prop];
|
2018-03-12 21:14:24 +00:00
|
|
|
}
|
2024-08-27 05:08:07 +00:00
|
|
|
assert.notDeepEqual(fakeGlobal, global);
|
|
|
|
// Message will be truncated anyway, don't validate
|
|
|
|
assert.throws(() => assert.deepStrictEqual(fakeGlobal, global),
|
|
|
|
assert.AssertionError);
|
2017-01-31 19:51:54 +00:00
|
|
|
}
|
|
|
|
|
2024-08-27 05:08:07 +00:00
|
|
|
{ // At the moment process has its own type tag
|
|
|
|
const fakeProcess = {};
|
|
|
|
Object.setPrototypeOf(fakeProcess, Object.getPrototypeOf(process));
|
|
|
|
for (const prop of Object.keys(process)) {
|
|
|
|
fakeProcess[prop] = process[prop];
|
|
|
|
}
|
|
|
|
assert.notDeepEqual(fakeProcess, process);
|
|
|
|
// Message will be truncated anyway, don't validate
|
|
|
|
assert.throws(() => assert.deepStrictEqual(fakeProcess, process),
|
|
|
|
assert.AssertionError);
|
2017-01-31 19:51:54 +00:00
|
|
|
}
|
2024-08-27 05:08:07 +00:00
|
|
|
});
|
2017-01-31 19:51:54 +00:00
|
|
|
/* eslint-enable */
|