@@ -64,29 +64,48 @@ function writeTempConfig(callback) {
64
64
} ) ;
65
65
}
66
66
67
- module . exports = function ( ) {
67
+ function run ( done , configPath ) {
68
+ grunt . log . writeln ( 'running jest (this may take a while)' ) ;
69
+
70
+ var args = [ '--harmony' , path . join ( 'node_modules' , 'jest-cli' , 'bin' , 'jest' ) ] ;
71
+ if ( configPath ) {
72
+ args . push ( '--config' , configPath ) ;
73
+ }
74
+ grunt . util . spawn ( {
75
+ cmd : 'node' ,
76
+ args : args ,
77
+ opts : { stdio : 'inherit' , env : { NODE_ENV : 'test' } } ,
78
+ } , function ( spawnErr , result , code ) {
79
+ if ( spawnErr ) {
80
+ onError ( spawnErr ) ;
81
+ } else {
82
+ grunt . log . ok ( 'jest passed' ) ;
83
+ }
84
+ grunt . log . writeln ( result . stdout ) ;
85
+
86
+ done ( code === 0 ) ;
87
+ } ) ;
88
+ }
89
+
90
+ function runJestNormally ( ) {
68
91
var done = this . async ( ) ;
92
+ run ( done ) ;
93
+ }
69
94
70
- grunt . log . writeln ( 'running jest (this may take a while)' ) ;
95
+ function runJestWithCoverage ( ) {
96
+ var done = this . async ( ) ;
71
97
72
98
writeTempConfig ( function ( writeErr ) {
73
99
if ( writeErr ) {
74
100
onError ( writeErr ) ;
75
101
return ;
76
102
}
77
- grunt . util . spawn ( {
78
- cmd : 'node' ,
79
- args : [ '--harmony' , path . join ( 'node_modules' , 'jest-cli' , 'bin' , 'jest' ) , '--config' , tempConfigPath ] ,
80
- opts : { stdio : 'inherit' , env : { NODE_ENV : 'test' } } ,
81
- } , function ( spawnErr , result , code ) {
82
- if ( spawnErr ) {
83
- onError ( spawnErr ) ;
84
- } else {
85
- grunt . log . ok ( 'jest passed' ) ;
86
- }
87
- grunt . log . writeln ( result . stdout ) ;
88
-
89
- done ( code === 0 ) ;
90
- } ) ;
103
+
104
+ run ( done , tempConfigPath ) ;
91
105
} ) ;
106
+ }
107
+
108
+ module . exports = {
109
+ normal : runJestNormally ,
110
+ coverage : runJestWithCoverage ,
92
111
} ;
0 commit comments