@@ -15,14 +15,13 @@ const getEmberPort = (() => {
1515
1616interface EmberCliOptions {
1717 args ?: string [ ] ;
18- env ?: any ;
18+ env ?: Record < string , string > ;
1919}
2020
2121export default class SkeletonApp {
2222 port = getEmberPort ( ) ;
2323 watched : WatchedEmberProcess | null = null ;
24- watchedTest : WatchedEmberProcess | null = null ;
25- cleanupTempDir = ( ) => rimraf ( this . root , ( error ) => console . error ( error ) ) ;
24+ cleanupTempDir = ( ) => rimraf ( this . root , ( error ) => error && console . error ( error ) ) ;
2625 root = path . join ( process . cwd ( ) , `test-skeleton-app-${ Math . random ( ) . toString ( 36 ) . slice ( 2 ) } ` ) ;
2726
2827 constructor ( ) {
@@ -31,26 +30,22 @@ export default class SkeletonApp {
3130 process . on ( 'beforeExit' , this . cleanupTempDir ) ;
3231 }
3332
34- build ( ) {
35- return this . _ember ( { args : [ 'build' ] } ) ;
33+ build ( { args = [ ] , env } : EmberCliOptions = { } ) {
34+ return this . _ember ( { args : [ 'build' , ... args ] , env } ) ;
3635 }
3736
38- serve ( options : EmberCliOptions = { args : [ ] , env : { } } ) {
37+ test ( { args = [ ] , env } : EmberCliOptions = { } ) {
38+ return this . _ember ( { args : [ 'test' , '--test-port' , `${ this . port } ` , ...args ] , env } ) ;
39+ }
40+
41+ serve ( { args = [ ] , env } : EmberCliOptions = { } ) {
3942 if ( this . watched ) {
4043 throw new Error ( 'Already serving' ) ;
4144 }
42- options . args = options . args || [ ] ;
43- options . args = [ 'serve' , '--port' , `${ this . port } ` , ...options . args ] ;
44- return ( this . watched = new WatchedEmberProcess ( this . _ember ( options ) , this . port ) ) ;
45- }
4645
47- test ( options : EmberCliOptions = { args : [ ] , env : { } } ) {
48- if ( this . watchedTest ) {
49- throw new Error ( 'Already testing' ) ;
50- }
51- options . args = options . args || [ ] ;
52- options . args = [ 'test' , ...options . args ] ;
53- return ( this . watchedTest = new WatchedEmberProcess ( this . _ember ( options ) ) ) ;
46+ let childProcess = this . _ember ( { args : [ 'serve' , '--port' , `${ this . port } ` , ...args ] , env } ) ;
47+
48+ return ( this . watched = new WatchedEmberProcess ( childProcess , this . port ) ) ;
5449 }
5550
5651 updatePackageJSON ( callback : ( arg : any ) => any ) {
@@ -77,21 +72,19 @@ export default class SkeletonApp {
7772 if ( this . watched ) {
7873 this . watched . kill ( ) ;
7974 }
80- if ( this . watchedTest ) {
81- this . watchedTest . kill ( ) ;
82- }
75+
8376 this . cleanupTempDir ( ) ;
8477 process . off ( 'beforeExit' , this . cleanupTempDir ) ;
8578 }
8679
87- _ember ( options : EmberCliOptions ) {
80+ _ember ( { args , env } : EmberCliOptions ) {
8881 let ember = require . resolve ( 'ember-cli/bin/ember' ) ;
89- return execa . node ( ember , options . args , { cwd : this . root , all : true , env : options . env } ) ;
82+ return execa . node ( ember , args , { cwd : this . root , all : true , env } ) ;
9083 }
9184}
9285
9386class WatchedEmberProcess extends EventEmitter {
94- constructor ( protected ember : execa . ExecaChildProcess , protected port ? : number ) {
87+ constructor ( protected ember : execa . ExecaChildProcess , protected port : number ) {
9588 super ( ) ;
9689 this . ember . stdout ?. on ( 'data' , ( data ) => {
9790 let output = data . toString ( ) ;
@@ -115,10 +108,6 @@ class WatchedEmberProcess extends EventEmitter {
115108 return got ( `http://localhost:${ this . port } ${ path } ` ) ;
116109 }
117110
118- raceForOutputs ( targets : string [ ] ) {
119- return Promise . race ( targets . map ( ( target ) => this . waitForOutput ( target ) ) ) ;
120- }
121-
122111 waitForOutput ( target : string ) {
123112 return new Promise ( ( resolve ) => {
124113 let output = '' ;
0 commit comments