11import { readFileSync } from 'fs'
22import { basename , join , normalize } from 'path'
33
4- import {
5- type CompilerOptions ,
6- DiagnosticCategory ,
7- type EmitOutput ,
8- type transpileModule ,
9- type TranspileOutput ,
10- } from 'typescript'
4+ import type { CompilerOptions , EmitOutput , transpileModule , TranspileOutput } from 'typescript'
5+ import * as ts from 'typescript'
116
127import { createConfigSet , makeCompiler } from '../../__helpers__/fakers'
138import type { DepGraphInfo } from '../../types'
@@ -16,6 +11,15 @@ import { Errors, interpolate } from '../../utils/messages'
1611import { updateOutput } from './compiler-utils'
1712import { TsCompiler } from './ts-compiler'
1813
14+ jest . mock ( 'typescript' , ( ) => {
15+ const actualModule = jest . requireActual ( 'typescript' ) as typeof ts
16+
17+ return {
18+ __esModule : true ,
19+ ...actualModule ,
20+ }
21+ } )
22+
1923const mockFolder = join ( process . cwd ( ) , 'src' , '__mocks__' )
2024
2125const baseTsJestConfig = { tsconfig : join ( process . cwd ( ) , 'tsconfig.spec.json' ) }
@@ -147,7 +151,7 @@ describe('TsCompiler', () => {
147151 outputText : 'var bar = 1' ,
148152 diagnostics : [
149153 {
150- category : DiagnosticCategory . Error ,
154+ category : ts . DiagnosticCategory . Error ,
151155 code : 123 ,
152156 messageText : 'An error occurs' ,
153157 file : undefined ,
@@ -550,15 +554,15 @@ describe('TsCompiler', () => {
550554 } as EmitOutput )
551555 const diagnostics = [
552556 {
553- category : DiagnosticCategory . Error ,
557+ category : ts . DiagnosticCategory . Error ,
554558 code : 123 ,
555559 messageText : 'An error occurs' ,
556560 file : undefined ,
557561 start : 0 ,
558562 length : 1 ,
559563 } ,
560564 {
561- category : DiagnosticCategory . Error ,
565+ category : ts . DiagnosticCategory . Error ,
562566 code : 456 ,
563567 messageText : 'An error occurs' ,
564568 file : undefined ,
@@ -611,15 +615,15 @@ describe('TsCompiler', () => {
611615 } )
612616 const diagnostics = [
613617 {
614- category : DiagnosticCategory . Error ,
618+ category : ts . DiagnosticCategory . Error ,
615619 code : 123 ,
616620 messageText : 'An error occurs' ,
617621 file : undefined ,
618622 start : 0 ,
619623 length : 1 ,
620624 } ,
621625 {
622- category : DiagnosticCategory . Error ,
626+ category : ts . DiagnosticCategory . Error ,
623627 code : 456 ,
624628 messageText : 'An error occurs' ,
625629 file : undefined ,
0 commit comments