1'use strict'; 2 3const common = require('../../common'); 4const assert = require('assert'); 5const path = require('path'); 6const helper = require('../../common/report.js'); 7const tmpdir = require('../../common/tmpdir'); 8 9const binding = path.resolve(__dirname, `./build/${common.buildType}/binding`); 10const addon = require(binding); 11 12function myAddonMain(method, { hasContext, hasEnv }) { 13 tmpdir.refresh(); 14 process.report.directory = tmpdir.path; 15 16 addon[method](); 17 18 const reports = helper.findReports(process.pid, tmpdir.path); 19 assert.strictEqual(reports.length, 1); 20 21 const report = reports[0]; 22 helper.validate(report, [ 23 ['header.event', 'FooMessage'], 24 ['header.trigger', 'BarTrigger'], 25 ]); 26 27 const content = require(report); 28 29 // Check that the javascript stack is present. 30 if (hasContext) { 31 assert.strictEqual(content.javascriptStack.stack.findIndex((frame) => frame.match('myAddonMain')), 0); 32 } else { 33 assert.strictEqual(content.javascriptStack.message, 'No stack.'); 34 } 35 36 if (hasEnv) { 37 assert.strictEqual(content.header.threadId, 0); 38 } else { 39 assert.strictEqual(content.header.threadId, null); 40 } 41} 42 43const methods = [ 44 ['triggerReport', true, true], 45 ['triggerReportNoIsolate', false, false], 46 ['triggerReportEnv', true, true], 47 ['triggerReportNoEnv', false, false], 48 ['triggerReportNoContext', false, false], 49 ['triggerReportNewContext', true, false], 50]; 51for (const [method, hasContext, hasEnv] of methods) { 52 myAddonMain(method, { hasContext, hasEnv }); 53} 54