4
4
createReadStream ,
5
5
createWriteStream ,
6
6
readFileSync ,
7
- renameSync
7
+ renameSync ,
8
+ writeFileSync ,
9
+ unlinkSync
8
10
} from 'fs'
9
11
import clearModule from 'clear-module'
10
12
import cache from '../lib/cache'
@@ -19,7 +21,7 @@ describe('load-babel-config.js', () => {
19
21
const babelRcPath = resolve ( __dirname , '../.babelrc' )
20
22
const tempPath = resolve ( __dirname , '../.renamed' )
21
23
renameSync ( babelRcPath , tempPath )
22
- const babelConfig = loadBabelConfig ( )
24
+ const babelConfig = loadBabelConfig ( { } )
23
25
try {
24
26
expect ( babelConfig ) . toBe ( undefined )
25
27
} catch ( err ) {
@@ -31,12 +33,25 @@ describe('load-babel-config.js', () => {
31
33
expect ( babelConfigCached ) . toBe ( undefined )
32
34
} )
33
35
36
+ it ( 'reads babelrc from jest globals if exists' , ( ) => {
37
+ const jestGlobalBabelPath = resolve ( __dirname , '../jest.babelrc' )
38
+ writeFileSync ( jestGlobalBabelPath , JSON . stringify ( {
39
+ plugins : [ 'foo' ]
40
+ } ) )
41
+ const jestGlobalBabelConfig = JSON . parse ( readFileSync ( jestGlobalBabelPath , { encoding : 'utf8' } ) )
42
+ const babelConfig = loadBabelConfig ( {
43
+ babelRcFile : 'jest.babelrc'
44
+ } )
45
+ expect ( babelConfig ) . toEqual ( jestGlobalBabelConfig )
46
+ unlinkSync ( jestGlobalBabelPath )
47
+ } )
48
+
34
49
it ( 'reads default babel if there is .babelrc' , ( ) => {
35
50
const babelRcPath = resolve ( __dirname , '../.babelrc' )
36
51
const babelRcCopiedPath = resolve ( __dirname , '../.babelrc_cp' )
37
52
createReadStream ( babelRcPath ) . pipe ( createWriteStream ( babelRcCopiedPath ) )
38
53
const babelRcOriginal = JSON . parse ( readFileSync ( babelRcPath , { encoding : 'utf8' } ) )
39
- const babelConfig = loadBabelConfig ( )
54
+ const babelConfig = loadBabelConfig ( { } )
40
55
expect ( babelConfig ) . toEqual ( babelRcOriginal )
41
56
const tempPath = resolve ( __dirname , '../.renamed' )
42
57
renameSync ( babelRcCopiedPath , tempPath )
0 commit comments