1'use strict'; 2 3const common = require('../../common'); 4const assert = require('assert'); 5const path = require('path'); 6const spawnSync = require('child_process').spawnSync; 7const helper = require('../../common/report.js'); 8const tmpdir = require('../../common/tmpdir'); 9 10const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`); 11 12if (process.argv[2] === 'child') { 13 (function childMain() { 14 const addon = require(binding); 15 addon.triggerFatalError(); 16 })(); 17 return; 18} 19 20const ARGS = [ 21 __filename, 22 'child', 23]; 24 25{ 26 // Verify that --report-on-fatalerror is respected when set. 27 tmpdir.refresh(); 28 const args = ['--report-on-fatalerror', ...ARGS]; 29 const child = spawnSync(process.execPath, args, { cwd: tmpdir.path }); 30 assert.notStrictEqual(child.status, 0, 'Process exited unexpectedly'); 31 32 const reports = helper.findReports(child.pid, tmpdir.path); 33 assert.strictEqual(reports.length, 1); 34 35 const report = reports[0]; 36 helper.validate(report); 37 38 const content = require(report); 39 assert.strictEqual(content.header.trigger, 'FatalError'); 40 41 // Check that the javascript stack is present. 42 assert.strictEqual(content.javascriptStack.stack.findIndex((frame) => frame.match('childMain')), 0); 43} 44 45{ 46 // Verify that --report-on-fatalerror is respected when not set. 47 const args = ARGS; 48 const child = spawnSync(process.execPath, args, { cwd: tmpdir.path }); 49 assert.notStrictEqual(child.status, 0, 'Process exited unexpectedly'); 50 const reports = helper.findReports(child.pid, tmpdir.path); 51 assert.strictEqual(reports.length, 0); 52} 53