Skip to content

Commit

Permalink
Revert "no cached readfile"
Browse files Browse the repository at this point in the history
This reverts commit 00c572a.
  • Loading branch information
SimenB committed Apr 28, 2020
1 parent 240f3aa commit 5cb78d8
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/jest-runtime/src/index.ts
Expand Up @@ -641,7 +641,7 @@ class Runtime {
moduleRegistry: ModuleRegistry,
) {
if (path.extname(modulePath) === '.json') {
const text = stripBOM(fs.readFileSync(modulePath, 'utf8'));
const text = stripBOM(this.readFile(modulePath));

const transformedFile = this._scriptTransformer.transformJson(
modulePath,
Expand Down Expand Up @@ -1059,14 +1059,16 @@ class Runtime {
filename: string,
options?: InternalModuleOptions,
): string {
const source = this.readFile(filename);

if (options?.isInternalModule) {
return this._cacheFS[filename] ?? fs.readFileSync(filename, 'utf8');
return source;
}

const transformedFile = this._scriptTransformer.transform(
filename,
this._getFullTransformationOptions(options),
this._cacheFS[filename],
source,
);

this._fileTransforms.set(filename, transformedFile);
Expand Down Expand Up @@ -1636,6 +1638,18 @@ class Runtime {
xtest: this._environment.global.xtest,
};
}

private readFile(filename: Config.Path): string {
let source = this._cacheFS[filename];

if (!source) {
source = fs.readFileSync(filename, 'utf8');

this._cacheFS[filename] = source;
}

return source;
}
}

function invariant(condition: unknown, message?: string): asserts condition {
Expand Down

0 comments on commit 5cb78d8

Please sign in to comment.