Skip to content
/ jest Public
forked from jestjs/jest

Commit

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

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

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

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

this._fileTransforms.set(filename, transformedFile);
Expand Down Expand Up @@ -1610,18 +1608,6 @@ 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 00c572a

Please sign in to comment.