@@ -15,14 +15,13 @@ const getEmberPort = (() => {
15
15
16
16
interface EmberCliOptions {
17
17
args ?: string [ ] ;
18
- env ?: any ;
18
+ env ?: Record < string , string > ;
19
19
}
20
20
21
21
export default class SkeletonApp {
22
22
port = getEmberPort ( ) ;
23
23
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 ) ) ;
26
25
root = path . join ( process . cwd ( ) , `test-skeleton-app-${ Math . random ( ) . toString ( 36 ) . slice ( 2 ) } ` ) ;
27
26
28
27
constructor ( ) {
@@ -31,26 +30,22 @@ export default class SkeletonApp {
31
30
process . on ( 'beforeExit' , this . cleanupTempDir ) ;
32
31
}
33
32
34
- build ( ) {
35
- return this . _ember ( { args : [ 'build' ] } ) ;
33
+ build ( { args = [ ] , env } : EmberCliOptions = { } ) {
34
+ return this . _ember ( { args : [ 'build' , ... args ] , env } ) ;
36
35
}
37
36
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 = { } ) {
39
42
if ( this . watched ) {
40
43
throw new Error ( 'Already serving' ) ;
41
44
}
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
- }
46
45
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 ) ) ;
54
49
}
55
50
56
51
updatePackageJSON ( callback : ( arg : any ) => any ) {
@@ -77,21 +72,19 @@ export default class SkeletonApp {
77
72
if ( this . watched ) {
78
73
this . watched . kill ( ) ;
79
74
}
80
- if ( this . watchedTest ) {
81
- this . watchedTest . kill ( ) ;
82
- }
75
+
83
76
this . cleanupTempDir ( ) ;
84
77
process . off ( 'beforeExit' , this . cleanupTempDir ) ;
85
78
}
86
79
87
- _ember ( options : EmberCliOptions ) {
80
+ _ember ( { args , env } : EmberCliOptions ) {
88
81
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 } ) ;
90
83
}
91
84
}
92
85
93
86
class WatchedEmberProcess extends EventEmitter {
94
- constructor ( protected ember : execa . ExecaChildProcess , protected port ? : number ) {
87
+ constructor ( protected ember : execa . ExecaChildProcess , protected port : number ) {
95
88
super ( ) ;
96
89
this . ember . stdout ?. on ( 'data' , ( data ) => {
97
90
let output = data . toString ( ) ;
@@ -115,10 +108,6 @@ class WatchedEmberProcess extends EventEmitter {
115
108
return got ( `http://localhost:${ this . port } ${ path } ` ) ;
116
109
}
117
110
118
- raceForOutputs ( targets : string [ ] ) {
119
- return Promise . race ( targets . map ( ( target ) => this . waitForOutput ( target ) ) ) ;
120
- }
121
-
122
111
waitForOutput ( target : string ) {
123
112
return new Promise ( ( resolve ) => {
124
113
let output = '' ;
0 commit comments