Skip to content

Commit 1e749ca

Browse files
committed
test: use node:test in test-report-config
1 parent 4f1c27a commit 1e749ca

File tree

1 file changed

+83
-98
lines changed

1 file changed

+83
-98
lines changed

test/report/test-report-config.js

Lines changed: 83 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -2,112 +2,97 @@
22
'use strict';
33
const common = require('../common');
44
const assert = require('assert');
5+
const { test } = require('node:test');
56

6-
// Verify that process.report.directory behaves properly.
7-
assert.strictEqual(process.report.directory, '');
8-
process.report.directory = __dirname;
9-
assert.strictEqual(process.report.directory, __dirname);
10-
assert.throws(() => {
11-
process.report.directory = {};
12-
}, { code: 'ERR_INVALID_ARG_TYPE' });
13-
assert.strictEqual(process.report.directory, __dirname);
7+
const invalidArgType = { code: 'ERR_INVALID_ARG_TYPE' };
8+
const cases = [
9+
{
10+
key: 'directory',
11+
value: '',
12+
newValue: __dirname,
13+
throwingSetters: [[{}, invalidArgType]],
14+
},
15+
{
16+
key: 'filename',
17+
value: '',
18+
newValue: 'test-report.json',
19+
throwingSetters: [[{}, invalidArgType]],
20+
},
21+
{
22+
key: 'reportOnFatalError',
23+
value: true,
24+
newValue: false,
25+
throwingSetters: [[{}, invalidArgType]],
26+
},
27+
{
28+
key: 'reportOnUncaughtException',
29+
value: true,
30+
newValue: false,
31+
throwingSetters: [[{}, invalidArgType]],
32+
},
33+
{
34+
key: 'reportOnSignal',
35+
value: false,
36+
newValue: true,
37+
throwingSetters: [[{}, invalidArgType]],
38+
},
39+
{
40+
key: 'compact',
41+
value: true,
42+
newValue: false,
43+
throwingSetters: [[{}, invalidArgType]],
44+
},
45+
{
46+
key: 'excludeNetwork',
47+
value: false,
48+
newValue: true,
49+
throwingSetters: [[{}, invalidArgType]],
50+
},
51+
];
1452

15-
// Verify that process.report.filename behaves properly.
16-
assert.strictEqual(process.report.filename, '');
17-
process.report.filename = 'test-report.json';
18-
assert.strictEqual(process.report.filename, 'test-report.json');
19-
assert.throws(() => {
20-
process.report.filename = {};
21-
}, { code: 'ERR_INVALID_ARG_TYPE' });
22-
assert.strictEqual(process.report.filename, 'test-report.json');
53+
if (!common.isWindows) {
54+
cases.push({
55+
key: 'signal',
56+
value: 'SIGUSR1',
57+
newValue: 'SIGUSR2',
58+
throwingSetters: [
59+
[{}, invalidArgType],
60+
['foo', { code: 'ERR_UNKNOWN_SIGNAL', message: 'Unknown signal: foo' }],
61+
['sigusr1', { code: 'ERR_UNKNOWN_SIGNAL',
62+
message: 'Unknown signal: sigusr1 (signals must use all capital letters)' }],
63+
],
64+
});
2365

24-
// Verify that process.report.reportOnFatalError behaves properly.
25-
assert.strictEqual(process.report.reportOnFatalError, true);
26-
process.report.reportOnFatalError = false;
27-
assert.strictEqual(process.report.reportOnFatalError, false);
28-
process.report.reportOnFatalError = true;
29-
assert.strictEqual(process.report.reportOnFatalError, true);
30-
assert.throws(() => {
31-
process.report.reportOnFatalError = {};
32-
}, { code: 'ERR_INVALID_ARG_TYPE' });
33-
assert.strictEqual(process.report.reportOnFatalError, true);
66+
test('Verify that the interaction between reportOnSignal and signal is correct.', (t) => {
67+
process.report.reportOnSignal = false;
68+
t.assert.strictEqual(process.listenerCount('SIGUSR2'), 0);
3469

70+
process.report.reportOnSignal = true;
71+
t.assert.strictEqual(process.listenerCount('SIGUSR2'), 1);
3572

36-
// Verify that process.report.reportOnUncaughtException behaves properly.
37-
assert.strictEqual(process.report.reportOnUncaughtException, true);
38-
process.report.reportOnUncaughtException = false;
39-
assert.strictEqual(process.report.reportOnUncaughtException, false);
40-
process.report.reportOnUncaughtException = true;
41-
assert.strictEqual(process.report.reportOnUncaughtException, true);
42-
assert.throws(() => {
43-
process.report.reportOnUncaughtException = {};
44-
}, { code: 'ERR_INVALID_ARG_TYPE' });
45-
assert.strictEqual(process.report.reportOnUncaughtException, true);
73+
process.report.signal = 'SIGUSR1';
74+
t.assert.strictEqual(process.listenerCount('SIGUSR2'), 0);
75+
t.assert.strictEqual(process.listenerCount('SIGUSR1'), 1);
4676

47-
// Verify that process.report.reportOnSignal behaves properly.
48-
assert.strictEqual(process.report.reportOnSignal, true);
49-
process.report.reportOnSignal = false;
50-
assert.strictEqual(process.report.reportOnSignal, false);
51-
process.report.reportOnSignal = true;
52-
assert.strictEqual(process.report.reportOnSignal, true);
53-
assert.throws(() => {
54-
process.report.reportOnSignal = {};
55-
}, { code: 'ERR_INVALID_ARG_TYPE' });
56-
assert.strictEqual(process.report.reportOnSignal, true);
77+
process.report.reportOnSignal = false;
78+
t.assert.strictEqual(process.listenerCount('SIGUSR1'), 0);
79+
});
80+
}
5781

