From 3c87e31b94d5da0b76bed2f1638dbb8a898e9ded Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 28 Apr 2020 13:16:33 +0200 Subject: [PATCH] Revert "no cached readfile" This reverts commit 00c572ae43942321d35d7bffefa460c4bee60619. --- packages/jest-runtime/src/index.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 86dedbce5827..06b50eab2b89 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -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, @@ -1031,14 +1031,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); @@ -1608,6 +1610,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 {