/
ts-compiler.spec.ts
669 lines (603 loc) · 25.3 KB
/
ts-compiler.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
import { readFileSync } from 'fs'
import { basename, join, normalize } from 'path'
import { DiagnosticCategory, EmitOutput, ModuleKind, ScriptTarget, TranspileOutput } from 'typescript'
import { makeCompiler } from '../__helpers__/fakers'
import { mockFolder } from '../__helpers__/path'
import type { DepGraphInfo } from '../types'
import { Errors, interpolate } from '../utils/messages'
import { updateOutput } from './compiler-utils'
const baseTsJestConfig = { tsconfig: join(process.cwd(), 'tsconfig.spec.json') }
describe('TsCompiler', () => {
describe('getResolvedModules', () => {
const fileName = join(mockFolder, 'thing.ts')
test('should return undefined when file name is not known to compiler', () => {
const compiler = makeCompiler({
tsJestConfig: baseTsJestConfig,
})
expect(compiler.getResolvedModules('const foo = 1', fileName, new Map())).toEqual([])
})
test('should return undefined when it is isolatedModules true', () => {
const compiler = makeCompiler({
tsJestConfig: {
...baseTsJestConfig,
isolatedModules: true,
},
})
expect(compiler.getResolvedModules('const foo = 1', fileName, new Map())).toEqual([])
})
test('should return undefined when file has no resolved modules', () => {
const jestCacheFS = new Map<string, string>()
jestCacheFS.set(fileName, 'const foo = 1')
const compiler = makeCompiler(
{
tsJestConfig: baseTsJestConfig,
},
jestCacheFS,
)
expect(compiler.getResolvedModules('const foo = 1', fileName, new Map())).toEqual([])
})
test('should return resolved modules when file has resolved modules', () => {
const jestCacheFS = new Map<string, string>()
const importedModule1 = join(mockFolder, 'thing1.ts')
const importedModule2 = join(mockFolder, 'thing2.ts')
const importedModule3 = join(mockFolder, 'babel-foo.config.js')
const fileContentWithModules = readFileSync(fileName, 'utf-8')
jestCacheFS.set(importedModule1, readFileSync(importedModule1, 'utf-8'))
const compiler = makeCompiler(
{
tsJestConfig: baseTsJestConfig,
},
jestCacheFS,
)
expect(
compiler
.getResolvedModules(fileContentWithModules, fileName, new Map())
.map((resolvedFileName) => normalize(resolvedFileName)),
).toEqual([importedModule3, importedModule1, importedModule2])
})
})
describe('getCompiledOutput', () => {
describe('isolatedModules true', () => {
const fileName = join(mockFolder, 'thing.ts')
const fileContent = 'const bar = 1'
test.each([true, false])('should transpile code with useESM %p', (useESM) => {
const compiler = makeCompiler({
tsJestConfig: { ...baseTsJestConfig, isolatedModules: true, useESM },
})
const transformersStub = {
before: [],
after: [],
afterDeclarations: [],
}
// @ts-expect-error testing purpose
compiler._ts.transpileModule = jest.fn().mockReturnValueOnce({
sourceMapText: '{}',
outputText: 'var bar = 1',
diagnostics: [],
} as TranspileOutput)
// @ts-expect-error testing purpose
compiler._makeTransformers = jest.fn().mockReturnValueOnce(transformersStub)
compiler.getCompiledOutput(fileContent, fileName, {
depGraphs: new Map(),
supportsStaticESM: true,
watchMode: false,
})
// @ts-expect-error testing purpose
const compilerOptions = compiler._compilerOptions
// @ts-expect-error testing purpose
expect(compiler._ts.transpileModule).toHaveBeenCalledWith(fileContent, {
fileName,
compilerOptions: {
...compilerOptions,
module: useESM ? ModuleKind.ESNext : ModuleKind.CommonJS,
target: useESM ? ScriptTarget.ES2015 : compilerOptions.target,
esModuleInterop: useESM ? true : compilerOptions.esModuleInterop,
allowSyntheticDefaultImports: useESM ? true : compilerOptions.allowSyntheticDefaultImports,
},
transformers: transformersStub,
reportDiagnostics: compiler.configSet.shouldReportDiagnostics(fileName),
})
})
test.each([true, false])('should report diagnostics if shouldReportDiagnostics is %p', (shouldReport) => {
const compiler = makeCompiler({
tsJestConfig: { ...baseTsJestConfig, isolatedModules: true, useESM: false },
})
compiler.configSet.raiseDiagnostics = jest.fn()
compiler.configSet.shouldReportDiagnostics = jest.fn().mockReturnValue(shouldReport)
const compileOutput: TranspileOutput = {
sourceMapText: '{}',
outputText: 'var bar = 1',
diagnostics: [
{
category: DiagnosticCategory.Error,
code: 123,
messageText: 'An error occurs',
file: undefined,
start: 0,
length: 1,
},
],
}
// @ts-expect-error testing purpose
compiler._ts.transpileModule = jest.fn().mockReturnValueOnce(compileOutput)
compiler.getCompiledOutput(fileContent, fileName, {
depGraphs: new Map(),
supportsStaticESM: true,
watchMode: false,
})
if (shouldReport) {
expect(compiler.configSet.raiseDiagnostics).toHaveBeenCalledWith(
compileOutput.diagnostics,
fileName,
// @ts-expect-error testing purpose
compiler._logger,
)
} else {
expect(compiler.configSet.raiseDiagnostics).not.toHaveBeenCalled()
}
})
})
describe('isolatedModules false', () => {
const fileName = join(mockFolder, 'thing.ts')
const fileContent = 'const bar = 1'
const jsOutput = 'var bar = 1'
const sourceMap = '{}'
test.each([true, false])('should compile codes with useESM %p', (useESM) => {
const compiler = makeCompiler({
tsJestConfig: { ...baseTsJestConfig, useESM },
})
// @ts-expect-error testing purpose
compiler._languageService.getEmitOutput = jest.fn().mockReturnValueOnce({
outputFiles: [{ text: sourceMap }, { text: jsOutput }],
emitSkipped: false,
} as EmitOutput)
// @ts-expect-error testing purpose
compiler._doTypeChecking = jest.fn()
const output = compiler.getCompiledOutput(fileContent, fileName, {
depGraphs: new Map(),
supportsStaticESM: true,
watchMode: false,
})
// @ts-expect-error testing purpose
const compileTarget = compiler._compilerOptions.target
// @ts-expect-error testing purpose
const moduleKind = compiler._compilerOptions.module
// @ts-expect-error testing purpose
const esModuleInterop = compiler._compilerOptions.esModuleInterop
// @ts-expect-error testing purpose
const allowSyntheticDefaultImports = compiler._compilerOptions.allowSyntheticDefaultImports
expect(compileTarget).toEqual(useESM ? ScriptTarget.ES2015 : compileTarget)
expect(moduleKind).toEqual(useESM ? ModuleKind.ESNext : moduleKind)
expect(esModuleInterop).toEqual(useESM ? true : esModuleInterop)
expect(allowSyntheticDefaultImports).toEqual(useESM ? true : allowSyntheticDefaultImports)
expect(output).toEqual(updateOutput(jsOutput, fileName, sourceMap))
})
test('should show a warning message and return original file content for non ts/tsx files if emitSkipped is true', () => {
const compiler = makeCompiler({
tsJestConfig: { ...baseTsJestConfig },
})
// @ts-expect-error testing purpose
compiler._languageService.getEmitOutput = jest.fn().mockReturnValueOnce({
outputFiles: [{ text: sourceMap }, { text: jsOutput }],
emitSkipped: true,
} as EmitOutput)
// @ts-expect-error testing purpose
compiler._logger.warn = jest.fn()
// @ts-expect-error testing purpose
compiler._doTypeChecking = jest.fn()
const fileToCheck = fileName.replace('.ts', '.js')
const output = compiler.getCompiledOutput(fileContent, fileToCheck, {
depGraphs: new Map(),
supportsStaticESM: false,
watchMode: false,
})
// @ts-expect-error testing purpose
expect(compiler._logger.warn).toHaveBeenCalled()
expect(output).toEqual(updateOutput(fileContent, fileToCheck, undefined))
})
test.each([fileName, fileName.replace('.ts', '.tsx')])(
'should throw error for ts/tsx files if emitSkipped is true',
(fileToCheck) => {
const compiler = makeCompiler({
tsJestConfig: { ...baseTsJestConfig },
})
// @ts-expect-error testing purpose
compiler._languageService.getEmitOutput = jest.fn().mockReturnValueOnce({
outputFiles: [{ text: sourceMap }, { text: jsOutput }],
emitSkipped: true,
} as EmitOutput)
// @ts-expect-error testing purpose
compiler._logger.warn = jest.fn()
// @ts-expect-error testing purpose
compiler._doTypeChecking = jest.fn()
// @ts-expect-error testing purpose
expect(compiler._logger.warn).not.toHaveBeenCalled()
expect(() =>
compiler.getCompiledOutput(fileContent, fileToCheck, {
depGraphs: new Map(),
supportsStaticESM: false,
watchMode: false,
}),
).toThrowError()
},
)
test('should throw error when there are no outputFiles', () => {
const compiler = makeCompiler({
tsJestConfig: { ...baseTsJestConfig },
})
// @ts-expect-error testing purpose
compiler._languageService.getEmitOutput = jest.fn().mockReturnValueOnce({
outputFiles: [],
emitSkipped: false,
} as EmitOutput)
// @ts-expect-error testing purpose
compiler._doTypeChecking = jest.fn()
expect(() =>
compiler.getCompiledOutput(fileContent, fileName, {
depGraphs: new Map(),
supportsStaticESM: false,
watchMode: false,
}),
).toThrowError(
new TypeError(
interpolate(Errors.UnableToRequireDefinitionFile, {
file: basename(fileName),
}),
),
)
})
})
})
describe('_makeTransformers', () => {
test('should return the transformers object which contains before, after and afterDeclarations transformers', () => {
const compiler = makeCompiler({
tsJestConfig: { ...baseTsJestConfig, isolatedModules: true, useESM: false },
})
const transformerStub = join(mockFolder, 'dummy-transformer.js')
console.log = jest.fn()
// @ts-expect-error testing purpose
const transformers = compiler._makeTransformers({
before: [
{
name: 'dummy-transformer',
version: 1,
factory: require(transformerStub).factory,
},
],
after: [
{
name: 'dummy-transformer',
version: 1,
factory: require(transformerStub).factory,
},
],
afterDeclarations: [
{
name: 'dummy-transformer',
version: 1,
factory: require(transformerStub).factory,
},
],
})
expect(transformers.before?.length).toEqual(1)
expect(transformers.after?.length).toEqual(1)
expect(transformers.afterDeclarations?.length).toEqual(1)
})
})
describe('_updateMemoryCache', () => {
const fileName = join(mockFolder, 'thing.ts')
const fileContent = 'const bar = 1'
const compiler = makeCompiler({
tsJestConfig: { ...baseTsJestConfig, isolatedModules: true },
})
const fileContentCache = new Map<string, string>()
const fileVersionCache = new Map<string, number>()
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()
})
test('should increase project version if processing file is not in _fileContentCache', () => {
// @ts-expect-error testing purpose
compiler._fileContentCache = fileContentCache
// @ts-expect-error testing purpose
compiler._fileVersionCache = fileVersionCache
// @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 is not in _fileVersionCache', () => {
fileContentCache.set(fileName, fileContent)
// @ts-expect-error testing purpose
compiler._fileContentCache = fileContentCache
// @ts-expect-error testing purpose
compiler._fileVersionCache = fileVersionCache
// @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 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)
// @ts-expect-error testing purpose
compiler._fileContentCache = fileContentCache
// @ts-expect-error testing purpose
compiler._fileVersionCache = fileVersionCache
// @ts-expect-error testing purpose
compiler._updateMemoryCache(fileContent, fileName)
// @ts-expect-error testing purpose
expect(compiler._projectVersion).toEqual(2)
})
test(
'should increase file version in _fileVersionCache as well as ' +
'update file content in _fileContentCache for processing file if previous ' +
'content is not the same as new content and increase project version',
() => {
const newContent = 'const foo = 1'
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._updateMemoryCache(newContent, fileName)
// @ts-expect-error testing purpose
expect(compiler._fileVersionCache.get(fileName)).toEqual(2)
// @ts-expect-error testing purpose
expect(compiler._fileContentCache.get(fileName)).toEqual(newContent)
// @ts-expect-error testing purpose
expect(compiler._projectVersion).toEqual(2)
},
)
test(
'should only increase project version if the previous content is the ' +
'same as current content and the processing file is not in the list of compiler file names',
() => {
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._parsedTsConfig.fileNames = []
// @ts-expect-error testing purpose
compiler._updateMemoryCache(fileContent, fileName)
// @ts-expect-error testing purpose
expect(compiler._fileVersionCache.get(fileName)).toEqual(1)
// @ts-expect-error testing purpose
expect(compiler._fileContentCache.get(fileName)).toEqual(fileContent)
// @ts-expect-error testing purpose
expect(compiler._projectVersion).toEqual(2)
},
)
test(
'should not increase project version if the previous content is ' +
'the same as current content and the processing file is in the list of compiler file names',
() => {
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._parsedTsConfig.fileNames = [fileName]
// @ts-expect-error testing purpose
compiler._updateMemoryCache(fileContent, fileName)
// @ts-expect-error testing purpose
expect(compiler._fileVersionCache.get(fileName)).toEqual(1)
// @ts-expect-error testing purpose
expect(compiler._fileContentCache.get(fileName)).toEqual(fileContent)
// @ts-expect-error testing purpose
expect(compiler._projectVersion).toEqual(1)
},
)
})
describe('_doTypeChecking', () => {
const fileName = join(mockFolder, 'thing.ts')
const fileName1 = join(mockFolder, 'thing1.ts')
const fileContent = 'const bar = 1'
const jsOutput = 'var bar = 1'
const sourceMap = '{}'
test.each([true, false])(
'should/should not report diagnostics if shouldReportDiagnostics is %p in non-watch mode',
(shouldReport) => {
const compiler = makeCompiler({
tsJestConfig: baseTsJestConfig,
})
compiler.configSet.raiseDiagnostics = jest.fn()
compiler.configSet.shouldReportDiagnostics = jest.fn().mockReturnValue(shouldReport)
// @ts-expect-error testing purpose
compiler._languageService.getEmitOutput = jest.fn().mockReturnValueOnce({
outputFiles: [{ text: sourceMap }, { text: jsOutput }],
emitSkipped: false,
} as EmitOutput)
const diagnostics = [
{
category: DiagnosticCategory.Error,
code: 123,
messageText: 'An error occurs',
file: undefined,
start: 0,
length: 1,
},
{
category: DiagnosticCategory.Error,
code: 456,
messageText: 'An error occurs',
file: undefined,
start: 0,
length: 1,
},
]
// @ts-expect-error testing purpose
compiler._languageService?.getSemanticDiagnostics = jest.fn().mockReturnValueOnce([diagnostics[0]])
// @ts-expect-error testing purpose
compiler._languageService?.getSyntacticDiagnostics = jest.fn().mockReturnValueOnce([diagnostics[1]])
compiler.getCompiledOutput(fileContent, fileName, {
depGraphs: new Map(),
supportsStaticESM: false,
watchMode: false,
})
if (shouldReport) {
// @ts-expect-error testing purpose
expect(compiler._languageService?.getSemanticDiagnostics).toHaveBeenCalledWith(fileName)
// @ts-expect-error testing purpose
expect(compiler._languageService?.getSyntacticDiagnostics).toHaveBeenCalledWith(fileName)
expect(compiler.configSet.raiseDiagnostics).toHaveBeenCalledWith(
diagnostics,
fileName,
// @ts-expect-error testing purpose
compiler._logger,
)
} else {
// @ts-expect-error testing purpose
expect(compiler._languageService?.getSemanticDiagnostics).not.toHaveBeenCalled()
// @ts-expect-error testing purpose
expect(compiler._languageService?.getSyntacticDiagnostics).not.toHaveBeenCalled()
expect(compiler.configSet.raiseDiagnostics).not.toHaveBeenCalled()
}
},
)
test.each([true, false])(
'should/should not report diagnostics in watch mode when shouldReportDiagnostics is %p ' +
'and processing file is used by other files',
(shouldReport) => {
const compiler = makeCompiler({
tsJestConfig: { ...baseTsJestConfig, useESM: false },
})
const depGraphs = new Map<string, DepGraphInfo>()
depGraphs.set(fileName1, {
fileContent,
resolvedModuleNames: [fileName],
})
const diagnostics = [
{
category: DiagnosticCategory.Error,
code: 123,
messageText: 'An error occurs',
file: undefined,
start: 0,
length: 1,
},
{
category: DiagnosticCategory.Error,
code: 456,
messageText: 'An error occurs',
file: undefined,
start: 0,
length: 1,
},
]
compiler.configSet.raiseDiagnostics = jest.fn()
compiler.configSet.shouldReportDiagnostics = jest.fn().mockImplementation((fileToCheck) => {
return fileToCheck === fileName1 ? shouldReport : false
})
// @ts-expect-error testing purpose
compiler._languageService.getEmitOutput = jest.fn().mockReturnValueOnce({
outputFiles: [{ text: sourceMap }, { text: jsOutput }],
emitSkipped: false,
} as EmitOutput)
// @ts-expect-error testing purpose
compiler._getFileContentFromCache = jest.fn()
// @ts-expect-error testing purpose
compiler._languageService?.getSemanticDiagnostics = jest.fn().mockImplementation((fileToGet) => {
return fileToGet === fileName ? [] : [diagnostics[0]]
})
// @ts-expect-error testing purpose
compiler._languageService?.getSyntacticDiagnostics = jest.fn().mockImplementation((fileToGet) => {
return fileToGet === fileName ? [] : [diagnostics[1]]
})
compiler.getCompiledOutput(fileContent, fileName, {
depGraphs,
supportsStaticESM: false,
watchMode: true,
})
if (shouldReport) {
// @ts-expect-error testing purpose
expect(compiler._languageService?.getSemanticDiagnostics).toHaveBeenCalledWith(fileName1)
// @ts-expect-error testing purpose
expect(compiler._languageService?.getSyntacticDiagnostics).toHaveBeenCalledWith(fileName1)
expect(compiler.configSet.raiseDiagnostics).toHaveBeenCalledWith(
diagnostics,
fileName,
// @ts-expect-error testing purpose
compiler._logger,
)
} else {
// @ts-expect-error testing purpose
expect(compiler._languageService?.getSemanticDiagnostics).not.toHaveBeenCalled()
// @ts-expect-error testing purpose
expect(compiler._languageService?.getSyntacticDiagnostics).not.toHaveBeenCalled()
expect(compiler.configSet.raiseDiagnostics).not.toHaveBeenCalled()
}
},
)
test('should not report diagnostics in watch mode when processing file is not used by other files', () => {
const compiler = makeCompiler({
tsJestConfig: baseTsJestConfig,
})
const depGraphs = new Map<string, DepGraphInfo>()
depGraphs.set(fileName1, {
fileContent,
resolvedModuleNames: ['bar.ts'],
})
compiler.configSet.raiseDiagnostics = jest.fn()
compiler.configSet.shouldReportDiagnostics = jest.fn().mockReturnValue(false)
// @ts-expect-error testing purpose
compiler._languageService.getEmitOutput = jest.fn().mockReturnValueOnce({
outputFiles: [{ text: sourceMap }, { text: jsOutput }],
emitSkipped: false,
} as EmitOutput)
// @ts-expect-error testing purpose
compiler._getFileContentFromCache = jest.fn()
// @ts-expect-error testing purpose
compiler._languageService?.getSemanticDiagnostics = jest.fn().mockReturnValueOnce([])
// @ts-expect-error testing purpose
compiler._languageService?.getSyntacticDiagnostics = jest.fn().mockReturnValueOnce([])
compiler.getCompiledOutput(fileContent, fileName, {
depGraphs,
supportsStaticESM: false,
watchMode: true,
})
// @ts-expect-error testing purpose
expect(compiler._languageService?.getSemanticDiagnostics).not.toHaveBeenCalled()
// @ts-expect-error testing purpose
expect(compiler._languageService?.getSyntacticDiagnostics).not.toHaveBeenCalled()
expect(compiler.configSet.raiseDiagnostics).not.toHaveBeenCalled()
})
})
})