• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kulshekhar / ts-jest / 9804725795

05 Jul 2024 07:30AM UTC coverage: 96.474%. Remained the same
9804725795

push

github

ahnpnl
build(deps): Update dependency eslint-plugin-jsdoc to ^48.5.1

788 of 885 branches covered (89.04%)

Branch coverage included in aggregate %.

4712 of 4816 relevant lines covered (97.84%)

1248.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.83
/src/legacy/compiler/ts-compiler.ts
1
import { basename, normalize } from 'path'
6✔
2

6✔
3
import { LogContexts, Logger, LogLevels } from 'bs-logger'
6✔
4
import memoize from 'lodash.memoize'
6✔
5
import type {
6✔
6
  Bundle,
6✔
7
  CompilerOptions,
6✔
8
  CustomTransformerFactory,
6✔
9
  CustomTransformers,
6✔
10
  Diagnostic,
6✔
11
  EmitOutput,
6✔
12
  LanguageService,
6✔
13
  LanguageServiceHost,
6✔
14
  ModuleResolutionCache,
6✔
15
  ModuleResolutionHost,
6✔
16
  ParsedCommandLine,
6✔
17
  Program,
6✔
18
  ResolvedModuleFull,
6✔
19
  ResolvedModuleWithFailedLookupLocations,
6✔
20
  SourceFile,
6✔
21
  TransformerFactory,
6✔
22
  TranspileOutput,
6✔
23
} from 'typescript'
6✔
24

6✔
25
import { LINE_FEED, TS_TSX_REGEX } from '../../constants'
6✔
26
import type {
6✔
27
  StringMap,
6✔
28
  TsCompilerInstance,
6✔
29
  TsJestAstTransformer,
6✔
30
  TsJestCompileOptions,
6✔
31
  TTypeScript,
6✔
32
} from '../../types'
6✔
33
import { CompiledOutput } from '../../types'
6✔
34
import { rootLogger } from '../../utils'
6✔
35
import { Errors, interpolate } from '../../utils/messages'
6✔
36
import type { ConfigSet } from '../config/config-set'
6✔
37

6✔
38
import { updateOutput } from './compiler-utils'
6✔
39

