Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be more general in stripping off stack frames to fix Firefox tests #2425

Merged
merged 2 commits into from Jan 25, 2022

Conversation

cincodenada
Copy link
Contributor

@cincodenada cincodenada commented Jan 23, 2022

Purpose (TL;DR)

This fixes a breaking change to tests in Firefox introduced in #2410, by reverting a small subset of that PR.

Background (Problem in detail)

We're stripping off stack traces for comparison's sake in tests, and previously to #2410 we used a pretty non-specific regex to do so, which accidentally stripped off part of the assertion message "expected func() to have been called at least once", and thus were asserting that such an assertion results in the message "expected func() to have been called". This is technically incorrect, but also fairly harmless. Amusingly, the message itself is still semantically sound, just less specific than the original.

As part of a larger refactor in #2410, I attempted to make this regex more specific, and thus not incorrectly strip part of the assertion message along with the stack traces. This was successful in not stripping the message, but went too far in the other direction - the new regex is now too specific, and makes assumptions about stack traces that do not hold for Firefox's stack trace format.

Solution

It's likely possible to come up with a regex that will match both formats, while still not stripping off the ends of legitimate messages, but in the interest of expedience and simplicity, this PR simply reverts to the previous regex, and adjusts the one test affected to once again assert against the technically incorrect message.

How to verify - mandatory

  1. Run the tests in this branch under Firefox (with SauceLabs, or elsewise)

Checklist for author

  • npm run lint passes
  • References to standard library functions are cached.

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.
@cincodenada cincodenada mentioned this pull request Jan 23, 2022
2 tasks
@cincodenada
Copy link
Contributor Author

Okay, I was able to run the tests under Firefox now, verified that I got the failures in master, and that the tests are passing again in this branch.

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.
@cincodenada
Copy link
Contributor Author

cincodenada commented Jan 24, 2022

Okay, and now that I can test, and after thinking on it a bit, I just pushed a follow-up commit with a more general regex whose only assumption is that a stack frame has a non-word, non-space character somewhere - which seems a much safer assumption to me, and certainly holds for all the browsers we test in.

This gets us back to not chopping off the ends of legitimate messages, and seems like a reasonable regex to me as far as regexes go, but feel free to revert to the previous commit if we'd rather go with the simpler fix.

@cincodenada cincodenada changed the title Revert breaking change to stack-stripping regex Be more general in stripping off stack frames to fix Firefox tests Jan 24, 2022
@fatso83 fatso83 merged commit 1d5ab86 into sinonjs:master Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants