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

feat(testing): add tests for registerServiceWorker #3200

Merged
merged 2 commits into from
Apr 24, 2021

Conversation

jsjoeio
Copy link
Contributor

@jsjoeio jsjoeio commented Apr 23, 2021

This PR adds two more tests to cover the last line for src/browser/register.ts which should be at 100% now.

image

Interestingly - the output from Jest and what Codecov picks up are a little different 🤷‍♂️

@jsjoeio jsjoeio requested a review from a team as a code owner April 23, 2021 23:36
@jsjoeio jsjoeio changed the title jsjoeio/add-test-browser-register feat(testing): add tests for registerServiceWorker Apr 23, 2021
@jsjoeio jsjoeio self-assigned this Apr 23, 2021
@jsjoeio jsjoeio added the testing Anything related to testing label Apr 23, 2021
@jsjoeio jsjoeio added this to the v3.9.4 milestone Apr 23, 2021
const options = getOptions()
const path = normalize(`${options.csStaticBase}/dist/serviceWorker.js`)
try {
await navigator.serviceWorker.register(path, {
scope: (options.base ?? "") + "/",
scope: options.base + "/",
Copy link
Contributor Author

@jsjoeio jsjoeio Apr 23, 2021

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
Copy link

codecov bot commented Apr 23, 2021

Codecov Report

Merging #3200 (f8d386d) into main (5ad8e68) will increase coverage by 0.04%.
The diff coverage is 100.00%.

❗ Current head f8d386d differs from pull request most recent head 83746c8. Consider uploading reports for the commit 83746c8 to get more accurate results
Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
src/browser/register.ts 92.30% <100.00%> (+0.64%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5ad8e68...83746c8. Read the comment docs.

Copy link
Contributor

@jawnsy jawnsy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

test/unit/register.test.ts Outdated Show resolved Hide resolved
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.
@jsjoeio jsjoeio force-pushed the jsjoeio/add-test-browser-register branch from 67dbb36 to 83746c8 Compare April 24, 2021 00:09
@repo-ranger repo-ranger bot merged commit d31439e into main Apr 24, 2021
@repo-ranger repo-ranger bot deleted the jsjoeio/add-test-browser-register branch April 24, 2021 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Anything related to testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants