Bug 1377946 - Don't include promise rejection dates in the first line of failure messages. r=KWierso
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Wed, 05 Jul 2017 10:50:07 +0100
changeset 367660 01fdf4dd0a122c42315821b32eccdf3c306a89aa
parent 367659 530b9cd1f9635702612eb16db37b79338a826bdd
child 367661 4d6404af7e75e570825a90ebdea99d844f983dc7
push id32141
push userkwierso@gmail.com
push dateThu, 06 Jul 2017 23:10:59 +0000
treeherdermozilla-central@20f32734df75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersKWierso
bugs1377946
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1377946 - Don't include promise rejection dates in the first line of failure messages. r=KWierso MozReview-Commit-ID: IftDgyZNgIL
toolkit/modules/tests/modules/PromiseTestUtils.jsm
--- 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.