node/test/addons/report-fatalerror/test.js
Anna Henningsen 4b289d047d
test: expand linting rules around assert w literal messages
Expands the existing restrictions around not using literal messages
to the `not` variants of `strictEqual` and `deepStrictEqual`, and
forbids `assert()` where the second argument is a non-string literal,
which almost always is a mis-typed `assert.strictEquals()`.

PR-URL: https://github.com/nodejs/node/pull/59147
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2025-07-23 16:28:06 +00:00

52 lines
1.5 KiB
JavaScript

'use strict';
const common = require('../../common');
const assert = require('assert');
const path = require('path');
const spawnSync = require('child_process').spawnSync;
const helper = require('../../common/report.js');
const tmpdir = require('../../common/tmpdir');
const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`);
if (process.argv[2] === 'child') {
(function childMain() {
const addon = require(binding);
addon.triggerFatalError();
})();
return;
}
const ARGS = [
__filename,
'child',
];
{
// Verify that --report-on-fatalerror is respected when set.
tmpdir.refresh();
const args = ['--report-on-fatalerror', ...ARGS];
const child = spawnSync(process.execPath, args, { cwd: tmpdir.path });
assert.notStrictEqual(child.status, 0);
const reports = helper.findReports(child.pid, tmpdir.path);
assert.strictEqual(reports.length, 1);
const report = reports[0];
helper.validate(report);
const content = require(report);
assert.strictEqual(content.header.trigger, 'FatalError');
// Check that the javascript stack is present.
assert.strictEqual(content.javascriptStack.stack.findIndex((frame) => frame.match('childMain')), 0);
}
{
// Verify that --report-on-fatalerror is respected when not set.
const args = ARGS;
const child = spawnSync(process.execPath, args, { cwd: tmpdir.path });
assert.notStrictEqual(child.status, 0);
const reports = helper.findReports(child.pid, tmpdir.path);
assert.strictEqual(reports.length, 0);
}