From d47d1ebdb9248f722408431eba0b061c82dbc127 Mon Sep 17 00:00:00 2001 From: Sorin Davidoi Date: Wed, 9 Feb 2022 23:25:45 +0100 Subject: [PATCH] perf(transformer): leverage the `ts-jest` config set cache (#1318) Instead of creating ConfigSet instances all the time (which is an expensive operation, as it involves path concatenations, merging configurations, reading from disk...), we use a private method in `ts-jest` that caches the configurations. Fixes #1311 --- src/ng-jest-transformer.spec.ts | 2 ++ src/ng-jest-transformer.ts | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ng-jest-transformer.spec.ts b/src/ng-jest-transformer.spec.ts index 686874a55c..0c089a8da4 100644 --- a/src/ng-jest-transformer.spec.ts +++ b/src/ng-jest-transformer.spec.ts @@ -105,6 +105,7 @@ describe('NgJestTransformer', () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const transformSyncMock = transformSync as unknown as jest.MockInstance; const transformCfg = { + cacheFS: new Map(), config: { cwd: process.cwd(), extensionsToTreatAsEsm: [], @@ -161,6 +162,7 @@ describe('NgJestTransformer', () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const transformSyncMock = transformSync as unknown as jest.MockInstance; const transformCfg = { + cacheFS: new Map(), config: { cwd: process.cwd(), extensionsToTreatAsEsm: [], diff --git a/src/ng-jest-transformer.ts b/src/ng-jest-transformer.ts index cd284dec17..95cc4450e6 100644 --- a/src/ng-jest-transformer.ts +++ b/src/ng-jest-transformer.ts @@ -50,7 +50,8 @@ export class NgJestTransformer extends TsJestTransformer { filePath: Config.Path, transformOptions: TransformOptionsTsJest, ): TransformedSource | string { - const configSet = this._createConfigSet(transformOptions.config); + // @ts-expect-error we are accessing the private cache to avoid creating new objects all the time + const configSet = super._configsFor(transformOptions); /** * TypeScript < 4.5 doesn't support compiling `.mjs` file by default when running `tsc` which throws error. Also we * transform `js` files from `node_modules` assuming that `node_modules` contains compiled files to speed up compilation.