Skip to content

Commit 3a400c5

Browse files
Alanmgechev
Alan
authored andcommitted
fix(@angular-devkit/build-angular): dev-server port number mismatches in logs when using port=0
Fixes #14499
1 parent 22d7728 commit 3a400c5

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

packages/angular_devkit/build_angular/src/dev-server/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,9 @@ export function serveWebpackBrowser(
216216

217217
if (first) {
218218
first = false;
219-
220219
context.logger.info(tags.oneLine`
221220
**
222-
Angular Live Development Server is listening on ${options.host}:${options.port},
221+
Angular Live Development Server is listening on ${options.host}:${buildEvent.port},
223222
open your browser on ${serverAddress}
224223
**
225224
`);

packages/angular_devkit/build_angular/test/dev-server/works_spec_large.ts

+25
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,29 @@ describe('Dev Server Builder', () => {
6767
expect(res).not.toContain('This file is automatically generated during release.');
6868
expect(res).toContain('<title>HelloWorldApp</title>');
6969
});
70+
71+
it('works with port 0', async () => {
72+
const logger = new logging.Logger('');
73+
const logs: string[] = [];
74+
logger.subscribe(e => logs.push(e.message));
75+
76+
const run = await architect.scheduleTarget(target, { port: 0 }, { logger });
77+
runs.push(run);
78+
const output = await run.result as DevServerBuilderOutput;
79+
expect(output.success).toBe(true);
80+
81+
const groups = logs.join().match(/\:(\d+){4,6}/g);
82+
if (!groups) {
83+
throw new Error('Expected log to contain port number.');
84+
}
85+
86+
// tests that both the ports in the logs are the same.
87+
const [firstPort, secondPort] = groups;
88+
expect(firstPort).toBe(secondPort);
89+
90+
expect(output.baseUrl).toBe(`http://localhost${firstPort}/`);
91+
const response = await fetch(`http://localhost${firstPort}/index.html`);
92+
expect(await response.text()).toContain('<title>HelloWorldApp</title>');
93+
});
94+
7095
});

0 commit comments

Comments
 (0)