Skip to content

Commit b36f8c2

Browse files
jasnelltargos
authored andcommitted
test: update multiple assert tests to use node:test
PR-URL: #54585 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent bb9f77d commit b36f8c2

File tree

6 files changed

+992
-961
lines changed

6 files changed

+992
-961
lines changed

test/parallel/test-assert-checktag.js

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,68 @@
11
'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');
84
const assert = require('assert');
95

6+
// Turn off no-restricted-properties because we are testing deepEqual!
7+
/* eslint-disable no-restricted-properties */
8+
109
// Disable colored output to prevent color codes from breaking assertion
1110
// message comparisons. This should only be an issue when process.stdout
1211
// is a TTY.
1312
if (process.stdout.isTTY)
1413
process.env.NODE_DISABLE_COLORS = '1';
1514

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();
1822

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);
2525

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+
}
2843

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];
4349
}
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);
5254
}
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-
}
5855

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);
6466
}
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+
});
7068
/* eslint-enable */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy