-
-
Notifications
You must be signed in to change notification settings - Fork 45
Allow Error object to be passed to node-report #82
Changes from all commits
15fd45a
c73968a
5b75c5e
e5edd5f
cee0a31
7130888
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
// Testcase for passing an error object to the API call. | ||
|
||
if (process.argv[2] === 'child') { | ||
const nodereport = require('../'); | ||
try { | ||
throw new Error("Testing error handling"); | ||
} catch (err) { | ||
nodereport.triggerReport(err); | ||
} | ||
} else { | ||
const common = require('./common.js'); | ||
const spawn = require('child_process').spawn; | ||
const tap = require('tap'); | ||
|
||
const child = spawn(process.execPath, [__filename, 'child']); | ||
child.on('exit', (code) => { | ||
tap.plan(3); | ||
tap.equal(code, 0, 'Process exited cleanly'); | ||
const reports = common.findReports(child.pid); | ||
tap.equal(reports.length, 1, 'Found reports ' + reports); | ||
const report = reports[0]; | ||
common.validate(tap, report, {pid: child.pid, | ||
commandline: child.spawnargs.join(' '), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was half convinced by the argument for spawning above, then I read test/common.js, and now I'm not. The command line is just checked against what is passed in here, which could just as easily be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of the problems we had with But as I pointed out elsewhere the command line check is optional -- We can leave out |
||
expectedException: "Testing error handling", | ||
}); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why the test is spawning a child to call triggerReport(), why not just call it directly in the test? It looks like boilerplate copied from a test that must exist in order to get the report that doesn't apply here. If it is needed, probably needs a comment explaining why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe most of the tests use spawn so the standard validation checks in common.js can check a known set of process arguments. I think @richardlau would be the person to ask if you want the history.
The test is a direct copy of test-api.js with a small change to how the
triggerReport()
call is made and an extra parameter to thecommon.validate()
function. All the tests work along similar lines so I'll leave it how it is to make sure it fits the current model. If we want to change that we should do it under a separate PR so all the tests are consistent.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, part of the standard validation checks in
common.js
is to check the command line, so our tests spawn as it's the only way to be certain what to expect.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although the command line check can be skipped by not setting
commandline
on the options object passed to validate.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sam-github Do you want this changed before you approve? I'm happy to raise a separate PR about changing the tests.