4
4
createReadStream ,
5
5
createWriteStream ,
6
6
readFileSync ,
7
- renameSync
7
+ writeFileSync ,
8
+ renameSync ,
9
+ unlinkSync
8
10
} from 'fs'
9
11
import clearModule from 'clear-module'
10
12
import cache from '../lib/cache'
@@ -20,7 +22,7 @@ describe('load-typescript-config.js', () => {
20
22
const tempPath = resolve ( __dirname , '../.renamed' )
21
23
renameSync ( tsconfigPath , tempPath )
22
24
23
- const tsConfig = loadTypescriptConfig ( )
25
+ const tsConfig = loadTypescriptConfig ( { } )
24
26
25
27
try {
26
28
expect ( tsConfig ) . toEqual ( defaultConfig )
@@ -34,16 +36,34 @@ describe('load-typescript-config.js', () => {
34
36
expect ( tsconfigCachedConfig ) . toEqual ( defaultConfig )
35
37
} )
36
38
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
+
37
57
it ( 'reads default tsconfig if there is tsconfig.json' , ( ) => {
38
58
const tsconfigPath = resolve ( __dirname , '../tsconfig.json' )
39
59
const tsconfigCopiedPath = resolve ( __dirname , '../.tsconfig.json_cp' )
40
60
createReadStream ( tsconfigPath ) . pipe ( createWriteStream ( tsconfigCopiedPath ) )
41
61
const tsconfigOriginal = JSON . parse ( readFileSync ( tsconfigPath , { encoding : 'utf8' } ) )
42
- const tsconfig = loadTypescriptConfig ( )
62
+ const tsconfig = loadTypescriptConfig ( { } )
43
63
expect ( tsconfig ) . toEqual ( tsconfigOriginal )
44
64
const tempPath = resolve ( __dirname , '../.renamed' )
45
65
renameSync ( tsconfigCopiedPath , tempPath )
46
- const tsconfigCached = loadTypescriptConfig ( )
66
+ const tsconfigCached = loadTypescriptConfig ( { } )
47
67
try {
48
68
expect ( tsconfig ) . not . toBe ( tsconfigCached )
49
69
expect ( tsconfig ) . toEqual ( tsconfigCached )
0 commit comments