@@ -10,39 +10,47 @@ const explorer = cosmiconfig('jest-runner');
1010
1111const isWin32 = os . platform ( ) === 'win32' ;
1212
13+ /* eslint max-statements: ["error", 25] */
1314export default async function jetRunnerBabel ( { testPath, config } ) {
1415 const start = new Date ( ) ;
1516 let options = normalizeRunnerConfig ( explorer . searchSync ( ) ) ;
1617 const cfgs = [ ] . concat ( options . babel ) . filter ( Boolean ) ;
1718
1819 const testResults = await Promise . all (
19- cfgs . map ( ( { config : cfg , ...opts } ) => {
20+ cfgs . reduce ( ( acc , { config : cfg , ...opts } ) => {
2021 options = { ...options , ...opts } ;
22+
2123 let result = null ;
22- // index += 1;
2324
25+ const babelConfig = { ...cfg } ;
26+
27+ // sasa;
2428 try {
25- result = transformFileSync ( testPath , cfg ) ;
29+ result = transformFileSync ( testPath , babelConfig ) ;
2630 } catch ( err ) {
27- return fail ( {
28- start,
29- end : new Date ( ) ,
30- test : { path : testPath , title : 'Babel' , errorMessage : err . message } ,
31- } ) ;
31+ return acc . concat (
32+ fail ( {
33+ start,
34+ end : new Date ( ) ,
35+ test : { path : testPath , title : 'Babel' , errorMessage : err . message } ,
36+ } ) ,
37+ ) ;
3238 }
3339
3440 // Classics in the genre! Yes, it's possible, sometimes.
3541 // Old habit for ensurance
3642 if ( ! result ) {
37- return fail ( {
38- start,
39- end : new Date ( ) ,
40- test : {
41- path : testPath ,
42- title : 'Babel' ,
43- errorMessage : `Babel runner fails...` ,
44- } ,
45- } ) ;
43+ return acc . concat (
44+ fail ( {
45+ start,
46+ end : new Date ( ) ,
47+ test : {
48+ path : testPath ,
49+ title : 'Babel' ,
50+ errorMessage : `Babel runner fails...` ,
51+ } ,
52+ } ) ,
53+ ) ;
4654 }
4755
4856 let relativeTestPath = path . relative ( config . rootDir , testPath ) ;
@@ -53,15 +61,15 @@ export default async function jetRunnerBabel({ testPath, config }) {
5361
5462 // if not in monorepo, the `outs.dir` will be empty
5563 const outs = relativeTestPath . split ( '/' ) . reduce (
56- ( acc , item , idx ) => {
64+ ( accumulator , item , idx ) => {
5765 // only if we are in monorepo we want to get the first 2 items
5866 if ( options . isMonorepo ( config . cwd ) && idx < 2 ) {
59- return { ...acc , dir : acc . dir . concat ( item ) } ;
67+ return { ...accumulator , dir : accumulator . dir . concat ( item ) } ;
6068 }
6169
6270 return {
63- ...acc ,
64- file : acc . file
71+ ...accumulator ,
72+ file : accumulator . file
6573 . concat ( item === options . srcDir ? null : item )
6674 . filter ( Boolean ) ,
6775 } ;
@@ -85,12 +93,32 @@ export default async function jetRunnerBabel({ testPath, config }) {
8593 fs . mkdirSync ( outDir , { recursive : true } ) ;
8694 fs . writeFileSync ( outFile , result . code ) ;
8795
88- return pass ( {
89- start,
90- end : new Date ( ) ,
91- test : { path : outFile , title : 'Babel' } ,
92- } ) ;
93- } ) ,
96+ if ( result . map || babelConfig . sourceMaps === true ) {
97+ const mapFile = `${ outFile } .map` ;
98+ fs . writeFileSync ( mapFile , JSON . stringify ( result . map ) ) ;
99+
100+ return acc . concat (
101+ pass ( {
102+ start,
103+ end : new Date ( ) ,
104+ test : { path : outFile , title : 'Babel' } ,
105+ } ) ,
106+ pass ( {
107+ start,
108+ end : new Date ( ) ,
109+ test : { path : mapFile , title : 'Babel' } ,
110+ } ) ,
111+ ) ;
112+ }
113+
114+ return acc . concat (
115+ pass ( {
116+ start,
117+ end : new Date ( ) ,
118+ test : { path : outFile , title : 'Babel' } ,
119+ } ) ,
120+ ) ;
121+ } , [ ] ) ,
94122 ) ;
95123
96124 return testResults ;
0 commit comments