Skip to content

Protractor builder should use dev server supplied baseUrl when available #14376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions packages/angular_devkit/build_angular/src/dev-server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export function serveWebpackBrowser(
const browserTarget = targetFromTargetString(options.browserTarget);
const root = context.workspaceRoot;
let first = true;
let openAddress: string;
const host = new NodeJsSyncHost();

const loggingFn = transforms.logging
Expand Down Expand Up @@ -152,15 +151,6 @@ export function serveWebpackBrowser(
options.publicHost = clientAddress.host;
}

// Resolve serve address.
const serverAddress = url.format({
protocol: options.ssl ? 'https' : 'http',
hostname: options.host === '0.0.0.0' ? 'localhost' : options.host,
// Port cannot be undefined here since we have a step that sets it back in options above.
// tslint:disable-next-line:no-non-null-assertion
port: options.port !.toString(),
});

// Add live reload config.
if (options.liveReload) {
_addLiveReload(options, browserOptions, webpackConfig, clientAddress, context.logger);
Expand Down Expand Up @@ -193,24 +183,34 @@ export function serveWebpackBrowser(
`);
}

context.logger.info(tags.oneLine`
**
Angular Live Development Server is listening on ${options.host}:${options.port},
open your browser on ${serverAddress}${webpackDevServerConfig.publicPath}
**
`);

openAddress = serverAddress + webpackDevServerConfig.publicPath;

return runWebpackDevServer(webpackConfig, context, { logging: loggingFn });
}),
map(buildEvent => {
if (first && options.open) {
first = false;
open(openAddress);
}

return { ...buildEvent, baseUrl: openAddress } as DevServerBuilderOutput;
return runWebpackDevServer(webpackConfig, context, { logging: loggingFn }).pipe(
map(buildEvent => {
// Resolve serve address.
const serverAddress = url.format({
protocol: options.ssl ? 'https' : 'http',
hostname: options.host === '0.0.0.0' ? 'localhost' : options.host,
pathname: webpackDevServerConfig.publicPath,
port: buildEvent.port,
});

if (first) {
first = false;

context.logger.info(tags.oneLine`
**
Angular Live Development Server is listening on ${options.host}:${options.port},
open your browser on ${serverAddress}
**
`);

if (options.open) {
open(serverAddress);
}
}

return { ...buildEvent, baseUrl: serverAddress } as DevServerBuilderOutput;
}),
);
}),
);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/angular_devkit/build_angular/src/protractor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ async function execute(
}
const clientUrl = url.parse(publicHost);
baseUrl = url.format(clientUrl);
} else if (typeof result.baseUrl === 'string') {
baseUrl = result.baseUrl;
} else if (typeof result.port === 'number') {
baseUrl = url.format({
protocol: serverOptions.ssl ? 'https' : 'http',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,20 @@ describe('Protractor Builder', () => {
await run.stop();
}, 30000);

it('supports dev server builder with browser builder base HREF option', async () => {
host.replaceInFile(
'angular.json',
'"main": "src/main.ts",',
'"main": "src/main.ts", "baseHref": "/base/",',
);
// Need to reset architect to use the modified config
architect = (await createArchitect(host.root())).architect;

const run = await architect.scheduleTarget(protractorTargetSpec);

await expectAsync(run.result).toBeResolvedTo(jasmine.objectContaining({ success: true }));

await run.stop();
}, 30000);

});