@@ -9,11 +9,12 @@ import {
9
9
replaceInFile ,
10
10
writeFile ,
11
11
} from '../../utils/fs' ;
12
+ import { findFreePort } from '../../utils/network' ;
12
13
import { installPackage } from '../../utils/packages' ;
13
14
import { ng } from '../../utils/process' ;
14
15
import { updateJsonFile } from '../../utils/project' ;
15
- import { expectToFail } from '../../utils/utils' ;
16
16
import { readNgVersion } from '../../utils/version' ;
17
+ import { Server } from 'http' ;
17
18
18
19
// Configurations for each locale.
19
20
export const baseDir = 'dist/test-project' ;
@@ -67,13 +68,31 @@ export const langTranslations = [
67
68
] ;
68
69
export const sourceLocale = langTranslations [ 0 ] . lang ;
69
70
70
- export const externalServer = ( outputPath : string , baseUrl = '/' ) => {
71
+ export interface ExternalServer {
72
+ readonly server : Server ;
73
+ readonly port : number ;
74
+ readonly url : string ;
75
+ }
76
+
77
+ /**
78
+ * Create an `express` `http.Server` listening on a random port.
79
+ *
80
+ * Call .close() on the server return value to close the server.
81
+ */
82
+ export async function externalServer ( outputPath : string , baseUrl = '/' ) : Promise < ExternalServer > {
83
+ const port = await findFreePort ( ) ;
84
+
71
85
const app = express ( ) ;
72
86
app . use ( baseUrl , express . static ( resolve ( outputPath ) ) ) ;
73
87
74
- // call .close() on the return value to close the server.
75
- return app . listen ( 4200 , 'localhost' ) ;
76
- } ;
88
+ const server = app . listen ( port , 'localhost' ) ;
89
+
90
+ return {
91
+ server,
92
+ port,
93
+ url : `http://localhost:${ port } ${ baseUrl } ` ,
94
+ } ;
95
+ }
77
96
78
97
export const formats = {
79
98
'xlf' : {
0 commit comments