Skip to content

Commit

Permalink
test: Fail CDP commands on unhandled exceptions
Browse files Browse the repository at this point in the history
Install a Chrome Devtools Protocol handler for unhandled exceptions, and
fail the next CDP command with it.

This got lost with the move from PhantomJS to Chrome.
  • Loading branch information
martinpitt authored and stefwalter committed Jul 12, 2018
1 parent 5c94255 commit 119f8ca
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion test/common/cdp-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ function success(result) {
var messages = [];
var logPromiseResolver;
var nReportedLogMessages = 0;
var unhandledExceptions = [];

function setupLogging(client) {
client.Runtime.enable();
Expand All @@ -72,6 +73,8 @@ function setupLogging(client) {
resolveLogPromise();
});

client.Runtime.exceptionThrown(info => unhandledExceptions.push(info.exceptionDetails));

client.Log.enable();
client.Log.entryAdded(entry => {
let msg = entry["entry"];
Expand Down Expand Up @@ -288,7 +291,14 @@ CDP.New(options)
pageLoadPromise = new Promise((resolve, reject) => { pageLoadResolve = resolve; pageLoadReject = reject; });

// run the command
eval(command).then(success, fail);
eval(command).then(reply => {
if (unhandledExceptions.length === 0) {
success(reply);
} else {
fail(unhandledExceptions[0].exception.description);
unhandledExceptions.length = 0;
}
}, fail);

input_buf = input_buf.slice(i+1);
}
Expand Down

0 comments on commit 119f8ca

Please sign in to comment.