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

Cache browsers locally instead of globally #106

Merged
merged 3 commits into from
Jun 16, 2021
Merged

Conversation

calebeby
Copy link
Member

Closes #77

Now the browser instance cache file is stored in the pleasantest folder rather than globally (previously it was /Users/<user>/Library/Application\ Support/pleasantest-nodejs/config.json. Now it is stored as a sibling to the dist folder.

This solves several problems:

  • If someone is having issues with cached browsers and wants to start fresh browsers instead of continuing to use whatever was wrong, now if they run npm ci, they will get fresh browsers
  • If someone has multiple versions of puppeteer (/ multiple versions of pleasantest) installed, there are no longer issues with the cache returning a browser whose version is mismatched with puppeteer's version.

Comment on lines 88 to 93
// I acknowledge that this code is gross and should be refactored
// Constraints:
// - If there is no browser in the config, multiple concurrent processes should only start 1 new browser
// - If there is a killed browser in the config, multiple concurrent processes should only start 1 new browser
// - If there "starting" in the config but nothing is really starting, multiple concurrent processes should only start 1 new browser
// - If there is no browser in the cache, multiple concurrent processes should only start 1 new browser
// - If there is a killed browser in the cache, multiple concurrent processes should only start 1 new browser
// - If there "starting" in the cache but nothing is really starting, multiple concurrent processes should only start 1 new browser
// TODO: Idea: use a state machine!!!
Copy link
Member Author

Choose a reason for hiding this comment

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

This code is still pretty gross, but it has held together way better than I expected. I'm leaving this comment here because I would still like to come back and rewrite it, but for the time being it works and is pretty resilient and "robust enough".


const readConfig = async (configPath: string) => {
const readCache = async (cachePath: string) => {
Copy link
Member Author

@calebeby calebeby Jun 14, 2021

Choose a reason for hiding this comment

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

Renamed all the things config -> cache because cache is more descriptive of what it actually is. I think at one point I had planned to put other stuff than browser cache URL's in that file, but not anymore.

Copy link
Member

@gerardo-rodriguez gerardo-rodriguez left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@calebeby calebeby merged commit 994b810 into main Jun 16, 2021
@calebeby calebeby deleted the local-browser-cache branch June 16, 2021 19:44
@github-actions github-actions bot mentioned this pull request Jun 16, 2021
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.

Cached browser config should be stored in node_modules
2 participants