-
Notifications
You must be signed in to change notification settings - Fork 687
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Improve Jest error detection and reporter output (#1615) #1948
Conversation
|
packages/venia-concept/src/index.js
Outdated
); | ||
} | ||
// This is stored as a global for testing purposes. | ||
window.__registerServiceWorker = () => { |
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.
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.
Looks like this PR changes things, that have been moved to different files as part of #1905
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.
Not a fan of custom globals though __
prefix is OK I guess.
Is there not another way around this?
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.
It's ugly, but it's incredibly common to have a custom global in an app like this one that takes over the whole document. And it does have the advantage that something else can remotely unsubscribe the handler, because there's a real reference to the handler: window.removeEventListener('load', window.__registerServiceWorker)
is something that a future Webpack hot module reloading strategy could use.
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.
@revanth0212 Once one of these is merged, we'll rebase the other one!
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.
I have issue with registering a global, especially for tests.
I also want to see some docs around the (necessary?) unhandled rejection handler.
Anyways, verification steps work. I think this is definitely better and cleaner. Woo!
@@ -0,0 +1,58 @@ | |||
/** | |||
* Spanish console magic. Quiets the console during test reporting, except | |||
* for console methods called _within tests themselves._ |
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.
I'm ugly crying. This is great!
Great documentation :)
const tick = () => new Promise(setImmediate); | ||
|
||
module.exports = Base => | ||
class RejectionHandlingEnv extends Base { |
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.
This class feels unnecessary -- why not just fix the tests in the first place?
And if we want to keep this I think we should add some docs around this explaining its purpose.
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.
I can add comments, but I do want to keep it.
The reason I added this is that the tests weren't failing, so they just flew past in the console logging and the test command exited clean. If you're in a hurry or you're unfamiliar with our test command output, you won't know there are tests to fix!
This doesn't allow tests to have unhandled promise rejections in them; instead, it actually forbids them by forcing a test containing them to fail.
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.
Thank you so much for the explanation and docs!
4ebf20d
to
61710f0
Compare
test: cleanup and improve jest output
61710f0
to
d5d6560
Compare
Description
Improve Jest exception handling and clean up Jest reporter output.
fileMock
from venia-concept, since it's used invenia-ui
now.packages/pwa-buildpack/lib/Utilities/__tests__/graphQL.spec.js
was testing promise rejections with statements likeexpect(promise).rejects
. In Jest you need to add another assertion after.rejects
.packages/venia-concept/src/__tests__/index.spec.js
was trying to re-require the module in a way that caused unhandled rejections. Refactored the implementation for testability and simplified the test.packages/venia-ui/lib/components/ProductFullDetail/__tests__/productFullDetail.spec.js
was mocking a React component in a way that made it renderundefined
, which was causing a problem inreact-test-renderer
.Notes:
NODE_DEBUG
toDEBUG
to a non-empty value.Related Issue
Closes #1615.
Acceptance
Verification Stakeholders
All core devs and QA:
Verification Steps
yarn test
.NODE_DEBUG=1 yarn test
.await
from an asynchronous test to cause an unhandled rejection.yarn run test:dev
.Optional:
console.log
statement to a test file, helper file, or mock file.yarn test
.Checklist