-
Notifications
You must be signed in to change notification settings - Fork 48
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
✅ Use jasmine for testing #230
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This promise is not awaited on because this handler happens within a callback event, however the close method may reject if it has already been called or if the browser has been killed.
Fix string matching windows path Ignore racey code coverage
For Windows
Robdel12
approved these changes
Mar 8, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏁 We've been sleepin on Jasmine
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is this?
In preparation to add browser support for
@percy/logger
and@percy/sdk-utils
, their test suites (along with@percy/dom
) were evaluated.While Mocha is supported in browsers, Jest's expect is not. This is handled in
@percy/dom
by not including Jest's expect and instead using a thin helper mimicking the expect API. This helper from@percy/dom
would need to be included in browser tests for@percy/logger
and@percy/sdk-utils
, however these two packages still need to be tested in Node since they will be polymorphic.We could have two test suites for these packages — one for Node and one for browsers; or we could perform browser-only test aliasing to ensure Node specific code is replaced with browser compatible code. Instead, this PR proposes migrating to Jasmine, which includes its own
expect
with a very similar API; as well as Jasmine is specifically built to be polymorphic. It also contains its own spy library which we can utilize rather than the current manual mocks and spies.Approach
Migrating the tests themselves was pretty straightforward since Mocha's and expect's APIs are very similar to, or in most instances exactly the same as, Jasmine's APIs. For the APIs that did not perfectly match, a codemod was used to transform all of the tests using the same set of rules (which also makes it super easy to list below).
One Jest expectation does not exist in Jasmine but is used everywhere,
toHaveProperty(key, value)
. The Jasmine equivalent is a bit more verbose,toEqual(jasmine.objectContaining({ key: value }))
, and doesn't work with nested key paths. Rather than make this into a transform, a global test-helper util is used to add a customtoHaveProperty
Jasmine matcher. This global test-helper also overrides another Jasmine matcher,toContain
, to add support for deeply checking Sets. The Jasmine variant wants to support IE, which cannot perform a deep check on Sets without the performance tradeoff of transforming the Set into an array.Finally, manually added mocks, stubs, and spies were replaced with Jasmine's
spyOn
, as well as associated expectations updated to use Jasmine's Spy expect matchers.Code Transforms
Test hooks:
Async expectations:
Expectations with different method names:
Static expect helpers:
Other Changes
A custom test script is used in order to add the
jasmine-spec-reporter
which can only be added programmatically (and not via the CLI). Some Jasmine options are also not available as CLI options, so the test script makes it easier for all monorepo packages to share the same test setup.The tests seem faster? Which revealed a
@percy/core
test failure in which a method called during a page crash did not handle asynchronous errors, causing an unhandle promise rejection warning. Coverage of the failure is flakey and ultimately only needs to be handled to prevent the promise warning so is ignored. Other@percy/core
tests needed to escape path separators for Windows since Jasmine'sstringMatching
helper handles substrings differently than Jest's.