58-
// Verify that process.report.reportCompact behaves properly.
59-
assert.strictEqual(process.report.compact, true);
60-
process.report.compact = false;
61-
assert.strictEqual(process.report.compact, false);
62-
process.report.compact = true;
63-
assert.strictEqual(process.report.compact, true);
64-
assert.throws(() => {
65-
process.report.compact = {};
66-
}, { code: 'ERR_INVALID_ARG_TYPE' });
67-
assert.strictEqual(process.report.compact, true);
82+
for (const testCase of cases) {
83+
const { key, value, newValue, throwingSetters } = testCase;
6884

69-
// Verify that process.report.excludeNetwork behaves properly.
70-
assert.strictEqual(process.report.excludeNetwork, false);
71-
process.report.excludeNetwork = true;
72-
assert.strictEqual(process.report.excludeNetwork, true);
73-
process.report.excludeNetwork = false;
74-
assert.strictEqual(process.report.excludeNetwork, false);
75-
assert.throws(() => {
76-
process.report.excludeNetwork = {};
77-
}, { code: 'ERR_INVALID_ARG_TYPE' });
78-
assert.strictEqual(process.report.excludeNetwork, false);
85+
test(`Verify that process.report.${key} behaves properly`, (t) => {
86+
t.assert.strictEqual(process.report[key], value);
7987

80-
if (!common.isWindows) {
81-
// Verify that process.report.signal behaves properly.
82-
assert.strictEqual(process.report.signal, 'SIGUSR2');
83-
assert.throws(() => {
84-
process.report.signal = {};
85-
}, { code: 'ERR_INVALID_ARG_TYPE' });
86-
assert.throws(() => {
87-
process.report.signal = 'foo';
88-
}, {
89-
code: 'ERR_UNKNOWN_SIGNAL',
90-
message: 'Unknown signal: foo',
91-
});
92-
assert.throws(() => {
93-
process.report.signal = 'sigusr1';
94-
}, {
95-
code: 'ERR_UNKNOWN_SIGNAL',
96-
message: 'Unknown signal: sigusr1 (signals must use all capital letters)',
97-
});
98-
assert.strictEqual(process.report.signal, 'SIGUSR2');
99-
process.report.signal = 'SIGUSR1';
100-
assert.strictEqual(process.report.signal, 'SIGUSR1');
88+
process.report[key] = newValue;
89+
t.assert.strictEqual(process.report[key], newValue);
10190

102-
// Verify that the interaction between reportOnSignal and signal is correct.
103-
process.report.signal = 'SIGUSR2';
104-
process.report.reportOnSignal = false;
105-
assert.strictEqual(process.listenerCount('SIGUSR2'), 0);
106-
process.report.reportOnSignal = true;
107-
assert.strictEqual(process.listenerCount('SIGUSR2'), 1);
108-
process.report.signal = 'SIGUSR1';
109-
assert.strictEqual(process.listenerCount('SIGUSR2'), 0);
110-
assert.strictEqual(process.listenerCount('SIGUSR1'), 1);
111-
process.report.reportOnSignal = false;
112-
assert.strictEqual(process.listenerCount('SIGUSR1'), 0);
91+
for (const throwingSetter of throwingSetters) {
92+
assert.throws(() => process.report[key] = throwingSetter[0], throwingSetter[1]);
93+
}
94+
95+
process.report[key] = newValue;
96+
t.assert.strictEqual(process.report[key], newValue);
97+
});
11398
}

0 commit comments

Comments
 (0)