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

Implement getCacheKey #51

Open
nvh95 opened this issue Apr 16, 2022 · 3 comments · May be fixed by #54
Open

Implement getCacheKey #51

nvh95 opened this issue Apr 16, 2022 · 3 comments · May be fixed by #54
Assignees
Labels
enhancement Enhancement to current features/ behaviors feature request Request a new feature

Comments

@nvh95
Copy link
Owner

nvh95 commented Apr 16, 2022

What & Why

  • Now, jest-preview hasn't implemented getCacheKey for css, file and fileCRA transformer.
    'use strict';
    import { processCss } from '../transform';
    function process(src: string, filename: string) {
    return processCss(src, filename);
    }
    export default { process };
  • The reason is that we are not very deeply understand the benefit of getCacheKey. The [docs]((https://jestjs.io/docs/code-transformation) itself is not very detail. But we know it boosts the performance when running Jest since we're caching the transformed files.

How

@nvh95 nvh95 added the feature request Request a new feature label Apr 16, 2022
@nvh95 nvh95 self-assigned this Apr 16, 2022
@nvh95 nvh95 added the enhancement Enhancement to current features/ behaviors label Apr 16, 2022
@nvh95 nvh95 mentioned this issue Apr 16, 2022
3 tasks
@nvh95
Copy link
Owner Author

nvh95 commented Apr 16, 2022

As I observe and guess, if we do not implement getCacheKey, Jest automatically cache using return value in the transformation.
For e.g: If our css transform a css file to

const relativeCssPath = "/demo/App.css";
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href = relativeCssPath;
document.body.appendChild(link);

module.exports = JSON.stringify(relativeCssPath);

This whole file content will be used as the key for caching.
So what is the point of implementing getCacheKey? To get a shorter key? Do we need to do that?

@nvh95
Copy link
Owner Author

nvh95 commented Apr 16, 2022

How to see the cache key by yourself

  1. Run jest --clearCache to see where the cache located. For e.g, on mac: /private/var/folders/hg/cg39z3hd4gv3grbrd08524gh0000gp/T/jest_dy
  2. cd to that project and explore

Jest Cache

@nvh95 nvh95 linked a pull request Aug 6, 2022 that will close this issue
1 task
@nvh95
Copy link
Owner Author

nvh95 commented Aug 20, 2022

My hypothesis: If we do not explicitly implement getCacheKey. It will use src and filename as cache key.

So, we should add transformer file content into account. So each time we upgrade the transformer. The Jest cache get cleared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to current features/ behaviors feature request Request a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant