@@ -13,9 +13,14 @@ const getEmberPort = (() => {
1313 return ( ) => lastPort ++ ;
1414} ) ( ) ;
1515
16+ interface EmberCliOptions {
17+ args ?: string [ ] ;
18+ env ?: Record < string , string > ;
19+ }
20+
1621export default class SkeletonApp {
1722 port = getEmberPort ( ) ;
18- watched : WatchedBuild | null = null ;
23+ watched : WatchedEmberProcess | null = null ;
1924 cleanupTempDir = ( ) => rimraf ( this . root , ( error ) => error && console . error ( error ) ) ;
2025 root = path . join ( process . cwd ( ) , `test-skeleton-app-${ Math . random ( ) . toString ( 36 ) . slice ( 2 ) } ` ) ;
2126
@@ -25,18 +30,22 @@ export default class SkeletonApp {
2530 process . on ( 'beforeExit' , this . cleanupTempDir ) ;
2631 }
2732
28- build ( ) {
29- return this . _ember ( [ 'build' ] ) ;
33+ build ( { args = [ ] , env } : EmberCliOptions = { } ) {
34+ return this . _ember ( { args : [ 'build' , ...args ] , env } ) ;
35+ }
36+
37+ test ( { args = [ ] , env } : EmberCliOptions = { } ) {
38+ return this . _ember ( { args : [ 'test' , '--test-port' , `${ this . port } ` , ...args ] , env } ) ;
3039 }
3140
32- serve ( ) {
41+ serve ( { args = [ ] , env } : EmberCliOptions = { } ) {
3342 if ( this . watched ) {
3443 throw new Error ( 'Already serving' ) ;
3544 }
36- return ( this . watched = new WatchedBuild (
37- this . _ember ( [ 'serve' , '--port' , `${ this . port } ` ] ) ,
38- this . port
39- ) ) ;
45+
46+ let childProcess = this . _ember ( { args : [ 'serve' , '--port' , `${ this . port } ` , ... args ] , env } ) ;
47+
48+ return ( this . watched = new WatchedEmberProcess ( childProcess , this . port ) ) ;
4049 }
4150
4251 updatePackageJSON ( callback : ( arg : any ) => any ) {
@@ -68,13 +77,13 @@ export default class SkeletonApp {
6877 process . off ( 'beforeExit' , this . cleanupTempDir ) ;
6978 }
7079
71- _ember ( args : string [ ] ) {
80+ _ember ( { args, env } : EmberCliOptions ) {
7281 let ember = require . resolve ( 'ember-cli/bin/ember' ) ;
73- return execa . node ( ember , args , { cwd : this . root , all : true } ) ;
82+ return execa . node ( ember , args , { cwd : this . root , all : true , env } ) ;
7483 }
7584}
7685
77- class WatchedBuild extends EventEmitter {
86+ class WatchedEmberProcess extends EventEmitter {
7887 constructor ( protected ember : execa . ExecaChildProcess , protected port : number ) {
7988 super ( ) ;
8089 this . ember . stdout ?. on ( 'data' , ( data ) => {
0 commit comments