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 the source of a test file to avoid reading it twice #3060

Closed
SimenB opened this issue Mar 3, 2017 · 1 comment · Fixed by #3125
Closed

Cache the source of a test file to avoid reading it twice #3060

SimenB opened this issue Mar 3, 2017 · 1 comment · Fixed by #3125

Comments

@SimenB
Copy link
Member

SimenB commented Mar 3, 2017

Do you want to request a feature or report a bug?
Feature, I suppose

What is the current behavior?
As of the behavior introduced in #2859, all test files are read from disk twice; once inrunTest.js in order to check for docblocks, and once in jest-runtime to actually transform and run it. This is unnecessary, the content should only be read once.

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.
N/A

What is the expected behavior?
That the source code is only read once. See @cpojer's suggestion in #2859

I'm a bit worried about the fact that this will end up reading every test file twice and we could potentially change things around by passing a fake FS into ModuleLoader that has a cache, like this:
new ModuleLoader({
…,
cacheFS: {
[path]: source,
},
});
and then later pass that source to transform inside of jest-runtime so that we don't read the same file twice.

The idea was to change jest-runtime to accept a cacheFS property in the constructor which is just a map from path -> source. Then inside of _execModule we could pass on the source that we already read to the transform function somehow. Basically we could do transform(…, {source: this._cacheFS[pathToFile] || null}) – does that make sense?

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
N/A

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant