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(gatsby): update cache.set to resolve with set value #11327

Merged
merged 4 commits into from
Feb 15, 2019

Conversation

mgmolisani
Copy link
Contributor

Description

Cache set method will now resolve to the stored value. Both cache set and get now also reject on cache errors.

Also, I have never written Jest tests so this was a pretty exciting learning experience. Mocking was not very intuitive, especially due to the resolve function being in the callback of the get and set cache manager package. We also don't actually talk to the cache so the get tests feel a little wonky. Also, I do not know the shape of the error object sent from the cache manager or what actually can cause it so I mocked its existence with !undefined which is obviously just true but I wanted it to read as something that was defined and not just true. Is there a better/conventional way to say err is defined? Would {} be a better solution? Interested if anyone has a better testing strategy than just forcing the error argument to exist or not.

Related Issues

Addresses #11275

@mgmolisani mgmolisani requested a review from a team as a code owner January 27, 2019 01:25
@mgmolisani
Copy link
Contributor Author

mgmolisani commented Jan 27, 2019

General Jest question after continuing to think of Jest best practices. For the code where I need the err and res variables set dynamically per test, would it be better to declare regular variables and clean them up with an afterEach? Or if calling them as mocked functions like they are now, is it better practice to use jest.fn().mockReturnValue() when we are using them like variables and not functions since the body of the function is always just the returned value? Really deep diving into Jest but it doesn't seem like mocking variables is explained in the docs (likely because you can literally just use variables or callback mocked functions to return a value as stated above). What do other people think?

@DSchau
Copy link
Contributor

DSchau commented Jan 28, 2019

@mgmolisani yep! Just update with a new commit (as many as you want actually!). Come merge time, we'll just squash all those commits down into one nice, clean commit message :)

@mgmolisani
Copy link
Contributor Author

@DSchau Updated with suggestions (sorry if this is basically just a duplicate notification).

@pieh pieh changed the title Updated cache.set to resolve with set value feat: update cache.set to resolve with set value Jan 29, 2019
@DSchau DSchau changed the title feat: update cache.set to resolve with set value feat(gatsby): update cache.set to resolve with set value Jan 29, 2019
Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

There are few things that should be changed

packages/gatsby/src/utils/__tests__/cache.js Outdated Show resolved Hide resolved
packages/gatsby/src/utils/__tests__/cache.js Outdated Show resolved Hide resolved
packages/gatsby/src/utils/cache.js Outdated Show resolved Hide resolved
@mgmolisani
Copy link
Contributor Author

Updated. Now resolves to undefined on errors. Is this the behavior that is desired?

(Also, as a git contributing noob, I didn't know that I should pull the official master branch into my topic branch to sync with the prod build. Caused a bunch of test failures. Is this something that is worth a pull request to the docs for?)

@wardpeet wardpeet merged commit 930164a into gatsbyjs:master Feb 15, 2019
@gatsbot
Copy link

gatsbot bot commented Feb 15, 2019

Holy buckets, @mgmolisani — we just merged your PR to Gatsby! 💪💜

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (Currently we’ve got a couple t-shirts available, plus some socks that are really razzing our berries right now.)
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. Accept the invite by visiting https://github.com/orgs/gatsbyjs/invitation. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again!

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

4 participants