@@ -9,36 +9,28 @@ let babel: typeof __types__babel;
99let istanbulPlugin : typeof __types__istanbulPlugin ;
1010let jestPreset : typeof __types__jestPreset ;
1111function importBabelDeps ( ) {
12- if ( babel ) {
13- return ;
14- }
15- babel = require ( '@babel/core' ) ;
16- istanbulPlugin = require ( 'babel-plugin-istanbul' ) . default ;
17- jestPreset = require ( 'babel-preset-jest' ) ;
12+ if ( babel ) return ; // tslint:ignore-line
13+ // ensure we use the require from jest
14+ babel = require . main . require ( '@babel/core' ) ;
15+ istanbulPlugin = require . main . require ( 'babel-plugin-istanbul' ) . default ;
16+ jestPreset = require . main . require ( 'babel-preset-jest' ) ;
1817}
19- import { CompilerOptions } from 'typescript' ;
2018import {
2119 BabelTransformOptions ,
2220 PostProcessHook ,
2321 JestCacheKeyOptions ,
24- TsJestConfig ,
2522} from './types' ;
2623import { logOnce } from './utils/logger' ;
24+ import getTSJestConfig from './utils/get-ts-jest-config' ;
2725
2826// Function that takes the transpiled typescript and runs it through babel/whatever.
2927export function postProcessCode (
30- compilerOptions : CompilerOptions ,
3128 jestConfig : jest . ProjectConfig ,
32- tsJestConfig : TsJestConfig ,
3329 transformOptions : jest . TransformOptions ,
3430 transpileOutput : jest . TransformedSource ,
3531 filePath : string ,
3632) : jest . TransformedSource {
37- const postHook = getPostProcessHook (
38- compilerOptions ,
39- jestConfig ,
40- tsJestConfig ,
41- ) ;
33+ const postHook = getPostProcessHook ( jestConfig ) ;
4234
4335 return postHook ( transpileOutput , filePath , jestConfig , transformOptions ) ;
4436}
@@ -89,29 +81,29 @@ function createBabelTransformer(
8981}
9082
9183export const getPostProcessHook = (
92- tsCompilerOptions : CompilerOptions ,
9384 jestConfig : jest . ProjectConfig ,
94- tsJestConfig : TsJestConfig ,
9585) : PostProcessHook => {
86+ const tsJestConfig = getTSJestConfig ( jestConfig ) ;
9687 if ( tsJestConfig . skipBabel ) {
9788 logOnce ( 'Not using any postprocess hook.' ) ;
9889 // Identity function
9990 return input => input ;
10091 }
10192
102- const plugins = Array . from (
103- ( tsJestConfig . babelConfig && tsJestConfig . babelConfig . plugins ) || [ ] ,
104- ) ;
105-
93+ const tsJestBabelConfig = tsJestConfig . babelConfig || { } ;
10694 const babelOptions : BabelTransformOptions = {
107- ...tsJestConfig . babelConfig ,
95+ ...tsJestBabelConfig ,
10896 babelrc : tsJestConfig . useBabelrc || false ,
109- plugins,
110- presets : tsJestConfig . babelConfig ? tsJestConfig . babelConfig . presets : [ ] ,
111- sourceMaps : tsJestConfig . disableSourceMapSupport !== true ,
97+ plugins : toArray ( tsJestBabelConfig . plugins ) ,
98+ presets : toArray ( tsJestBabelConfig . presets ) ,
99+ sourceMaps : ! tsJestConfig . disableSourceMapSupport ,
112100 } ;
113101
114102 logOnce ( 'Using babel with options:' , babelOptions ) ;
115103
116104 return createBabelTransformer ( babelOptions ) ;
117105} ;
106+
107+ function toArray < T > ( iter ?: Iterable < T > | null ) : Array < T > {
108+ return iter ? Array . from ( iter ) : [ ] ;
109+ }
0 commit comments