-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
feat(testing): add tests for registerServiceWorker #3200
Conversation
const options = getOptions() | ||
const path = normalize(`${options.csStaticBase}/dist/serviceWorker.js`) | ||
try { | ||
await navigator.serviceWorker.register(path, { | ||
scope: (options.base ?? "") + "/", | ||
scope: options.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.
TLDR: options.base
will always return a string
. No need to use nullish coalescing operator
See commit message for explanation: 67dbb36
Codecov Report
@@ Coverage Diff @@
## main #3200 +/- ##
==========================================
+ Coverage 46.77% 46.81% +0.04%
==========================================
Files 23 23
Lines 1193 1194 +1
Branches 237 237
==========================================
+ Hits 558 559 +1
Misses 451 451
Partials 184 184
Continue to review full report at Codecov.
|
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.
LGTM!
Inside registerServiceWorker, we were originally using the nullash coalescing operator to check if options.base was null or undefined. However, I realized this check is not necessary. If you look at getOptions' return value, we return an object with a key "base" which is of type "string". We get that value by calling resolveBase which always returns a string. As a result, we didn't need to check if options.base was null or undefined because it never can be.
67dbb36
to
83746c8
Compare
This PR adds two more tests to cover the last line for
src/browser/register.ts
which should be at 100% now.Interestingly - the output from Jest and what Codecov picks up are a little different 🤷♂️