From 240f3aa4ae1ee3ed080a9b36c3483e9979cd9109 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 27 Apr 2020 22:34:28 +0200 Subject: [PATCH] no cached readfile --- packages/jest-runtime/src/index.ts | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 737258df6c92..dc23b3c63a1d 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(this.readFile(modulePath)); + const text = stripBOM(fs.readFileSync(modulePath, 'utf8')); const transformedFile = this._scriptTransformer.transformJson( modulePath, @@ -1059,16 +1059,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); @@ -1638,18 +1636,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 {