Skip to content

Commit 5f91336

Browse files
authoredFeb 13, 2021
fix(config): cache config and compiler correctly between runs (#2356)
1 parent 63ce57d commit 5f91336

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed
 

‎src/ts-jest-transformer.spec.ts

+22-8
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,32 @@ beforeEach(() => {
3131

3232
describe('TsJestTransformer', () => {
3333
describe('_configsFor', () => {
34+
const obj1 = {
35+
config: { cwd: process.cwd(), extensionsToTreatAsEsm: [], globals: {}, testMatch: [], testRegex: [] },
36+
cacheFS: new Map(),
37+
}
38+
39+
test('should cache necessary things', () => {
40+
// @ts-expect-error testing purpose
41+
new TsJestTransformer()._configsFor(obj1)
42+
43+
// @ts-expect-error testing purpose
44+
expect(Object.keys(TsJestTransformer._cachedConfigSets[0])).toMatchInlineSnapshot(`
45+
Array [
46+
"jestConfig",
47+
"configSet",
48+
"transformerCfgStr",
49+
"compiler",
50+
"depGraphs",
51+
"tsResolvedModulesCachePath",
52+
]
53+
`)
54+
})
55+
3456
test(
3557
'should return the same config set for same values with different jest config objects' +
3658
' but their serialized versions are the same',
3759
() => {
38-
const obj1 = {
39-
config: { cwd: process.cwd(), extensionsToTreatAsEsm: [], globals: {}, testMatch: [], testRegex: [] },
40-
cacheFS: new Map(),
41-
}
4260
const obj2 = { ...obj1, config: { ...obj1.config, globals: Object.create(null) } }
4361
// @ts-expect-error testing purpose
4462
const cs1 = new TsJestTransformer()._configsFor(obj1)
@@ -50,10 +68,6 @@ describe('TsJestTransformer', () => {
5068
)
5169

5270
test('should return the same config set for same values with jest config objects', () => {
53-
const obj1 = {
54-
config: { cwd: process.cwd(), extensionsToTreatAsEsm: [], globals: {}, testMatch: [], testRegex: [] },
55-
cacheFS: new Map(),
56-
}
5771
const obj2 = { ...obj1 }
5872
// @ts-expect-error testing purpose
5973
const cs1 = new TsJestTransformer()._configsFor(obj1)

‎src/ts-jest-transformer.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ interface CachedConfigSet {
2323
jestConfig: JsonableValue<ProjectConfigTsJest>
2424
transformerCfgStr: string
2525
compiler: TsJestCompiler
26+
depGraphs: Map<string, DepGraphInfo>
27+
tsResolvedModulesCachePath: string | undefined
2628
}
2729

2830
interface TsJestHooksMap {
@@ -65,6 +67,8 @@ export class TsJestTransformer implements Transformer {
6567
if (ccs) {
6668
this._transformCfgStr = ccs.transformerCfgStr
6769
this._compiler = ccs.compiler
70+
this._depGraphs = ccs.depGraphs
71+
this._tsResolvedModulesCachePath = ccs.tsResolvedModulesCachePath
6872
configSet = ccs.configSet
6973
} else {
7074
// try to look-it up by stringified version
@@ -79,6 +83,8 @@ export class TsJestTransformer implements Transformer {
7983
serializedCcs.jestConfig.value = config
8084
this._transformCfgStr = serializedCcs.transformerCfgStr
8185
this._compiler = serializedCcs.compiler
86+
this._depGraphs = serializedCcs.depGraphs
87+
this._tsResolvedModulesCachePath = serializedCcs.tsResolvedModulesCachePath
8288
configSet = serializedCcs.configSet
8389
} else {
8490
// create the new record in the index
@@ -92,13 +98,15 @@ export class TsJestTransformer implements Transformer {
9298
jest.cacheDirectory = undefined as any
9399
this._transformCfgStr = `${new JsonableValue(jest).serialized}${configSet.cacheSuffix}`
94100
this._compiler = new TsJestCompiler(configSet, cacheFS)
101+
this._getFsCachedResolvedModules(configSet)
95102
TsJestTransformer._cachedConfigSets.push({
96103
jestConfig: new JsonableValue(config),
97104
configSet,
98105
transformerCfgStr: this._transformCfgStr,
99106
compiler: this._compiler,
107+
depGraphs: this._depGraphs,
108+
tsResolvedModulesCachePath: this._tsResolvedModulesCachePath,
100109
})
101-
this._getFsCachedResolvedModules(configSet)
102110
}
103111
}
104112

0 commit comments

Comments
 (0)
Please sign in to comment.