Skip to content

Commit 090ca7b

Browse files
committed
perf(cache): share config-sets for parallel test running
1 parent 5ef980f commit 090ca7b

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

e2e/__tests__/__snapshots__/logger.test.ts.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Array [
88
"[level:20] checking version of jest: OK",
99
"[level:20] created new transformer",
1010
"[level:20] computing cache key for <cwd>/Hello.spec.ts",
11+
"[level:30] no matching config-set found, creating a new one",
1112
"[level:20] backporting config",
1213
"[level:20] normalized jest config",
1314
"[level:20] normalized ts-jest config",
@@ -40,6 +41,7 @@ Array [
4041
"[level:20] checking version of jest: OK",
4142
"[level:20] created new transformer",
4243
"[level:20] computing cache key for <cwd>/Hello.spec.ts",
44+
"[level:30] no matching config-set found, creating a new one",
4345
"[level:20] backporting config",
4446
"[level:20] normalized jest config",
4547
"[level:20] normalized ts-jest config",
@@ -83,6 +85,7 @@ Array [
8385
"[level:20] checking version of jest: OK",
8486
"[level:20] created new transformer",
8587
"[level:20] computing cache key for <cwd>/Hello.spec.ts",
88+
"[level:30] no matching config-set found, creating a new one",
8689
"[level:20] backporting config",
8790
"[level:20] normalized jest config",
8891
"[level:20] normalized ts-jest config",
@@ -124,6 +127,7 @@ Array [
124127
"[level:20] checking version of jest: OK",
125128
"[level:20] created new transformer",
126129
"[level:20] computing cache key for <cwd>/Hello.spec.ts",
130+
"[level:30] no matching config-set found, creating a new one",
127131
"[level:20] backporting config",
128132
"[level:20] normalized jest config",
129133
"[level:20] normalized ts-jest config",
@@ -156,6 +160,7 @@ Array [
156160
"[level:20] checking version of jest: OK",
157161
"[level:20] created new transformer",
158162
"[level:20] computing cache key for <cwd>/Hello.spec.ts",
163+
"[level:30] no matching config-set found, creating a new one",
159164
"[level:20] backporting config",
160165
"[level:20] normalized jest config",
161166
"[level:20] normalized ts-jest config",

src/ts-jest-transformer.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,19 @@ interface ConfigSetIndexItem {
1818
}
1919

2020
export class TsJestTransformer implements jest.Transformer {
21-
protected static _lastTransformerId: number = 0
21+
private static _configSetsIndex: ConfigSetIndexItem[] = []
22+
private static _lastTransformerId: number = 0
2223
static get lastTransformerId() {
2324
return TsJestTransformer._lastTransformerId
2425
}
25-
protected static get _nextTransformerId() {
26+
private static get _nextTransformerId() {
2627
return ++TsJestTransformer._lastTransformerId
2728
}
2829

2930
readonly logger: Logger
3031
readonly id: number
3132
readonly options: TsJestGlobalOptions
3233

33-
private _configSetsIndex: ConfigSetIndexItem[] = []
34-
3534
constructor(baseOptions: TsJestGlobalOptions = {}) {
3635
this.options = { ...baseOptions }
3736
this.id = TsJestTransformer._nextTransformerId
@@ -50,17 +49,19 @@ export class TsJestTransformer implements jest.Transformer {
5049
let csi: ConfigSetIndexItem | undefined
5150
let jestConfigObj: jest.ProjectConfig
5251
if (typeof jestConfig === 'string') {
53-
csi = this._configSetsIndex.find(
52+
csi = TsJestTransformer._configSetsIndex.find(
5453
cs => cs.jestConfig.serialized === jestConfig,
5554
)
5655
if (csi) return csi.configSet
5756
jestConfigObj = parse(jestConfig)
5857
} else {
59-
csi = this._configSetsIndex.find(cs => cs.jestConfig.value === jestConfig)
58+
csi = TsJestTransformer._configSetsIndex.find(
59+
cs => cs.jestConfig.value === jestConfig,
60+
)
6061
if (csi) return csi.configSet
6162
// try to look-it up by stringified version
6263
const serialized = stringify(jestConfig)
63-
csi = this._configSetsIndex.find(
64+
csi = TsJestTransformer._configSetsIndex.find(
6465
cs => cs.jestConfig.serialized === serialized,
6566
)
6667
if (csi) {
@@ -74,8 +75,9 @@ export class TsJestTransformer implements jest.Transformer {
7475
}
7576

7677
// create the new record in the index
78+
this.logger.info(`no matching config-set found, creating a new one`)
7779
const configSet = new ConfigSet(jestConfigObj, this.options, this.logger)
78-
this._configSetsIndex.push({
80+
TsJestTransformer._configSetsIndex.push({
7981
jestConfig: new JsonableValue(jestConfigObj),
8082
configSet,
8183
})

0 commit comments

Comments
 (0)