|
9 | 9 | import { Architect } from '@angular-devkit/architect';
|
10 | 10 | import { getSystemPath, join, normalize, virtualFs } from '@angular-devkit/core';
|
11 | 11 | import * as express from 'express'; // tslint:disable-line:no-implicit-dependencies
|
| 12 | +import * as http from 'http'; |
| 13 | +import { AddressInfo } from 'net'; |
12 | 14 | import { createArchitect, host } from '../test-utils';
|
13 | 15 |
|
14 | 16 | describe('AppShell Builder', () => {
|
@@ -251,19 +253,25 @@ describe('AppShell Builder', () => {
|
251 | 253 | // Serve the app using a simple static server.
|
252 | 254 | const app = express();
|
253 | 255 | app.use('/', express.static(getSystemPath(join(host.root(), 'dist')) + '/'));
|
254 |
| - const server = app.listen(4200); |
255 |
| - |
256 |
| - // Load app in protractor, then check service worker status. |
257 |
| - const protractorRun = await architect.scheduleTarget( |
258 |
| - { project: 'app-e2e', target: 'e2e' }, |
259 |
| - { devServerTarget: undefined } as {}, |
260 |
| - ); |
261 |
| - const protractorOutput = await protractorRun.result; |
262 |
| - await protractorRun.stop(); |
263 |
| - expect(protractorOutput.success).toBe(true); |
264 |
| - |
265 |
| - // Close the express server. |
266 |
| - server.close(); |
| 256 | + const server = await new Promise<http.Server>((resolve) => { |
| 257 | + const innerServer = app.listen(0, 'localhost', () => resolve(innerServer)); |
| 258 | + }); |
| 259 | + try { |
| 260 | + const serverPort = (server.address() as AddressInfo).port; |
| 261 | + // Load app in protractor, then check service worker status. |
| 262 | + const protractorRun = await architect.scheduleTarget( |
| 263 | + { project: 'app-e2e', target: 'e2e' }, |
| 264 | + { baseUrl: `http://localhost:${serverPort}/`, devServerTarget: '' }, |
| 265 | + ); |
| 266 | + |
| 267 | + const protractorOutput = await protractorRun.result; |
| 268 | + await protractorRun.stop(); |
| 269 | + |
| 270 | + expect(protractorOutput.success).toBe(true); |
| 271 | + } finally { |
| 272 | + // Close the express server. |
| 273 | + await new Promise<void>((resolve) => server.close(() => resolve())); |
| 274 | + } |
267 | 275 | });
|
268 | 276 |
|
269 | 277 | it('critical CSS is inlined', async () => {
|
|
0 commit comments