Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): make sure language service use updated compiler options #2628

Merged
merged 1 commit into from May 26, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/compiler/ts-compiler.spec.ts
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
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