Skip to content

Commit 1d5ab86

Browse files
authored
Be more general in stripping off stack frames to fix Firefox tests (#2425)
* Revert breaking change to stack-stripping regex This regex was made more specific in an attempt to avoid incorrectly stripping off parts of messages - we strip off anything after " at", which means "to have been called at least once" becomes "to have been called". However, the new regex was too specific and made faulty assumptions about stack traces - namely, that they'll always have parentheses after the at. Firefox's stack traces, however, look like so: func() at callFn@about:blank line 2 > injectedScript:47353:21 So, we could try to come up with a better regex that matches all browsers that we test with, or perhaps add some sort of indicator when we're appending the stack traces, but since this change is breaking the tests for everyone right now, for expedience we'll just revert to how we were stripping things before. This means changing one of the asserts back to how it was before, where it was asserting against a partial message due to the over-eager stripping, so add a comment about that as well. * Update with a more general regex This should match any stack frame format that has at least one non-word, non-space character in it, which should be a pretty safe assumption, and holds for the three browsers we test in anyway. This gets us back to not trimming messages improperly, while also not breaking firefox, and I think is reasonable as far as regexes go. This seems like a reasonable enough regex - the original fixed one was overly complicated because it tried to remove an arbitrary number of stack frames, which was unnecessary because we only append one.
1 parent 56b0612 commit 1d5ab86

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

test/assert-test.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,9 +1438,15 @@ describe("assert", function () {
14381438
[].slice.call(arguments, 1)
14391439
);
14401440
} catch (e) {
1441-
// We sometimes append stack frames to the message and they
1442-
// make assertions messy, so strip those off here
1443-
return e.message.replace(/( at.*\(.*\)$)+/gm, "");
1441+
/* We sometimes append stack frames to the message and they
1442+
* make assertions messy, so strip those off here
1443+
*
1444+
* In the regex we assume that a stack frame will have at
1445+
* least one "special character" (not a word or space) and
1446+
* use that to make sure we don't strip off the end of
1447+
* legitimate messages that end with "at least once..."
1448+
*/
1449+
return e.message.replace(/ at.*?[^\w\s].*/g, "");
14441450
}
14451451
};
14461452
});

0 commit comments

Comments
 (0)