11import { readFileSync } from 'fs'
22import { join , normalize } from 'path'
33
4- import { makeCompiler } from '../__helpers__/fakers'
4+ import { createConfigSet , makeCompiler } from '../__helpers__/fakers'
55import { logTargetMock } from '../__helpers__/mocks'
66import { mockFolder } from '../__helpers__/path'
77import ProcessedSource from '../__helpers__/processed-source'
88
9+ import { TsCompiler } from './ts-compiler'
10+
911const logTarget = logTargetMock ( )
1012
1113describe ( 'TsCompiler' , ( ) => {
@@ -236,6 +238,20 @@ const t: string = f(5)
236238 expect ( compiler . _initialCompilerOptions . allowSyntheticDefaultImports ) . not . toEqual ( true )
237239 } )
238240
241+ test ( 'should compile ts file which has an existing js file' , ( ) => {
242+ const configSet = createConfigSet ( {
243+ tsJestConfig : baseTsJestConfig ,
244+ } )
245+ const fileName = join ( mockFolder , 'thing.ts' )
246+ const fileContent = readFileSync ( fileName , 'utf-8' )
247+ configSet . parsedTsConfig . fileNames . push ( ...[ fileName . replace ( '.ts' , '.js' ) , fileName ] )
248+ const compiler = new TsCompiler ( configSet , new Map ( ) )
249+
250+ const compiledOutput = compiler . getCompiledOutput ( fileContent , fileName , false )
251+
252+ expect ( new ProcessedSource ( compiledOutput , fileName ) . outputCodeWithoutMaps ) . toMatchSnapshot ( )
253+ } )
254+
239255 describe ( 'allowJs option' , ( ) => {
240256 const fileName = 'test-allow-js.js'
241257 const source = 'export default 42'
@@ -407,6 +423,7 @@ const t: string = f(5)
407423 const jestCacheFS = new Map < string , string > ( )
408424 const importedModule1 = join ( mockFolder , 'thing1.ts' )
409425 const importedModule2 = join ( mockFolder , 'thing2.ts' )
426+ const importedModule3 = join ( mockFolder , 'babel-foo.config.js' )
410427 const fileContentWithModules = readFileSync ( fileName , 'utf-8' )
411428 jestCacheFS . set ( importedModule1 , readFileSync ( importedModule1 , 'utf-8' ) )
412429 const compiler = makeCompiler (
@@ -420,7 +437,7 @@ const t: string = f(5)
420437 compiler
421438 . getResolvedModules ( fileContentWithModules , fileName , new Map ( ) )
422439 . map ( ( resolvedFileName ) => normalize ( resolvedFileName ) ) ,
423- ) . toEqual ( [ importedModule1 , importedModule2 ] )
440+ ) . toEqual ( [ importedModule3 , importedModule1 , importedModule2 ] )
424441 } )
425442 } )
426443
0 commit comments