6✔
40
export class TsCompiler implements TsCompilerInstance {
6✔
41
  protected readonly _logger: Logger
6✔
42
  protected readonly _ts: TTypeScript
6✔
43
  protected readonly _initialCompilerOptions: CompilerOptions
6✔
44
  protected _compilerOptions: CompilerOptions
6✔
45
  /**
6✔
46
   * @private
6✔
47
   */
6✔
48
  private _runtimeCacheFS: StringMap
6✔
49
  /**
6✔
50
   * @private
6✔
51
   */
6✔
52
  private _fileContentCache: StringMap | undefined
6✔
53
  /**
6✔
54
   * @internal
6✔
55
   */
6✔
56
  private readonly _parsedTsConfig: ParsedCommandLine
6✔
57
  /**
6✔
58
   * @internal
6✔
59
   */
6✔
60
  private readonly _fileVersionCache: Map<string, number> | undefined
6✔
61
  /**
6✔
62
   * @internal
6✔
63
   */
6✔
64
  private readonly _cachedReadFile: LanguageServiceHost['readFile'] | undefined
6✔
65
  /**
6✔
66
   * @internal
6✔
67
   */
6✔
68
  private _projectVersion = 1
6✔
69
  /**
6✔
70
   * @internal
6✔
71
   */
6✔
72
  private _languageService: LanguageService | undefined
6✔
73
  /**
6✔
74
   * @internal
6✔
75
   */
6✔
76
  private readonly _moduleResolutionHost: ModuleResolutionHost | undefined
6✔
77
  /**
6✔
78
   * @internal
6✔
79
   */
6✔
80
  private readonly _moduleResolutionCache: ModuleResolutionCache | undefined
6✔
81

6✔
82
  program: Program | undefined
6✔
83

6✔
84
  constructor(readonly configSet: ConfigSet, readonly runtimeCacheFS: StringMap) {
6✔
85
    this._ts = configSet.compilerModule
249✔
86
    this._logger = rootLogger.child({ namespace: 'ts-compiler' })
249✔
87
    this._parsedTsConfig = this.configSet.parsedTsConfig as ParsedCommandLine
249✔
88
    this._initialCompilerOptions = { ...this._parsedTsConfig.options }
249✔
89
    this._compilerOptions = { ...this._initialCompilerOptions }
249✔
90
    this._runtimeCacheFS = runtimeCacheFS
249✔
91
    if (!this.configSet.isolatedModules) {
249✔
92
      this._fileContentCache = new Map<string, string>()
189✔
93
      this._fileVersionCache = new Map<string, number>()
189✔
94
      this._cachedReadFile = this._logger.wrap(
189✔
95
        {
189✔
96
          namespace: 'ts:serviceHost',
189✔
97
          call: null,
189✔
98
          [LogContexts.logLevel]: LogLevels.trace,
189✔
99
        },
189✔
100
        'readFile',
189✔
101
        memoize(this._ts.sys.readFile),
189✔
102
      )
189✔
103
      /* istanbul ignore next */
189✔
104
      this._moduleResolutionHost = {
189✔
105
        fileExists: memoize(this._ts.sys.fileExists),
189✔
106
        readFile: this._cachedReadFile,
189✔
107
        directoryExists: memoize(this._ts.sys.directoryExists),
189✔
108
        getCurrentDirectory: () => this.configSet.cwd,
189✔
109
        realpath: this._ts.sys.realpath && memoize(this._ts.sys.realpath),
189✔
110
        getDirectories: memoize(this._ts.sys.getDirectories),
189✔
111
        useCaseSensitiveFileNames: () => this._ts.sys.useCaseSensitiveFileNames,
189✔
112
      }
189✔
113
      this._moduleResolutionCache = this._ts.createModuleResolutionCache(
189✔
114
        this.configSet.cwd,
189✔
115
        this._ts.sys.useCaseSensitiveFileNames ? (x) => x : (x) => x.toLowerCase(),
189!
116
        this._compilerOptions,
189✔
117
      )
189✔
118
      this._createLanguageService()
189✔
119
    }
189✔
120
  }
249✔
121

6✔
122
  getResolvedModules(fileContent: string, fileName: string, runtimeCacheFS: StringMap): string[] {
6✔
123
    // In watch mode, it is possible that the initial cacheFS becomes empty
24✔
124
    if (!this.runtimeCacheFS.size) {
24✔
125
      this._runtimeCacheFS = runtimeCacheFS
12✔
126
    }
12✔
127

24✔
128
    this._logger.debug({ fileName }, 'getResolvedModules(): resolve direct imported module paths')
24✔
129

24✔
130
    const importedModulePaths: string[] = Array.from(new Set(this._getImportedModulePaths(fileContent, fileName)))
24✔
131

24✔
132
    this._logger.debug(
24✔
133
      { fileName },
24✔
134
      'getResolvedModules(): resolve nested imported module paths from directed imported module paths',
24✔
135
    )
24✔
136

24✔
137
    importedModulePaths.forEach((importedModulePath) => {
24✔
138
      const resolvedFileContent = this._getFileContentFromCache(importedModulePath)
18✔
139
      importedModulePaths.push(
18✔
140
        ...this._getImportedModulePaths(resolvedFileContent, importedModulePath).filter(
18✔
141
          (modulePath) => !importedModulePaths.includes(modulePath),
18✔
142
        ),
18✔
143
      )
18✔
144
    })
24✔
145

24✔
146
    return importedModulePaths
24✔
147
  }
24✔
148

6✔
149
  getCompiledOutput(fileContent: string, fileName: string, options: TsJestCompileOptions): CompiledOutput {
6✔
150
    let moduleKind = this._initialCompilerOptions.module
108✔
151
    let esModuleInterop = this._initialCompilerOptions.esModuleInterop
108✔
152
    let allowSyntheticDefaultImports = this._initialCompilerOptions.allowSyntheticDefaultImports
108✔
153
    const currentModuleKind = this._compilerOptions.module
108✔
154
    const isEsmMode = this.configSet.useESM && options.supportsStaticESM
108✔
155
    if (
108✔
156
      (this.configSet.babelJestTransformer || (!this.configSet.babelJestTransformer && options.supportsStaticESM)) &&
108✔
157
      this.configSet.useESM
48✔
158
    ) {
108✔
159
      moduleKind =
24✔
160
        !moduleKind ||
24✔
161
        (moduleKind &&
24✔
162
          ![this._ts.ModuleKind.ES2015, this._ts.ModuleKind.ES2020, this._ts.ModuleKind.ESNext].includes(moduleKind))
24✔
163
          ? this._ts.ModuleKind.ESNext
24✔
164
          : moduleKind
24!
165
      // Make sure `esModuleInterop` and `allowSyntheticDefaultImports` true to support import CJS into ESM
24✔
166
      esModuleInterop = true
24✔
167
      allowSyntheticDefaultImports = true
24✔
168
    } else {
108✔
169
      moduleKind = this._ts.ModuleKind.CommonJS
84✔
170
    }
84✔
171
    this._compilerOptions = {
108✔
172
      ...this._compilerOptions,
108✔
173
      allowSyntheticDefaultImports,
108✔
174
      esModuleInterop,
108✔
175
      module: moduleKind,
108✔
176
    }
108✔
177
    if (this._languageService) {
108✔
178
      this._logger.debug({ fileName }, 'getCompiledOutput(): compiling using language service')
72✔
179

72✔
180
      // Must set memory cache before attempting to compile
72✔
181
      this._updateMemoryCache(fileContent, fileName, currentModuleKind === moduleKind)
72✔
182
      const output: EmitOutput = this._languageService.getEmitOutput(fileName)
72✔
183
      const diagnostics = this.getDiagnostics(fileName)
72✔
184
      if (!isEsmMode && diagnostics.length) {
72✔
185
        this.configSet.raiseDiagnostics(diagnostics, fileName, this._logger)
6✔
186
        if (options.watchMode) {
6!
187
          this._logger.debug({ fileName }, '_doTypeChecking(): starting watch mode computing diagnostics')
×
188

×
189
          for (const entry of options.depGraphs.entries()) {
×
190
            const normalizedModuleNames = entry[1].resolvedModuleNames.map((moduleName) => normalize(moduleName))
×
191
            const fileToReTypeCheck = entry[0]
×
192
            if (normalizedModuleNames.includes(fileName) && this.configSet.shouldReportDiagnostics(fileToReTypeCheck)) {
×
193
              this._logger.debug(
×
194
                { fileToReTypeCheck },
×
195
                '_doTypeChecking(): computing diagnostics using language service',
×
196
              )
×
197

×
198
              this._updateMemoryCache(this._getFileContentFromCache(fileToReTypeCheck), fileToReTypeCheck)
×
199
              const importedModulesDiagnostics = [
×
200
                // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
×
201
                ...this._languageService!.getSemanticDiagnostics(fileToReTypeCheck),
×
202
                // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
×
203
                ...this._languageService!.getSyntacticDiagnostics(fileToReTypeCheck),
×
204
              ]
×
205
              // will raise or just warn diagnostics depending on config
×
206
              this.configSet.raiseDiagnostics(importedModulesDiagnostics, fileName, this._logger)
×
207
            }
×
208
          }
×
209
        }
×
210
      }
6✔
211
      if (output.emitSkipped) {
72✔
212
        if (TS_TSX_REGEX.test(fileName)) {
18✔
213
          throw new Error(interpolate(Errors.CannotProcessFile, { file: fileName }))
12✔
214
        } else {
18✔
215
          this._logger.warn(interpolate(Errors.CannotProcessFileReturnOriginal, { file: fileName }))
6✔
216

6✔
217
          return {
6✔
218
            code: fileContent,
6✔
219
          }
6✔
220
        }
6✔
221
      }
18✔
222
      // Throw an error when requiring `.d.ts` files.
54✔
223
      if (!output.outputFiles.length) {
72✔
224
        throw new TypeError(
6✔
225
          interpolate(Errors.UnableToRequireDefinitionFile, {
6✔
226
            file: basename(fileName),
6✔
227
          }),
6✔
228
        )
6✔
229
      }
6✔
230
      const { outputFiles } = output
48✔
231

48✔
232
      return this._compilerOptions.sourceMap
48✔
233
        ? {
48✔
234
            code: updateOutput(outputFiles[1].text, fileName, outputFiles[0].text),
48✔
235
            diagnostics,
48✔
236
          }
48✔
237
        : {
72!
238
            code: updateOutput(outputFiles[0].text, fileName),
×
239
            diagnostics,
×
240
          }
×
241
    } else {
108✔
242
      this._logger.debug({ fileName }, 'getCompiledOutput(): compiling as isolated module')
36✔
243

36✔
244
      const result: TranspileOutput = this._transpileOutput(fileContent, fileName)
36✔
245
      if (result.diagnostics && this.configSet.shouldReportDiagnostics(fileName)) {
36✔
246
        this.configSet.raiseDiagnostics(result.diagnostics, fileName, this._logger)
30✔
247
      }
30✔
248

36✔
249
      return {
36✔
250
        code: updateOutput(result.outputText, fileName, result.sourceMapText),
36✔
251
      }
36✔
252
    }
36✔
253
  }
108✔
254

6✔
255
  protected _transpileOutput(fileContent: string, fileName: string): TranspileOutput {
6✔
256
    return this._ts.transpileModule(fileContent, {
36✔
257
      fileName,
36✔
258
      transformers: this._makeTransformers(this.configSet.resolvedTransformers),
36✔
259
      compilerOptions: this._compilerOptions,
36✔
260
      reportDiagnostics: this.configSet.shouldReportDiagnostics(fileName),
36✔
261
    })
36✔
262
  }
36✔
263

6✔
264
  protected _makeTransformers(customTransformers: TsJestAstTransformer): CustomTransformers {
6✔
265
    return {
18✔
266
      before: customTransformers.before.map((beforeTransformer) =>
18✔
267
        beforeTransformer.factory(this, beforeTransformer.options),
18✔
268
      ) as Array<TransformerFactory<SourceFile> | CustomTransformerFactory>,
18✔
269
      after: customTransformers.after.map((afterTransformer) =>
18✔
270
        afterTransformer.factory(this, afterTransformer.options),
18✔
271
      ) as Array<TransformerFactory<SourceFile> | CustomTransformerFactory>,
18✔
272
      afterDeclarations: customTransformers.afterDeclarations.map((afterDeclarations) =>
18✔
273
        afterDeclarations.factory(this, afterDeclarations.options),
18✔
274
      ) as Array<TransformerFactory<SourceFile | Bundle>>,
18✔
275
    }
18✔
276
  }
18✔
277

6✔
278
  /**
6✔
279
   * @internal
6✔
280
   */
6✔
281
  private _createLanguageService(): void {
6✔
282
    // Initialize memory cache for typescript compiler
189✔
283
    this._parsedTsConfig.fileNames
189✔
284
      .filter((fileName) => TS_TSX_REGEX.test(fileName) && !this.configSet.isTestFile(fileName))
189✔
285
      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
189✔
286
      .forEach((fileName) => this._fileVersionCache!.set(fileName, 0))
189✔
287
    /* istanbul ignore next */
189✔
288
    const serviceHost: LanguageServiceHost = {
189✔
289
      useCaseSensitiveFileNames: () => this._ts.sys.useCaseSensitiveFileNames,
189✔
290
      getProjectVersion: () => String(this._projectVersion),
189✔
291
      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
189✔
292
      getScriptFileNames: () => [...this._fileVersionCache!.keys()],
189✔
293
      getScriptVersion: (fileName: string) => {
189✔
294
        const normalizedFileName = normalize(fileName)
75,951✔
295
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
75,951✔
296
        const version = this._fileVersionCache!.get(normalizedFileName)
75,951✔
297

75,951✔
298
        // We need to return `undefined` and not a string here because TypeScript will use
75,951✔
299
        // `getScriptVersion` and compare against their own version - which can be `undefined`.
75,951✔
300
        // If we don't return `undefined` it results in `undefined === "undefined"` and run
75,951✔
301
        // `createProgram` again (which is very slow). Using a `string` assertion here to avoid
75,951✔
302
        // TypeScript errors from the function signature (expects `(x: string) => string`).
75,951✔
303
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
75,951✔
304
        return version === undefined ? (undefined as any as string) : String(version)
75,951!
305
      },
189✔
306
      getScriptSnapshot: (fileName: string) => {
189✔
307
        const normalizedFileName = normalize(fileName)
75,951✔
308
        const hit = this._isFileInCache(normalizedFileName)
75,951✔
309

75,951✔
310
        this._logger.trace({ normalizedFileName, cacheHit: hit }, 'getScriptSnapshot():', 'cache', hit ? 'hit' : 'miss')
75,951✔
311

75,951✔
312
        // Read file content from either memory cache or Jest runtime cache or fallback to file system read
75,951✔
313
        if (!hit) {
75,951✔
314
          const fileContent =
67,767✔
315
            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
67,767✔
316
            this._fileContentCache!.get(normalizedFileName) ??
67,767!
317
            this._runtimeCacheFS.get(normalizedFileName) ??
67,767✔
318
            this._cachedReadFile?.(normalizedFileName) ??
67,767!
319
            undefined
×
320
          if (fileContent !== undefined) {
67,767✔
321
            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
67,767✔
322
            this._fileContentCache!.set(normalizedFileName, fileContent)
67,767✔
323
            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
67,767✔
324
            this._fileVersionCache!.set(normalizedFileName, 1)
67,767✔
325
          }
67,767✔
326
        }
67,767✔
327
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
75,951✔
328
        const contents = this._fileContentCache!.get(normalizedFileName)
75,951✔
329

75,951✔
330
        if (contents === undefined) return
75,951!
331

75,951✔
332
        return this._ts.ScriptSnapshot.fromString(contents)
75,951✔
333
      },
189✔
334
      fileExists: memoize(this._ts.sys.fileExists),
189✔
335
      readFile: this._cachedReadFile ?? this._ts.sys.readFile,
189!
336
      readDirectory: memoize(this._ts.sys.readDirectory),
189✔
337
      getDirectories: memoize(this._ts.sys.getDirectories),
189✔
338
      directoryExists: memoize(this._ts.sys.directoryExists),
189✔
339
      realpath: this._ts.sys.realpath && memoize(this._ts.sys.realpath),
189✔
340
      getNewLine: () => LINE_FEED,
189✔
341
      getCurrentDirectory: () => this.configSet.cwd,
189✔
342
      getCompilationSettings: () => this._compilerOptions,
189✔
343
      getDefaultLibFileName: () => this._ts.getDefaultLibFilePath(this._compilerOptions),
189✔
344
      getCustomTransformers: () => this._makeTransformers(this.configSet.resolvedTransformers),
189✔
345
      resolveModuleNames: (moduleNames: string[], containingFile: string): Array<ResolvedModuleFull | undefined> =>
189✔
346
        moduleNames.map((moduleName) => this._resolveModuleName(moduleName, containingFile).resolvedModule),
189✔
347
    }
189✔
348

189✔
349
    this._logger.debug('created language service')
189✔
350

189✔
351
    this._languageService = this._ts.createLanguageService(
189✔
352
      serviceHost,
189✔
353
      this._ts.createDocumentRegistry(this._ts.sys.useCaseSensitiveFileNames, this.configSet.cwd),
189✔
354
    )
189✔
355
    this.program = this._languageService.getProgram()
189✔
356
  }
189✔
357

6✔
358
  /**
6✔
359
   * @internal
6✔
360
   */
6✔
361
  private _getFileContentFromCache(filePath: string): string {
6✔
362
    const normalizedFilePath = normalize(filePath)
18✔
363
    let resolvedFileContent = this._runtimeCacheFS.get(normalizedFilePath)
18✔
364
    if (!resolvedFileContent) {
18✔
365
      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
12✔
366
      resolvedFileContent = this._moduleResolutionHost!.readFile(normalizedFilePath)!
12✔
367
      this._runtimeCacheFS.set(normalizedFilePath, resolvedFileContent)
12✔
368
    }
12✔
369

18✔
370
    return resolvedFileContent
18✔
371
  }
18✔
372

6✔
373
  /**
6✔
374
   * @internal
6✔
375
   */
6✔
376
  private _getImportedModulePaths(resolvedFileContent: string, containingFile: string): string[] {
6✔
377
    return this._ts
42✔
378
      .preProcessFile(resolvedFileContent, true, true)
42✔
379
      .importedFiles.map((importedFile) => {
42✔
380
        const { resolvedModule } = this._resolveModuleName(importedFile.fileName, containingFile)
30✔
381
        /* istanbul ignore next already covered  */
30✔
382
        const resolvedFileName = resolvedModule?.resolvedFileName
30!
383

30✔
384
        /* istanbul ignore next already covered  */
30✔
385
        return resolvedFileName && !resolvedModule?.isExternalLibraryImport ? resolvedFileName : ''
30!
386
      })
42✔
387
      .filter((resolveFileName) => !!resolveFileName)
42✔
388
  }
42✔
389

6✔
390
  /**
6✔
391
   * @internal
6✔
392
   */
6✔
393
  private _resolveModuleName(
6✔
394
    moduleNameToResolve: string,
171,867✔
395
    containingFile: string,
171,867✔
396
  ): ResolvedModuleWithFailedLookupLocations {
171,867✔
397
    return this._ts.resolveModuleName(
171,867✔
398
      moduleNameToResolve,
171,867✔
399
      containingFile,
171,867✔
400
      this._compilerOptions,
171,867✔
401
      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
171,867✔
402
      this._moduleResolutionHost!,
171,867✔
403
      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
171,867✔
404
      this._moduleResolutionCache!,
171,867✔
405
    )
171,867✔
406
  }
171,867✔
407

6✔
408
  /**
6✔
409
   * @internal
6✔
410
   */
6✔
411
  private _isFileInCache(fileName: string): boolean {
6✔
412
    return (
76,065✔
413
      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
76,065✔
414
      this._fileContentCache!.has(fileName) &&
76,065✔
415
      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
8,280✔
416
      this._fileVersionCache!.has(fileName) &&
76,065✔
417
      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
8,274✔
418
      this._fileVersionCache!.get(fileName) !== 0
8,274✔
419
    )
76,065✔
420
  }
76,065✔
421

6✔
422
  /**
6✔
423
   * @internal
6✔
424
   */
6✔
425
  private _updateMemoryCache(contents: string, fileName: string, isModuleKindTheSame = true): void {
6✔
426
    this._logger.debug({ fileName }, 'updateMemoryCache: update memory cache for language service')
114✔
427

114✔
428
    let shouldIncrementProjectVersion = false
114✔
429
    const hit = this._isFileInCache(fileName)
114✔
430
    if (!hit) {
114✔
431
      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
30✔
432
      this._fileVersionCache!.set(fileName, 1)
30✔
433
      shouldIncrementProjectVersion = true
30✔
434
    } else {
114✔
435
      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
84✔
436
      const prevVersion = this._fileVersionCache!.get(fileName)!
84✔
437
      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
84✔
438
      const previousContents = this._fileContentCache!.get(fileName)
84✔
439
      // Avoid incrementing cache when nothing has changed.
84✔
440
      if (previousContents !== contents) {
84✔
441
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
66✔
442
        this._fileVersionCache!.set(fileName, prevVersion + 1)
66✔
443
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
66✔
444
        this._fileContentCache!.set(fileName, contents)
66✔
445
        shouldIncrementProjectVersion = true
66✔
446
      }
66✔
447
      /**
84✔
448
       * When a file is from node_modules or referenced to a referenced project and jest wants to transform it, we need
84✔
449
       * to make sure that the Program is updated with this information
84✔
450
       */
84✔
451
      if (!this._parsedTsConfig.fileNames.includes(fileName) || !isModuleKindTheSame) {
84✔
452
        shouldIncrementProjectVersion = true
54✔
453
      }
54✔
454
    }
84✔
455

114✔
456
    if (shouldIncrementProjectVersion) this._projectVersion++
114✔
457
  }
114✔
458

6✔
459
  /**
6✔
460
   * @internal
6✔
461
   */
6✔
462
  private getDiagnostics(fileName: string): Diagnostic[] {
6✔
463
    const diagnostics: Diagnostic[] = []
24✔
464
    if (this.configSet.shouldReportDiagnostics(fileName)) {
24✔
465
      this._logger.debug({ fileName }, '_doTypeChecking(): computing diagnostics using language service')
6✔
466

6✔
467
      // Get the relevant diagnostics - this is 3x faster than `getPreEmitDiagnostics`.
6✔
468
      diagnostics.push(
6✔
469
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
6✔
470
        ...this._languageService!.getSemanticDiagnostics(fileName),
6✔
471
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
6✔
472
        ...this._languageService!.getSyntacticDiagnostics(fileName),
6✔
473
      )
6✔
474
    }
6✔
475

24✔
476
    return diagnostics
24✔
477
  }
24✔
478
}
6✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc