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

kulshekhar / ts-jest / 3863036863

pending completion
3863036863

push

github

GitHub
build(deps): bump json5 from 2.2.1 to 2.2.3 in /e2e/transform-js (#3943)

937 of 1054 branches covered (88.9%)

Branch coverage included in aggregate %.

4055 of 4154 relevant lines covered (97.62%)

514.86 hits per line

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

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

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

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

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

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

3✔
82
  program: Program | undefined
3✔
83

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

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

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

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

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

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

12✔
146
    return importedModulePaths
12✔
147
  }
12✔
148

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

36✔
180
      // Must set memory cache before attempting to compile
36✔
181
      this._updateMemoryCache(fileContent, fileName, currentModuleKind === moduleKind)
36✔
182
      const output: EmitOutput = this._languageService.getEmitOutput(fileName)
36✔
183
      const diagnostics = this.getDiagnostics(fileName)
36✔
184
      if (!isEsmMode && diagnostics.length) {
36✔
185
        this.configSet.raiseDiagnostics(diagnostics, fileName, this._logger)
3✔
186
        if (options.watchMode) {
3!
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
      }
3✔
211
      if (output.emitSkipped) {
36✔
212
        if (TS_TSX_REGEX.test(fileName)) {
9✔
213
          throw new Error(interpolate(Errors.CannotProcessFile, { file: fileName }))
6✔
214
        } else {
9✔
215
          this._logger.warn(interpolate(Errors.CannotProcessFileReturnOriginal, { file: fileName }))
3✔
216

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

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

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

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

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

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

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

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

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

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

27,122✔
330
        if (contents === undefined) return
27,122!
331

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

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

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

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

9✔
370
    return resolvedFileContent
9✔
371
  }
9✔
372

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

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

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

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

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

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

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

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

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

12✔
476
    return diagnostics
12✔
477
  }
12✔
478
}
3✔
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