Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Bug 1052633 - Add infrastructure to throw on uncaught promise rejecti…
Browse files Browse the repository at this point in the history
…ons during tests
  • Loading branch information
jsantell committed Aug 12, 2014
1 parent ecd589a commit 2762109
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/sdk/core/promise.js
Expand Up @@ -17,7 +17,8 @@ const PROMISE_URI = 'resource://gre/modules/Promise.jsm';

getEnvironment.call(this, function ({ require, exports, module, Cu }) {

const { defer, resolve, all, reject, race } = Cu.import(PROMISE_URI, {}).Promise;
const Promise = Cu.import(PROMISE_URI, {}).Promise;
const { Debugging, defer, resolve, all, reject, race } = Promise;

module.metadata = {
'stability': 'unstable'
Expand Down Expand Up @@ -75,7 +76,7 @@ exports.resolve = resolve;
exports.reject = reject;
exports.race = race;
exports.Promise = Promise;

exports.Debugging = Debugging;
});

function getEnvironment (callback) {
Expand Down
14 changes: 13 additions & 1 deletion lib/sdk/deprecated/unit-test.js
Expand Up @@ -12,7 +12,7 @@ const timer = require("../timers");
const cfxArgs = require("../test/options");
const { getTabs, closeTab, getURI } = require("../tabs/utils");
const { windows, isBrowser } = require("../window/utils");
const { defer, all } = require("../core/promise");
const { defer, all, Debugging: PromiseDebugging } = require("../core/promise");

const findAndRunTests = function findAndRunTests(options) {
var TestFinder = require("./unit-test-finder").TestFinder;
Expand Down Expand Up @@ -57,6 +57,14 @@ TestRunner.prototype = {
this.test.errors[why]++;
},

_uncaughtErrorObserver: function({message, date, fileName, stack, lineNumber}) {
// Bug 998277, uncaught SDK promise errors should throw during tests.
// Uncomment when all failing tests have been fixed so this throws
// in future tests.
//
// this.fail("There was an uncaught Promise rejection: " + stack);
},

pass: function pass(message) {
if(!this.expectFailure) {
if ("testMessage" in this.console)
Expand Down Expand Up @@ -299,6 +307,8 @@ TestRunner.prototype = {
return promise;
});

PromiseDebugging.flushUncaughtErrors();

all(winPromises).then(_ => {
let tabs = [];
for (let win of wins.filter(isBrowser)) {
Expand Down Expand Up @@ -495,6 +505,8 @@ TestRunner.prototype = {
this.test.passed = 0;
this.test.failed = 0;
this.test.errors = {};
PromiseDebugging.clearUncaughtErrorObservers();
PromiseDebugging.addUncaughtErrorObserver(this._uncaughtErrorObserver.bind(this));

this.isDone = false;
this.onDone = function(self) {
Expand Down

0 comments on commit 2762109

Please sign in to comment.