Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use test runner in test-report-config #54571

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 83 additions & 98 deletions test/report/test-report-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,112 +2,97 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { test } = require('node:test');

// Verify that process.report.directory behaves properly.
assert.strictEqual(process.report.directory, '');
process.report.directory = __dirname;
assert.strictEqual(process.report.directory, __dirname);
assert.throws(() => {
process.report.directory = {};
}, { code: 'ERR_INVALID_ARG_TYPE' });
assert.strictEqual(process.report.directory, __dirname);
const invalidArgType = { code: 'ERR_INVALID_ARG_TYPE' };
const cases = [
{
key: 'directory',
value: '',
newValue: __dirname,
throwingSetters: [[{}, invalidArgType]],
},
{
key: 'filename',
value: '',
newValue: 'test-report.json',
throwingSetters: [[{}, invalidArgType]],
},
{
key: 'reportOnFatalError',
value: true,
newValue: false,
throwingSetters: [[{}, invalidArgType]],
},
{
key: 'reportOnUncaughtException',
value: true,
newValue: false,
throwingSetters: [[{}, invalidArgType]],
},
{
key: 'reportOnSignal',
value: false,
newValue: true,
throwingSetters: [[{}, invalidArgType]],
},
{
key: 'compact',
value: true,
newValue: false,
throwingSetters: [[{}, invalidArgType]],
},
{
key: 'excludeNetwork',
value: false,
newValue: true,
throwingSetters: [[{}, invalidArgType]],
},
];

// Verify that process.report.filename behaves properly.
assert.strictEqual(process.report.filename, '');
process.report.filename = 'test-report.json';
assert.strictEqual(process.report.filename, 'test-report.json');
assert.throws(() => {
process.report.filename = {};
}, { code: 'ERR_INVALID_ARG_TYPE' });
assert.strictEqual(process.report.filename, 'test-report.json');
if (!common.isWindows) {
cases.push({
key: 'signal',
value: 'SIGUSR1',
newValue: 'SIGUSR2',
throwingSetters: [
[{}, invalidArgType],
['foo', { code: 'ERR_UNKNOWN_SIGNAL', message: 'Unknown signal: foo' }],
['sigusr1', { code: 'ERR_UNKNOWN_SIGNAL',
message: 'Unknown signal: sigusr1 (signals must use all capital letters)' }],
],
});

// Verify that process.report.reportOnFatalError behaves properly.
assert.strictEqual(process.report.reportOnFatalError, true);
process.report.reportOnFatalError = false;
assert.strictEqual(process.report.reportOnFatalError, false);
process.report.reportOnFatalError = true;
assert.strictEqual(process.report.reportOnFatalError, true);
assert.throws(() => {
process.report.reportOnFatalError = {};
}, { code: 'ERR_INVALID_ARG_TYPE' });
assert.strictEqual(process.report.reportOnFatalError, true);
test('Verify that the interaction between reportOnSignal and signal is correct.', (t) => {
process.report.reportOnSignal = false;
t.assert.strictEqual(process.listenerCount('SIGUSR2'), 0);

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

// Verify that process.report.reportOnUncaughtException behaves properly.
assert.strictEqual(process.report.reportOnUncaughtException, true);
process.report.reportOnUncaughtException = false;
assert.strictEqual(process.report.reportOnUncaughtException, false);
process.report.reportOnUncaughtException = true;
assert.strictEqual(process.report.reportOnUncaughtException, true);
assert.throws(() => {
process.report.reportOnUncaughtException = {};
}, { code: 'ERR_INVALID_ARG_TYPE' });
assert.strictEqual(process.report.reportOnUncaughtException, true);
process.report.signal = 'SIGUSR1';
t.assert.strictEqual(process.listenerCount('SIGUSR2'), 0);
t.assert.strictEqual(process.listenerCount('SIGUSR1'), 1);

// Verify that process.report.reportOnSignal behaves properly.
assert.strictEqual(process.report.reportOnSignal, true);
process.report.reportOnSignal = false;
assert.strictEqual(process.report.reportOnSignal, false);
process.report.reportOnSignal = true;
assert.strictEqual(process.report.reportOnSignal, true);
assert.throws(() => {
process.report.reportOnSignal = {};
}, { code: 'ERR_INVALID_ARG_TYPE' });
assert.strictEqual(process.report.reportOnSignal, true);
process.report.reportOnSignal = false;
t.assert.strictEqual(process.listenerCount('SIGUSR1'), 0);
});
}

// Verify that process.report.reportCompact behaves properly.
assert.strictEqual(process.report.compact, true);
process.report.compact = false;
assert.strictEqual(process.report.compact, false);
process.report.compact = true;
assert.strictEqual(process.report.compact, true);
assert.throws(() => {
process.report.compact = {};
}, { code: 'ERR_INVALID_ARG_TYPE' });
assert.strictEqual(process.report.compact, true);
for (const testCase of cases) {
const { key, value, newValue, throwingSetters } = testCase;

// Verify that process.report.excludeNetwork behaves properly.
assert.strictEqual(process.report.excludeNetwork, false);
process.report.excludeNetwork = true;
assert.strictEqual(process.report.excludeNetwork, true);
process.report.excludeNetwork = false;
assert.strictEqual(process.report.excludeNetwork, false);
assert.throws(() => {
process.report.excludeNetwork = {};
}, { code: 'ERR_INVALID_ARG_TYPE' });
assert.strictEqual(process.report.excludeNetwork, false);
test(`Verify that process.report.${key} behaves properly`, (t) => {
t.assert.strictEqual(process.report[key], value);

if (!common.isWindows) {
// Verify that process.report.signal behaves properly.
assert.strictEqual(process.report.signal, 'SIGUSR2');
assert.throws(() => {
process.report.signal = {};
}, { code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => {
process.report.signal = 'foo';
}, {
code: 'ERR_UNKNOWN_SIGNAL',
message: 'Unknown signal: foo',
});
assert.throws(() => {
process.report.signal = 'sigusr1';
}, {
code: 'ERR_UNKNOWN_SIGNAL',
message: 'Unknown signal: sigusr1 (signals must use all capital letters)',
});
assert.strictEqual(process.report.signal, 'SIGUSR2');
process.report.signal = 'SIGUSR1';
assert.strictEqual(process.report.signal, 'SIGUSR1');
process.report[key] = newValue;
t.assert.strictEqual(process.report[key], newValue);

// Verify that the interaction between reportOnSignal and signal is correct.
process.report.signal = 'SIGUSR2';
process.report.reportOnSignal = false;
assert.strictEqual(process.listenerCount('SIGUSR2'), 0);
process.report.reportOnSignal = true;
assert.strictEqual(process.listenerCount('SIGUSR2'), 1);
process.report.signal = 'SIGUSR1';
assert.strictEqual(process.listenerCount('SIGUSR2'), 0);
assert.strictEqual(process.listenerCount('SIGUSR1'), 1);
process.report.reportOnSignal = false;
assert.strictEqual(process.listenerCount('SIGUSR1'), 0);
for (const throwingSetter of throwingSetters) {
assert.throws(() => process.report[key] = throwingSetter[0], throwingSetter[1]);
}

process.report[key] = newValue;
t.assert.strictEqual(process.report[key], newValue);
});
}
Loading