@@ -7,6 +7,8 @@ var chai = require('chai');
7
7
var expect = chai . expect ;
8
8
var conf = require ( 'ember-cli/tests/helpers/conf' ) ;
9
9
var sh = require ( 'shelljs' ) ;
10
+ var treeKill = require ( 'tree-kill' ) ;
11
+ var child_process = require ( 'child_process' ) ;
10
12
var ng = require ( '../helpers/ng' ) ;
11
13
var root = path . join ( process . cwd ( ) , 'tmp' ) ;
12
14
@@ -57,12 +59,12 @@ describe('Basic end-to-end Workflow', function () {
57
59
expect ( path . basename ( process . cwd ( ) ) ) . to . equal ( 'test-project' ) ;
58
60
} ) ;
59
61
60
- it ( 'Supports production builds via `ng build --environment=production `' , function ( ) {
62
+ it ( 'Supports production builds via `ng build -prod `' , function ( ) {
61
63
this . timeout ( 420000 ) ;
62
64
63
- // Can't user the `ng` helper because somewhere the environment gets
65
+ // Can't use the `ng` helper because somewhere the environment gets
64
66
// stuck to the first build done
65
- sh . exec ( `${ ngBin } build --environment=production ` ) ;
67
+ sh . exec ( `${ ngBin } build -prod ` ) ;
66
68
expect ( existsSync ( path . join ( process . cwd ( ) , 'dist' ) ) ) . to . be . equal ( true ) ;
67
69
var appBundlePath = path . join ( process . cwd ( ) , 'dist' , 'app' , 'index.js' ) ;
68
70
var appBundleContent = fs . readFileSync ( appBundlePath , { encoding : 'utf8' } ) ;
@@ -112,6 +114,49 @@ describe('Basic end-to-end Workflow', function () {
112
114
} ) ;
113
115
} ) ;
114
116
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
+
115
160
it ( 'Can create a test component using `ng generate component test-component`' , function ( ) {
116
161
this . timeout ( 10000 ) ;
117
162
return ng ( [ 'generate' , 'component' , 'test-component' ] ) . then ( function ( ) {
@@ -370,4 +415,47 @@ describe('Basic end-to-end Workflow', function () {
370
415
expect ( 'build failed where it should have succeeded' ) . to . equal ( '' ) ;
371
416
} ) ;
372
417
} ) ;
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
+ } ) ;
373
461
} ) ;
0 commit comments