|
5 | 5 | * LICENSE file in the root directory of this source tree. |
6 | 6 | */ |
7 | 7 |
|
8 | | -import {extname} from 'path'; |
9 | 8 | import pEachSeries from 'p-each-series'; |
10 | | -import {addHook} from 'pirates'; |
11 | 9 | import {Config} from '@jest/types'; |
12 | 10 | import {Test} from 'jest-runner'; |
13 | 11 | import {ScriptTransformer} from '@jest/transform'; |
@@ -47,46 +45,17 @@ export default async ({ |
47 | 45 |
|
48 | 46 | const transformer = new ScriptTransformer(projectConfig); |
49 | 47 |
|
50 | | - // Load the transformer to avoid a cycle where we need to load a |
51 | | - // transformer in order to transform it in the require hooks |
52 | | - transformer.preloadTransformer(modulePath); |
| 48 | + await transformer.requireAndTranspileModule(modulePath, async m => { |
| 49 | + const globalModule = interopRequireDefault(m).default; |
53 | 50 |
|
54 | | - let transforming = false; |
55 | | - const revertHook = addHook( |
56 | | - (code, filename) => { |
57 | | - try { |
58 | | - transforming = true; |
59 | | - return ( |
60 | | - transformer.transformSource(filename, code, false).code || code |
61 | | - ); |
62 | | - } finally { |
63 | | - transforming = false; |
64 | | - } |
65 | | - }, |
66 | | - { |
67 | | - exts: [extname(modulePath)], |
68 | | - ignoreNodeModules: false, |
69 | | - matcher: (...args) => { |
70 | | - if (transforming) { |
71 | | - // Don't transform any dependency required by the transformer itself |
72 | | - return false; |
73 | | - } |
74 | | - return transformer.shouldTransform(...args); |
75 | | - }, |
76 | | - }, |
77 | | - ); |
78 | | - |
79 | | - const globalModule = interopRequireDefault(require(modulePath)).default; |
80 | | - |
81 | | - if (typeof globalModule !== 'function') { |
82 | | - throw new TypeError( |
83 | | - `${moduleName} file must export a function at ${modulePath}`, |
84 | | - ); |
85 | | - } |
86 | | - |
87 | | - await globalModule(globalConfig); |
| 51 | + if (typeof globalModule !== 'function') { |
| 52 | + throw new TypeError( |
| 53 | + `${moduleName} file must export a function at ${modulePath}`, |
| 54 | + ); |
| 55 | + } |
88 | 56 |
|
89 | | - revertHook(); |
| 57 | + await globalModule(globalConfig); |
| 58 | + }); |
90 | 59 | }); |
91 | 60 | } |
92 | 61 |
|
|
0 commit comments