Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/ts-jest-transformer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,32 @@ beforeEach(() => {

describe('TsJestTransformer', () => {
describe('_configsFor', () => {
const obj1 = {
config: { cwd: process.cwd(), extensionsToTreatAsEsm: [], globals: {}, testMatch: [], testRegex: [] },
cacheFS: new Map(),
}

test('should cache necessary things', () => {
// @ts-expect-error testing purpose
new TsJestTransformer()._configsFor(obj1)

// @ts-expect-error testing purpose
expect(Object.keys(TsJestTransformer._cachedConfigSets[0])).toMatchInlineSnapshot(`
Array [
"jestConfig",
"configSet",
"transformerCfgStr",
"compiler",
"depGraphs",
"tsResolvedModulesCachePath",
]
`)
})

test(
'should return the same config set for same values with different jest config objects' +
' but their serialized versions are the same',
() => {
const obj1 = {
config: { cwd: process.cwd(), extensionsToTreatAsEsm: [], globals: {}, testMatch: [], testRegex: [] },
cacheFS: new Map(),
}
const obj2 = { ...obj1, config: { ...obj1.config, globals: Object.create(null) } }
// @ts-expect-error testing purpose
const cs1 = new TsJestTransformer()._configsFor(obj1)
Expand All @@ -50,10 +68,6 @@ describe('TsJestTransformer', () => {
)

test('should return the same config set for same values with jest config objects', () => {
const obj1 = {
config: { cwd: process.cwd(), extensionsToTreatAsEsm: [], globals: {}, testMatch: [], testRegex: [] },
cacheFS: new Map(),
}
const obj2 = { ...obj1 }
// @ts-expect-error testing purpose
const cs1 = new TsJestTransformer()._configsFor(obj1)
Expand Down
10 changes: 9 additions & 1 deletion src/ts-jest-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ interface CachedConfigSet {
jestConfig: JsonableValue<ProjectConfigTsJest>
transformerCfgStr: string
compiler: TsJestCompiler
depGraphs: Map<string, DepGraphInfo>
tsResolvedModulesCachePath: string | undefined
}

interface TsJestHooksMap {
Expand Down Expand Up @@ -65,6 +67,8 @@ export class TsJestTransformer implements Transformer {
if (ccs) {
this._transformCfgStr = ccs.transformerCfgStr
this._compiler = ccs.compiler
this._depGraphs = ccs.depGraphs
this._tsResolvedModulesCachePath = ccs.tsResolvedModulesCachePath
configSet = ccs.configSet
} else {
// try to look-it up by stringified version
Expand All @@ -79,6 +83,8 @@ export class TsJestTransformer implements Transformer {
serializedCcs.jestConfig.value = config
this._transformCfgStr = serializedCcs.transformerCfgStr
this._compiler = serializedCcs.compiler
this._depGraphs = serializedCcs.depGraphs
this._tsResolvedModulesCachePath = serializedCcs.tsResolvedModulesCachePath
configSet = serializedCcs.configSet
} else {
// create the new record in the index
Expand All @@ -92,13 +98,15 @@ export class TsJestTransformer implements Transformer {
jest.cacheDirectory = undefined as any
this._transformCfgStr = `${new JsonableValue(jest).serialized}${configSet.cacheSuffix}`
this._compiler = new TsJestCompiler(configSet, cacheFS)
this._getFsCachedResolvedModules(configSet)
TsJestTransformer._cachedConfigSets.push({
jestConfig: new JsonableValue(config),
configSet,
transformerCfgStr: this._transformCfgStr,
compiler: this._compiler,
depGraphs: this._depGraphs,
tsResolvedModulesCachePath: this._tsResolvedModulesCachePath,
})
this._getFsCachedResolvedModules(configSet)
}
}

Expand Down