@@ -11,7 +11,8 @@ var compile = require("node-elm-compiler").compile,
1111 temp = require ( "temp" ) . track ( ) , // Automatically cleans up temp files.
1212 util = require ( "util" ) ,
1313 _ = require ( "lodash" ) ,
14- childProcess = require ( "child_process" ) ;
14+ childProcess = require ( "child_process" ) ,
15+ findup = require ( "findup-sync" ) ;
1516
1617var elm = {
1718 'elm-package' : 'elm-package'
@@ -102,23 +103,24 @@ temp.open({ prefix:'elm_test_', suffix:'.js' }, function(err, info) {
102103
103104 console . log ( "Successfully compiled" , testFile ) ;
104105
105- var runnerOpts = { stdio : [ "pipe" , "inherit" , "inherit" ] } ;
106- var runnerProcess = childProcess . spawn ( "node" , [ ] , runnerOpts ) ;
106+ // append suffix to temp file
107+ fs . appendFile ( dest , suffix , function ( err ) {
108+ if ( err ) throw ( err ) ;
107109
108- runnerProcess . on ( 'exit' , function ( exitCode ) {
109- process . exit ( exitCode ) ;
110- } ) ;
110+ console . log ( "Bootstrapped test script" )
111111
112- var reader = fs . createReadStream ( dest ) ;
112+ // add node_modules to NODE_PATH so the temporary file can require
113+ // local modules
114+ var pathToNodeModules = findup ( "node_modules" ) ;
115+ process . env . NODE_PATH = _ . compact ( [ process . env . NODE_PATH , pathToNodeModules ] ) . join ( ':' ) ;
113116
114- reader . on ( "end" , function ( ) {
115- runnerProcess . stdin . write ( suffix ) ;
117+ var runnerProcess = childProcess . spawn ( "node" , [ dest ] , { stdio : 'inherit' } ) ;
116118
117- runnerProcess . stdin . end ( ) ;
118- } )
119+ runnerProcess . on ( 'exit' , function ( exitCode ) {
120+ process . exit ( exitCode ) ;
121+ } ) ;
119122
120- reader . pipe ( runnerProcess . stdin ) ;
121-
122- console . log ( "Running tests..." ) ;
123+ console . log ( "Running tests..." ) ;
124+ } ) ;
123125 } ) ;
124126} ) ;
0 commit comments