44 createReadStream ,
55 createWriteStream ,
66 readFileSync ,
7- renameSync
7+ writeFileSync ,
8+ renameSync ,
9+ unlinkSync
810} from 'fs'
911import clearModule from 'clear-module'
1012import cache from '../lib/cache'
@@ -20,7 +22,7 @@ describe('load-typescript-config.js', () => {
2022 const tempPath = resolve ( __dirname , '../.renamed' )
2123 renameSync ( tsconfigPath , tempPath )
2224
23- const tsConfig = loadTypescriptConfig ( )
25+ const tsConfig = loadTypescriptConfig ( { } )
2426
2527 try {
2628 expect ( tsConfig ) . toEqual ( defaultConfig )
@@ -34,16 +36,34 @@ describe('load-typescript-config.js', () => {
3436 expect ( tsconfigCachedConfig ) . toEqual ( defaultConfig )
3537 } )
3638
39+ it ( 'returns the tsconfig specified in jest globals' , ( ) => {
40+ const jestGlobalTsConfigPath = resolve ( __dirname , '../tsconfig.jest.json' )
41+
42+ writeFileSync ( jestGlobalTsConfigPath , JSON . stringify ( {
43+ allowJs : false
44+ } ) )
45+
46+ const jestGlobalTsConfig = JSON . parse ( readFileSync ( jestGlobalTsConfigPath , { encoding : 'utf8' } ) )
47+
48+ const tsconfig = loadTypescriptConfig ( {
49+ tsConfigFile : jestGlobalTsConfigPath
50+ } )
51+
52+ expect ( tsconfig ) . toEqual ( jestGlobalTsConfig )
53+
54+ unlinkSync ( jestGlobalTsConfigPath )
55+ } )
56+
3757 it ( 'reads default tsconfig if there is tsconfig.json' , ( ) => {
3858 const tsconfigPath = resolve ( __dirname , '../tsconfig.json' )
3959 const tsconfigCopiedPath = resolve ( __dirname , '../.tsconfig.json_cp' )
4060 createReadStream ( tsconfigPath ) . pipe ( createWriteStream ( tsconfigCopiedPath ) )
4161 const tsconfigOriginal = JSON . parse ( readFileSync ( tsconfigPath , { encoding : 'utf8' } ) )
42- const tsconfig = loadTypescriptConfig ( )
62+ const tsconfig = loadTypescriptConfig ( { } )
4363 expect ( tsconfig ) . toEqual ( tsconfigOriginal )
4464 const tempPath = resolve ( __dirname , '../.renamed' )
4565 renameSync ( tsconfigCopiedPath , tempPath )
46- const tsconfigCached = loadTypescriptConfig ( )
66+ const tsconfigCached = loadTypescriptConfig ( { } )
4767 try {
4868 expect ( tsconfig ) . not . toBe ( tsconfigCached )
4969 expect ( tsconfig ) . toEqual ( tsconfigCached )
0 commit comments