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

JestRuntime:-Using scriptTransformer cache in jest-runner #13735

Merged
merged 3 commits into from
Jan 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- `[@jest/expect-utils]` `toMatchObject` should handle `Symbol` properties ([#13639](https://github.com/facebook/jest/pull/13639))
- `[jest-resolve]` Add global paths to `require.resolve.paths` ([#13633](https://github.com/facebook/jest/pull/13633))
- `[jest-runtime]` Support Wasm files that import JS resources ([#13608](https://github.com/facebook/jest/pull/13608))
- `[jest-runtime]` Using the scriptTransformer cache in jest-runner ([#13735](https://github.com/facebook/jest/pull/13735))
- `[jest-snapshot]` Make sure to import `babel` outside of the sandbox ([#13694](https://github.com/facebook/jest/pull/13694))

### Chore & Maintenance
Expand Down
29 changes: 8 additions & 21 deletions packages/jest-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import {
CallerTransformOptions,
ScriptTransformer,
ShouldInstrumentOptions,
TransformResult,
TransformationOptions,
handlePotentialSyntaxError,
shouldInstrument,
Expand Down Expand Up @@ -1574,14 +1573,7 @@ export default class Runtime {
return source;
}

let transformedFile: TransformResult | undefined =
this._fileTransforms.get(filename);

if (transformedFile) {
return transformedFile.code;
}

transformedFile = this._scriptTransformer.transform(
const transformedFile = this._scriptTransformer.transform(
filename,
this._getFullTransformationOptions(options),
source,
Expand All @@ -1608,23 +1600,18 @@ export default class Runtime {
return source;
}

let transformedFile: TransformResult | undefined =
this._fileTransforms.get(filename);

if (transformedFile) {
return transformedFile.code;
}

transformedFile = await this._scriptTransformer.transformAsync(
const transformedFile = await this._scriptTransformer.transformAsync(
filename,
this._getFullTransformationOptions(options),
source,
);

this._fileTransforms.set(filename, {
...transformedFile,
wrapperLength: 0,
});
if (this._fileTransforms.get(filename)?.code !== transformedFile.code) {
this._fileTransforms.set(filename, {
...transformedFile,
wrapperLength: 0,
});
}

if (transformedFile.sourceMapPath) {
this._sourceMapRegistry.set(filename, transformedFile.sourceMapPath);
Expand Down