Skip to content

Commit

Permalink
JestRuntime:-Using scriptTransformer cache in jest-runner (#13735)
Browse files Browse the repository at this point in the history
  • Loading branch information
Biki-das authored Jan 7, 2023
1 parent a5e256d commit d2420aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- `[jest-mock]` fix mockReset and resetAllMocks undefined return ([#13692](https://github.com/facebook/jest/pull/13692))
- `[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

0 comments on commit d2420aa

Please sign in to comment.