Bug 1377946 - Don't include promise rejection dates in the first line of failure messages. r=KWierso
MozReview-Commit-ID: IftDgyZNgIL
--- a/toolkit/modules/tests/modules/PromiseTestUtils.jsm
+++ b/toolkit/modules/tests/modules/PromiseTestUtils.jsm
@@ -158,16 +158,22 @@ this.PromiseTestUtils = {
// We should convert the rejection stack to a string immediately. This is
// because the object might not be available when we report the rejection
// later, if the error occurred in a context that has been unloaded.
let stack = "(Unable to convert rejection stack to string.)";
try {
stack = "" + PromiseDebugging.getRejectionStack(promise);
} catch (ex) {}
+ // Always add a newline at the end of the stack for consistent reporting.
+ // This is already present when the stack is provided by PromiseDebugging.
+ if (!stack.endsWith("\n")) {
+ stack += "\n";
+ }
+
// It's important that we don't store any reference to the provided Promise
// object or its value after this function returns in order to avoid leaks.
this._rejections.push({
id: PromiseDebugging.getPromiseID(promise),
message,
date: new Date(),
stack,
});
@@ -246,21 +252,25 @@ this.PromiseTestUtils = {
}
// Check the global whitelisting functions.
if (this._globalRejectionIgnoreFns.some(fn => fn(rejection))) {
continue;
}
// Report the error. This operation can throw an exception, depending on
- // the configuration of the test suite that handles the assertion.
+ // the configuration of the test suite that handles the assertion. The
+ // first line of the message, including the latest call on the stack, is
+ // used to identify related test failures. To keep the first line similar
+ // between executions, we place the time-dependent rejection date on its
+ // own line, after all the other stack lines.
Assert.ok(false,
`A promise chain failed to handle a rejection:` +
- ` ${rejection.message} - rejection date: ${rejection.date}` +
- ` - stack: ${rejection.stack}`);
+ ` ${rejection.message} - stack: ${rejection.stack}` +
+ `Rejection date: ${rejection.date}`);
}
},
/**
* Fails the test if any rejection indicated by expectUncaughtRejection has
* not yet been reported at this time.
*
* This is called by the test suite at the end of each test file.