5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
- import fetch from 'node-fetch' ; // tslint:disable-line:no-implicit-dependencies
9
- import { mergeMap , take , timeout } from 'rxjs/operators' ;
10
8
import { serveWebpackBrowser } from '../../index' ;
9
+ import { executeOnceAndFetch } from '../execute-fetch' ;
11
10
import {
12
11
BASE_OPTIONS ,
13
- BUILD_TIMEOUT ,
14
12
DEV_SERVER_BUILDER_INFO ,
15
13
describeBuilder ,
16
14
setupBrowserTarget ,
@@ -32,21 +30,12 @@ describeBuilder(serveWebpackBrowser, DEV_SERVER_BUILDER_INFO, (harness) => {
32
30
...BASE_OPTIONS ,
33
31
} ) ;
34
32
35
- await harness
36
- . execute ( )
37
- . pipe (
38
- timeout ( BUILD_TIMEOUT ) ,
39
- mergeMap ( async ( { result } ) => {
40
- expect ( result ?. success ) . toBeTrue ( ) ;
33
+ const { result, response } = await executeOnceAndFetch ( harness , '/' , {
34
+ request : { headers : FETCH_HEADERS } ,
35
+ } ) ;
41
36
42
- if ( result ?. success ) {
43
- const response = await fetch ( `${ result . baseUrl } ` , { headers : FETCH_HEADERS } ) ;
44
- expect ( await response . text ( ) ) . toBe ( 'Invalid Host header' ) ;
45
- }
46
- } ) ,
47
- take ( 1 ) ,
48
- )
49
- . toPromise ( ) ;
37
+ expect ( result ?. success ) . toBeTrue ( ) ;
38
+ expect ( await response ?. text ( ) ) . toBe ( 'Invalid Host header' ) ;
50
39
} ) ;
51
40
52
41
it ( 'does not allow an invalid host when option is an empty array' , async ( ) => {
@@ -55,21 +44,12 @@ describeBuilder(serveWebpackBrowser, DEV_SERVER_BUILDER_INFO, (harness) => {
55
44
allowedHosts : [ ] ,
56
45
} ) ;
57
46
58
- await harness
59
- . execute ( )
60
- . pipe (
61
- timeout ( BUILD_TIMEOUT ) ,
62
- mergeMap ( async ( { result } ) => {
63
- expect ( result ?. success ) . toBeTrue ( ) ;
47
+ const { result, response } = await executeOnceAndFetch ( harness , '/' , {
48
+ request : { headers : FETCH_HEADERS } ,
49
+ } ) ;
64
50
65
- if ( result ?. success ) {
66
- const response = await fetch ( `${ result . baseUrl } ` , { headers : FETCH_HEADERS } ) ;
67
- expect ( await response . text ( ) ) . toBe ( 'Invalid Host header' ) ;
68
- }
69
- } ) ,
70
- take ( 1 ) ,
71
- )
72
- . toPromise ( ) ;
51
+ expect ( result ?. success ) . toBeTrue ( ) ;
52
+ expect ( await response ?. text ( ) ) . toBe ( 'Invalid Host header' ) ;
73
53
} ) ;
74
54
75
55
it ( 'allows a host when specified in the option' , async ( ) => {
@@ -78,21 +58,12 @@ describeBuilder(serveWebpackBrowser, DEV_SERVER_BUILDER_INFO, (harness) => {
78
58
allowedHosts : [ 'example.com' ] ,
79
59
} ) ;
80
60
81
- await harness
82
- . execute ( )
83
- . pipe (
84
- timeout ( BUILD_TIMEOUT ) ,
85
- mergeMap ( async ( { result } ) => {
86
- expect ( result ?. success ) . toBeTrue ( ) ;
61
+ const { result, response } = await executeOnceAndFetch ( harness , '/' , {
62
+ request : { headers : FETCH_HEADERS } ,
63
+ } ) ;
87
64
88
- if ( result ?. success ) {
89
- const response = await fetch ( `${ result . baseUrl } ` , { headers : FETCH_HEADERS } ) ;
90
- expect ( await response . text ( ) ) . toContain ( '<title>' ) ;
91
- }
92
- } ) ,
93
- take ( 1 ) ,
94
- )
95
- . toPromise ( ) ;
65
+ expect ( result ?. success ) . toBeTrue ( ) ;
66
+ expect ( await response ?. text ( ) ) . toContain ( '<title>' ) ;
96
67
} ) ;
97
68
} ) ;
98
69
} ) ;
0 commit comments