@@ -7,6 +7,8 @@ var chai = require('chai');
77var expect = chai . expect ;
88var conf = require ( 'ember-cli/tests/helpers/conf' ) ;
99var sh = require ( 'shelljs' ) ;
10+ var treeKill = require ( 'tree-kill' ) ;
11+ var child_process = require ( 'child_process' ) ;
1012var ng = require ( '../helpers/ng' ) ;
1113var root = path . join ( process . cwd ( ) , 'tmp' ) ;
1214
@@ -57,12 +59,12 @@ describe('Basic end-to-end Workflow', function () {
5759 expect ( path . basename ( process . cwd ( ) ) ) . to . equal ( 'test-project' ) ;
5860 } ) ;
5961
60- it ( 'Supports production builds via `ng build --environment=production `' , function ( ) {
62+ it ( 'Supports production builds via `ng build -prod `' , function ( ) {
6163 this . timeout ( 420000 ) ;
6264
63- // Can't user the `ng` helper because somewhere the environment gets
65+ // Can't use the `ng` helper because somewhere the environment gets
6466 // stuck to the first build done
65- sh . exec ( `${ ngBin } build --environment=production ` ) ;
67+ sh . exec ( `${ ngBin } build -prod ` ) ;
6668 expect ( existsSync ( path . join ( process . cwd ( ) , 'dist' ) ) ) . to . be . equal ( true ) ;
6769 var appBundlePath = path . join ( process . cwd ( ) , 'dist' , 'app' , 'index.js' ) ;
6870 var appBundleContent = fs . readFileSync ( appBundlePath , { encoding : 'utf8' } ) ;
@@ -112,6 +114,49 @@ describe('Basic end-to-end Workflow', function () {
112114 } ) ;
113115 } ) ;
114116
117+ it ( 'Serve and run e2e tests after initial build' , function ( ) {
118+ this . timeout ( 240000 ) ;
119+
120+ var ngServePid ;
121+
122+ function executor ( resolve , reject ) {
123+ var serveProcess = child_process . exec ( `${ ngBin } serve` ) ;
124+ var startedProtractor = false ;
125+ ngServePid = serveProcess . pid ;
126+
127+ serveProcess . stdout . on ( 'data' , ( data ) => {
128+ if ( / B u i l d s u c c e s s f u l / . test ( data ) && ! startedProtractor ) {
129+ startedProtractor = true ;
130+ child_process . exec ( `${ ngBin } e2e` , ( error , stdout , stderr ) => {
131+ if ( error !== null ) {
132+ reject ( stderr )
133+ } else {
134+ resolve ( ) ;
135+ }
136+ } ) ;
137+ } else if ( / f a i l e d w i t h : / . test ( data ) ) {
138+ reject ( data ) ;
139+ }
140+ } ) ;
141+
142+ serveProcess . stderr . on ( 'data' , ( data ) => {
143+ reject ( data ) ;
144+ } ) ;
145+ serveProcess . on ( 'close' , ( code ) => {
146+ code === 0 ? resolve ( ) : reject ( 'ng serve command closed with error' )
147+ } ) ;
148+ }
149+
150+ return new Promise ( executor )
151+ . then ( ( ) => {
152+ if ( ngServePid ) treeKill ( ngServePid ) ;
153+ } )
154+ . catch ( ( msg ) => {
155+ if ( ngServePid ) treeKill ( ngServePid ) ;
156+ throw new Error ( msg ) ;
157+ } ) ;
158+ } ) ;
159+
115160 it ( 'Can create a test component using `ng generate component test-component`' , function ( ) {
116161 this . timeout ( 10000 ) ;
117162 return ng ( [ 'generate' , 'component' , 'test-component' ] ) . then ( function ( ) {
@@ -370,4 +415,47 @@ describe('Basic end-to-end Workflow', function () {
370415 expect ( 'build failed where it should have succeeded' ) . to . equal ( '' ) ;
371416 } ) ;
372417 } ) ;
418+
419+ it ( 'Serve and run e2e tests after all other commands' , function ( ) {
420+ this . timeout ( 240000 ) ;
421+
422+ var ngServePid ;
423+
424+ function executor ( resolve , reject ) {
425+ var serveProcess = child_process . exec ( `${ ngBin } serve` ) ;
426+ var startedProtractor = false ;
427+ ngServePid = serveProcess . pid ;
428+
429+ serveProcess . stdout . on ( 'data' , ( data ) => {
430+ if ( / B u i l d s u c c e s s f u l / . test ( data ) && ! startedProtractor ) {
431+ startedProtractor = true ;
432+ child_process . exec ( `${ ngBin } e2e` , ( error , stdout , stderr ) => {
433+ if ( error !== null ) {
434+ reject ( stderr )
435+ } else {
436+ resolve ( ) ;
437+ }
438+ } ) ;
439+ } else if ( / f a i l e d w i t h : / . test ( data ) ) {
440+ reject ( data ) ;
441+ }
442+ } ) ;
443+
444+ serveProcess . stderr . on ( 'data' , ( data ) => {
445+ reject ( data ) ;
446+ } ) ;
447+ serveProcess . on ( 'close' , ( code ) => {
448+ code === 0 ? resolve ( ) : reject ( 'ng serve command closed with error' )
449+ } ) ;
450+ }
451+
452+ return new Promise ( executor )
453+ . then ( ( ) => {
454+ if ( ngServePid ) treeKill ( ngServePid ) ;
455+ } )
456+ . catch ( ( msg ) => {
457+ if ( ngServePid ) treeKill ( ngServePid ) ;
458+ throw new Error ( msg ) ;
459+ } ) ;
460+ } ) ;
373461} ) ;
0 commit comments