diff --git a/packages/angular_devkit/build_angular/src/protractor/index.ts b/packages/angular_devkit/build_angular/src/protractor/index.ts index c57d44d9010b..940f49f5475a 100644 --- a/packages/angular_devkit/build_angular/src/protractor/index.ts +++ b/packages/angular_devkit/build_angular/src/protractor/index.ts @@ -105,10 +105,21 @@ async function execute( const serverOptions = await context.getTargetOptions(target); const overrides: Record = { watch: false }; - if (options.host !== undefined) { overrides.host = options.host; } - if (options.port !== undefined) { overrides.port = options.port; } - server = await context.scheduleTarget(target, overrides); + if (options.host !== undefined) { + overrides.host = options.host; + } else if (typeof serverOptions.host === 'string') { + options.host = serverOptions.host; + } else { + options.host = overrides.host = 'localhost'; + } + if (options.port !== undefined) { + overrides.port = options.port; + } else if (typeof serverOptions.port === 'number') { + options.port = serverOptions.port; + } + + server = await context.scheduleTarget(target, overrides); let result; try { result = await server.result; diff --git a/packages/angular_devkit/build_angular/src/protractor/schema.json b/packages/angular_devkit/build_angular/src/protractor/schema.json index 1303da5b2511..4aea8deaecbc 100644 --- a/packages/angular_devkit/build_angular/src/protractor/schema.json +++ b/packages/angular_devkit/build_angular/src/protractor/schema.json @@ -41,8 +41,7 @@ }, "host": { "type": "string", - "description": "Host to listen on.", - "default": "localhost" + "description": "Host to listen on." }, "baseUrl": { "type": "string", diff --git a/tests/legacy-cli/e2e/tests/misc/e2e-host.ts b/tests/legacy-cli/e2e/tests/misc/e2e-host.ts new file mode 100644 index 000000000000..08d3a76712ae --- /dev/null +++ b/tests/legacy-cli/e2e/tests/misc/e2e-host.ts @@ -0,0 +1,28 @@ +import * as os from 'os'; +import { killAllProcesses, ng } from '../../utils/process'; +import { updateJsonFile } from '../../utils/project'; + +export default async function () { + const interfaces = [].concat.apply([], Object.values(os.networkInterfaces())); + let host = ''; + for (const { family, address, internal } of interfaces) { + if (family === 'IPv4' && !internal) { + host = address; + break; + } + } + + try { + await updateJsonFile('angular.json', workspaceJson => { + const appArchitect = workspaceJson.projects['test-project'].architect; + appArchitect.serve.options.port = 8888; + appArchitect.serve.options.host = host; + }); + + await ng('e2e'); + + await ng('e2e', '--host', host); + } finally { + await killAllProcesses(); + } +}