|
2 | 2 | * Postprocess step. Based on babel-jest: https://github.com/facebook/jest/blob/master/packages/babel-jest/src/index.js |
3 | 3 | * https://github.com/facebook/jest/blob/9b157c3a7c325c3971b2aabbe4c8ab4ce0b0c56d/packages/babel-jest/src/index.js |
4 | 4 | */ |
5 | | -import * as __types__babel from 'babel-core'; |
6 | | -import __types__istanbulPlugin from 'babel-plugin-istanbul'; |
7 | | -import * as __types__jestPreset from 'babel-preset-jest'; |
8 | 5 | import { |
9 | 6 | BabelTransformOptions, |
10 | 7 | PostProcessHook, |
11 | | - JestCacheKeyOptions, |
| 8 | + TBabel, |
| 9 | + TBabelPluginIstanbul, |
| 10 | + TBabelPresetJest, |
12 | 11 | } from './types'; |
13 | 12 | import { logOnce } from './utils/logger'; |
14 | 13 | import getTSJestConfig from './utils/get-ts-jest-config'; |
| 14 | +import { |
| 15 | + importBabelCore, |
| 16 | + importBabelPluginIstanbul, |
| 17 | + importBabelPresetJest, |
| 18 | +} from './utils/imports'; |
| 19 | +import { TransformOptions } from '@babel/core'; |
15 | 20 |
|
16 | | -let babel: typeof __types__babel; |
17 | | -let istanbulPlugin: typeof __types__istanbulPlugin; |
18 | | -let jestPreset: typeof __types__jestPreset; |
| 21 | +let babel: TBabel; |
| 22 | +let istanbulPlugin: TBabelPluginIstanbul; |
| 23 | +let jestPreset: TBabelPresetJest; |
19 | 24 |
|
20 | 25 | function importBabelDeps() { |
21 | 26 | if (babel) return; // tslint:disable-line |
22 | 27 | // we must use babel until we handle hoisting of jest.mock() internally |
23 | | - babel = require('@babel/core'); |
24 | | - istanbulPlugin = require('babel-plugin-istanbul').default; |
25 | | - jestPreset = require('babel-preset-jest'); |
| 28 | + babel = importBabelCore(); |
| 29 | + istanbulPlugin = importBabelPluginIstanbul(); |
| 30 | + jestPreset = importBabelPresetJest(); |
26 | 31 | } |
27 | 32 |
|
28 | 33 | // Function that takes the transpiled typescript and runs it through babel/whatever. |
@@ -62,13 +67,17 @@ function createBabelTransformer( |
62 | 67 | codeSourcemapPair: jest.TransformedSource, |
63 | 68 | filename: string, |
64 | 69 | config: jest.ProjectConfig, |
65 | | - transformOptions: JestCacheKeyOptions, |
| 70 | + transformOptions: jest.TransformOptions, |
66 | 71 | ): jest.TransformedSource => { |
67 | 72 | const inputSourceMap = |
68 | 73 | typeof codeSourcemapPair.map === 'string' |
69 | 74 | ? JSON.parse(codeSourcemapPair.map) |
70 | 75 | : codeSourcemapPair.map; |
71 | | - const theseOptions = { ...optionsBase, filename, inputSourceMap }; |
| 76 | + const theseOptions = { |
| 77 | + ...optionsBase, |
| 78 | + filename, |
| 79 | + inputSourceMap, |
| 80 | + } as TransformOptions; |
72 | 81 | if (transformOptions && transformOptions.instrument) { |
73 | 82 | theseOptions.auxiliaryCommentBefore = ' istanbul ignore next '; |
74 | 83 | // Copied from jest-runtime transform.js |
|
0 commit comments