1'use strict';
2// Test producing a report on uncaught exception.
3const common = require('../common');
4const assert = require('assert');
5const childProcess = require('child_process');
6const helper = require('../common/report');
7const tmpdir = require('../common/tmpdir');
8
9if (process.argv[2] === 'child') {
10  throw new Error('test error');
11}
12
13tmpdir.refresh();
14const child = childProcess.spawn(process.execPath, [
15  '--report-uncaught-exception',
16  __filename,
17  'child',
18], {
19  cwd: tmpdir.path,
20});
21child.on('exit', common.mustCall((code) => {
22  assert.strictEqual(code, 1);
23  const reports = helper.findReports(child.pid, tmpdir.path);
24  assert.strictEqual(reports.length, 1);
25
26  helper.validate(reports[0], [
27    ['header.event', 'Exception'],
28    ['header.trigger', 'Exception'],
29    ['javascriptStack.message', 'Error: test error'],
30  ]);
31}));
32