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
31 changes: 31 additions & 0 deletions src/compiler/ts-compiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ describe('TsCompiler', () => {
beforeEach(() => {
// @ts-expect-error testing purpose
compiler._projectVersion = 1
/**
* This is to ensure that `compilerOptions` value and `_parsedTsConfig.fileNames` are always like
* when compiler instance is created since here we only create compiler instance once for all the tests below.
*/
// @ts-expect-error testing purpose.
compiler._compilerOptions = { ...compiler._initialCompilerOptions }
// @ts-expect-error testing purpose.
compiler._parsedTsConfig.fileNames = []
fileContentCache.clear()
fileVersionCache.clear()
})
Expand Down Expand Up @@ -360,6 +368,29 @@ describe('TsCompiler', () => {
expect(compiler._projectVersion).toEqual(2)
})

test('should increase project version if processing file is in compiler file list', () => {
// @ts-expect-error testing purpose
compiler._parsedTsConfig.fileNames.push(fileName)
fileContentCache.set(fileName, fileContent)
fileVersionCache.set(fileName, 1)
// @ts-expect-error testing purpose
compiler._fileContentCache = fileContentCache
// @ts-expect-error testing purpose
compiler._fileVersionCache = fileVersionCache
// @ts-expect-error testing purpose
compiler._compilerOptions = {
// @ts-expect-error testing purpose
...compiler._compilerOptions,
module: ModuleKind.AMD,
}

// @ts-expect-error testing purpose
compiler._updateMemoryCache(fileContent, fileName)

// @ts-expect-error testing purpose
expect(compiler._projectVersion).toEqual(2)
})

test('should increase project version if processing file version is 0', () => {
fileContentCache.set(fileName, fileContent)
fileVersionCache.set(fileName, 0)
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/ts-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import type {
TsJestCompileOptions,
TTypeScript,
} from '../types'
import { stringify } from '../utils/json'
import { rootLogger } from '../utils/logger'
import { Errors, interpolate } from '../utils/messages'

Expand Down Expand Up @@ -405,6 +406,9 @@ export class TsCompiler implements TsCompilerInstance {
shouldIncrementProjectVersion = true
}
}
if (stringify(this._compilerOptions) !== stringify(this._initialCompilerOptions)) {
shouldIncrementProjectVersion = true
}

if (shouldIncrementProjectVersion) this._projectVersion++
}
Expand Down