Skip to content

Commit 16ce92d

Browse files
Alan Agiusalexeagle
Alan Agius
authored andcommittedMay 7, 2019
fix(@angular-devkit/build-angular): e2e does not respect dev-server host and port settings (#14165)
Fixes #14151
1 parent 968204f commit 16ce92d

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed
 

‎packages/angular_devkit/build_angular/src/protractor/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,21 @@ async function execute(
105105
const serverOptions = await context.getTargetOptions(target);
106106

107107
const overrides: Record<string, string | number | boolean> = { watch: false };
108-
if (options.host !== undefined) { overrides.host = options.host; }
109-
if (options.port !== undefined) { overrides.port = options.port; }
110-
server = await context.scheduleTarget(target, overrides);
108+
if (options.host !== undefined) {
109+
overrides.host = options.host;
110+
} else if (typeof serverOptions.host === 'string') {
111+
options.host = serverOptions.host;
112+
} else {
113+
options.host = overrides.host = 'localhost';
114+
}
111115

116+
if (options.port !== undefined) {
117+
overrides.port = options.port;
118+
} else if (typeof serverOptions.port === 'number') {
119+
options.port = serverOptions.port;
120+
}
121+
122+
server = await context.scheduleTarget(target, overrides);
112123
let result;
113124
try {
114125
result = await server.result;

‎packages/angular_devkit/build_angular/src/protractor/schema.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@
4141
},
4242
"host": {
4343
"type": "string",
44-
"description": "Host to listen on.",
45-
"default": "localhost"
44+
"description": "Host to listen on."
4645
},
4746
"baseUrl": {
4847
"type": "string",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import * as os from 'os';
2+
import { killAllProcesses, ng } from '../../utils/process';
3+
import { updateJsonFile } from '../../utils/project';
4+
5+
export default async function () {
6+
const interfaces = [].concat.apply([], Object.values(os.networkInterfaces()));
7+
let host = '';
8+
for (const { family, address, internal } of interfaces) {
9+
if (family === 'IPv4' && !internal) {
10+
host = address;
11+
break;
12+
}
13+
}
14+
15+
try {
16+
await updateJsonFile('angular.json', workspaceJson => {
17+
const appArchitect = workspaceJson.projects['test-project'].architect;
18+
appArchitect.serve.options.port = 8888;
19+
appArchitect.serve.options.host = host;
20+
});
21+
22+
await ng('e2e');
23+
24+
await ng('e2e', '--host', host);
25+
} finally {
26+
await killAllProcesses();
27+
}
28+
}

0 commit comments

Comments
 (0)