@@ -9,11 +9,12 @@ import {
99 replaceInFile ,
1010 writeFile ,
1111} from '../../utils/fs' ;
12+ import { findFreePort } from '../../utils/network' ;
1213import { installPackage } from '../../utils/packages' ;
1314import { ng } from '../../utils/process' ;
1415import { updateJsonFile } from '../../utils/project' ;
15- import { expectToFail } from '../../utils/utils' ;
1616import { readNgVersion } from '../../utils/version' ;
17+ import { Server } from 'http' ;
1718
1819// Configurations for each locale.
1920export const baseDir = 'dist/test-project' ;
@@ -67,13 +68,31 @@ export const langTranslations = [
6768] ;
6869export const sourceLocale = langTranslations [ 0 ] . lang ;
6970
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+
7185 const app = express ( ) ;
7286 app . use ( baseUrl , express . static ( resolve ( outputPath ) ) ) ;
7387
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://${ server } :${ port } ` ,
94+ } ;
95+ }
7796
7897export const formats = {
7998 'xlf' : {
0 commit comments