@@ -5,8 +5,8 @@ import {writeFile} from '../../utils/fs';
5
5
import { request } from '../../utils/http' ;
6
6
import { killAllProcesses , ng } from '../../utils/process' ;
7
7
import { ngServe } from '../../utils/project' ;
8
- import { expectToFail } from '../../utils/utils ' ;
9
-
8
+ import { updateJsonFile } from '../../utils/project ' ;
9
+ import { expectToFail } from "../../utils/utils" ;
10
10
11
11
export default function ( ) {
12
12
// Create an express app that serves as a proxy.
@@ -31,16 +31,39 @@ export default function() {
31
31
32
32
return Promise . resolve ( )
33
33
. then ( ( ) => writeFile ( proxyConfigFile , JSON . stringify ( proxyConfig , null , 2 ) ) )
34
- . then ( ( ) => ngServe ( '--proxy' , proxyConfigFile ) )
34
+ . then ( ( ) => ngServe ( '--proxy-config' , proxyConfigFile ) )
35
+ . then ( ( ) => request ( 'http://localhost:4200/api/test' ) )
36
+ . then ( body => {
37
+ if ( ! body . match ( / T E S T _ A P I _ R E T U R N / ) ) {
38
+ throw new Error ( 'Response does not match expected value.' ) ;
39
+ }
40
+ } )
41
+ . then ( ( ) => killAllProcesses ( ) , ( err ) => { killAllProcesses ( ) ; throw err ; } )
42
+
43
+ . then ( ( ) => updateJsonFile ( '.angular-cli.json' , configJson => {
44
+ const app = configJson . defaults ;
45
+ app . serve = {
46
+ proxyConfig : proxyConfigFile
47
+ } ;
48
+ } ) )
49
+ . then ( ( ) => ngServe ( ) )
35
50
. then ( ( ) => request ( 'http://localhost:4200/api/test' ) )
36
51
. then ( body => {
37
52
if ( ! body . match ( / T E S T _ A P I _ R E T U R N / ) ) {
38
53
throw new Error ( 'Response does not match expected value.' ) ;
39
54
}
40
55
} )
41
- . then ( ( ) => server . close ( ) , ( err ) => { server . close ( ) ; throw err ; } )
42
56
. then ( ( ) => killAllProcesses ( ) , ( err ) => { killAllProcesses ( ) ; throw err ; } )
43
57
58
+ . then ( ( ) => server . close ( ) , ( err ) => { server . close ( ) ; throw err ; } )
59
+
44
60
// A non-existing proxy file should error.
45
- . then ( ( ) => expectToFail ( ( ) => ng ( 'serve' , '--proxy' , 'proxy.non-existent.json' ) ) ) ;
61
+ . then ( ( ) => expectToFail ( ( ) => ng ( 'serve' , '--proxy-config' , 'proxy.non-existent.json' ) ) )
62
+ . then ( ( ) => updateJsonFile ( '.angular-cli.json' , configJson => {
63
+ const app = configJson . defaults ;
64
+ app . serve = {
65
+ proxyConfig : 'proxy.non-existent.json'
66
+ } ;
67
+ } ) )
68
+ . then ( ( ) => expectToFail ( ( ) => ng ( 'serve' ) ) ) ;
46
69
}
0 commit comments