1'use strict'; 2 3// Testcases for situations involving fatal errors, like Javascript heap OOM 4 5require('../common'); 6const assert = require('assert'); 7const fs = require('fs'); 8const helper = require('../common/report.js'); 9const spawnSync = require('child_process').spawnSync; 10const tmpdir = require('../common/tmpdir'); 11const fixtures = require('../common/fixtures'); 12 13// Common args that will cause an out-of-memory error for child process. 14const ARGS = [ 15 '--max-heap-size=20', 16 fixtures.path('report-oom'), 17]; 18const REPORT_FIELDS = [ 19 ['header.trigger', 'OOMError'], 20 ['javascriptHeap.memoryLimit', 20 * 1024 * 1024 /* 20MB */], 21]; 22 23{ 24 // Verify that --report-compact is respected when set. 25 tmpdir.refresh(); 26 const args = ['--report-on-fatalerror', '--report-compact', ...ARGS]; 27 const child = spawnSync(process.execPath, args, { cwd: tmpdir.path }); 28 assert.notStrictEqual(child.status, 0, 'Process exited unexpectedly'); 29 30 const reports = helper.findReports(child.pid, tmpdir.path); 31 assert.strictEqual(reports.length, 1); 32 33 const report = reports[0]; 34 helper.validate(report, REPORT_FIELDS); 35 36 // Subtract 1 because "xx\n".split("\n") => [ 'xx', '' ]. 37 const lines = fs.readFileSync(report, 'utf8').split('\n').length - 1; 38 assert.strictEqual(lines, 1); 39} 40