Skip to content

Commit

Permalink
perf(transformer): leverage the ts-jest config set cache (#1318)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sorin-davidoi authored Feb 9, 2022
1 parent 14b2b98 commit d47d1eb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/ng-jest-transformer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ describe('NgJestTransformer', () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const transformSyncMock = transformSync as unknown as jest.MockInstance<unknown, any>;
const transformCfg = {
cacheFS: new Map(),
config: {
cwd: process.cwd(),
extensionsToTreatAsEsm: [],
Expand Down Expand Up @@ -161,6 +162,7 @@ describe('NgJestTransformer', () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const transformSyncMock = transformSync as unknown as jest.MockInstance<unknown, any>;
const transformCfg = {
cacheFS: new Map(),
config: {
cwd: process.cwd(),
extensionsToTreatAsEsm: [],
Expand Down
3 changes: 2 additions & 1 deletion src/ng-jest-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d47d1eb

Please sign in to comment.