Skip to content

Commit

Permalink
perf(cache): share config-sets for parallel test running
Browse files Browse the repository at this point in the history
  • Loading branch information
huafu committed Sep 1, 2018
1 parent 5ef980f commit 090ca7b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
5 changes: 5 additions & 0 deletions e2e/__tests__/__snapshots__/logger.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Array [
"[level:20] checking version of jest: OK",
"[level:20] created new transformer",
"[level:20] computing cache key for <cwd>/Hello.spec.ts",
"[level:30] no matching config-set found, creating a new one",
"[level:20] backporting config",
"[level:20] normalized jest config",
"[level:20] normalized ts-jest config",
Expand Down Expand Up @@ -40,6 +41,7 @@ Array [
"[level:20] checking version of jest: OK",
"[level:20] created new transformer",
"[level:20] computing cache key for <cwd>/Hello.spec.ts",
"[level:30] no matching config-set found, creating a new one",
"[level:20] backporting config",
"[level:20] normalized jest config",
"[level:20] normalized ts-jest config",
Expand Down Expand Up @@ -83,6 +85,7 @@ Array [
"[level:20] checking version of jest: OK",
"[level:20] created new transformer",
"[level:20] computing cache key for <cwd>/Hello.spec.ts",
"[level:30] no matching config-set found, creating a new one",
"[level:20] backporting config",
"[level:20] normalized jest config",
"[level:20] normalized ts-jest config",
Expand Down Expand Up @@ -124,6 +127,7 @@ Array [
"[level:20] checking version of jest: OK",
"[level:20] created new transformer",
"[level:20] computing cache key for <cwd>/Hello.spec.ts",
"[level:30] no matching config-set found, creating a new one",
"[level:20] backporting config",
"[level:20] normalized jest config",
"[level:20] normalized ts-jest config",
Expand Down Expand Up @@ -156,6 +160,7 @@ Array [
"[level:20] checking version of jest: OK",
"[level:20] created new transformer",
"[level:20] computing cache key for <cwd>/Hello.spec.ts",
"[level:30] no matching config-set found, creating a new one",
"[level:20] backporting config",
"[level:20] normalized jest config",
"[level:20] normalized ts-jest config",
Expand Down
18 changes: 10 additions & 8 deletions src/ts-jest-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@ interface ConfigSetIndexItem {
}

export class TsJestTransformer implements jest.Transformer {
protected static _lastTransformerId: number = 0
private static _configSetsIndex: ConfigSetIndexItem[] = []
private static _lastTransformerId: number = 0
static get lastTransformerId() {
return TsJestTransformer._lastTransformerId
}
protected static get _nextTransformerId() {
private static get _nextTransformerId() {
return ++TsJestTransformer._lastTransformerId
}

readonly logger: Logger
readonly id: number
readonly options: TsJestGlobalOptions

private _configSetsIndex: ConfigSetIndexItem[] = []

constructor(baseOptions: TsJestGlobalOptions = {}) {
this.options = { ...baseOptions }
this.id = TsJestTransformer._nextTransformerId
Expand All @@ -50,17 +49,19 @@ export class TsJestTransformer implements jest.Transformer {
let csi: ConfigSetIndexItem | undefined
let jestConfigObj: jest.ProjectConfig
if (typeof jestConfig === 'string') {
csi = this._configSetsIndex.find(
csi = TsJestTransformer._configSetsIndex.find(
cs => cs.jestConfig.serialized === jestConfig,
)
if (csi) return csi.configSet
jestConfigObj = parse(jestConfig)
} else {
csi = this._configSetsIndex.find(cs => cs.jestConfig.value === jestConfig)
csi = TsJestTransformer._configSetsIndex.find(
cs => cs.jestConfig.value === jestConfig,
)
if (csi) return csi.configSet
// try to look-it up by stringified version
const serialized = stringify(jestConfig)
csi = this._configSetsIndex.find(
csi = TsJestTransformer._configSetsIndex.find(
cs => cs.jestConfig.serialized === serialized,
)
if (csi) {
Expand All @@ -74,8 +75,9 @@ export class TsJestTransformer implements jest.Transformer {
}

// create the new record in the index
this.logger.info(`no matching config-set found, creating a new one`)
const configSet = new ConfigSet(jestConfigObj, this.options, this.logger)
this._configSetsIndex.push({
TsJestTransformer._configSetsIndex.push({
jestConfig: new JsonableValue(jestConfigObj),
configSet,
})
Expand Down

0 comments on commit 090ca7b

Please sign in to comment.