Bug 1377946 - Don't include promise rejection dates in the first line of failure messages. r=KWierso draft
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Wed, 05 Jul 2017 10:50:07 +0100
changeset 604120 e09c0e88a1f43ea6f837a83d3fe1240ab84ccfce
parent 603705 fef489e8c2a193dde885adc48deb74cc883a5881
child 636092 df7a4a67155f4c5c3876c26a07e0a044e5e47a7a
push id66962
push userpaolo.mozmail@amadzone.org
push dateWed, 05 Jul 2017 09:51:26 +0000
reviewersKWierso
bugs1377946
milestone56.0a1
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.