mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-16 18:43:42 +08:00
feat(@angular-devkit/build-angular): add support for port 0 when using protractor
Fixes #13129
This commit is contained in:
parent
881966bbc8
commit
6db7038c1b
@ -13,9 +13,10 @@ import {
|
||||
BuilderContext,
|
||||
BuilderDescription,
|
||||
} from '@angular-devkit/architect';
|
||||
import { DevServerResult } from '@angular-devkit/build-webpack';
|
||||
import { Path, getSystemPath, normalize, resolve, tags } from '@angular-devkit/core';
|
||||
import { Observable, from, of } from 'rxjs';
|
||||
import { concatMap, take, tap } from 'rxjs/operators';
|
||||
import { concatMap, map, take, tap } from 'rxjs/operators';
|
||||
import * as url from 'url';
|
||||
import { requireProjectModule } from '../angular-cli-files/utilities/require-project-module';
|
||||
import { DevServerBuilderOptions } from '../dev-server';
|
||||
@ -70,9 +71,15 @@ export class ProtractorBuilder implements Builder<ProtractorBuilderOptions> {
|
||||
|
||||
return architect.getBuilderDescription(builderConfig).pipe(
|
||||
tap(description => devServerDescription = description),
|
||||
concatMap(devServerDescription => architect.validateBuilderOptions(
|
||||
builderConfig, devServerDescription)),
|
||||
concatMap(() => {
|
||||
concatMap(devServerDescription =>
|
||||
architect.validateBuilderOptions(builderConfig, devServerDescription)),
|
||||
map(() => this.context.architect.getBuilder(devServerDescription, this.context)),
|
||||
concatMap(builder => builder.run(builderConfig)),
|
||||
tap(buildEvent => {
|
||||
if (!buildEvent.success) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Compute baseUrl from devServerOptions.
|
||||
if (options.devServerTarget && builderConfig.options.publicHost) {
|
||||
let publicHost = builderConfig.options.publicHost;
|
||||
@ -84,19 +91,18 @@ export class ProtractorBuilder implements Builder<ProtractorBuilderOptions> {
|
||||
const clientUrl = url.parse(publicHost);
|
||||
baseUrl = url.format(clientUrl);
|
||||
} else if (options.devServerTarget) {
|
||||
const result: DevServerResult | undefined = buildEvent.result;
|
||||
|
||||
baseUrl = url.format({
|
||||
protocol: builderConfig.options.ssl ? 'https' : 'http',
|
||||
hostname: options.host,
|
||||
port: builderConfig.options.port.toString(),
|
||||
port: result && result.port.toString(),
|
||||
});
|
||||
}
|
||||
|
||||
// Save the computed baseUrl back so that Protractor can use it.
|
||||
options.baseUrl = baseUrl;
|
||||
|
||||
return of(this.context.architect.getBuilder(devServerDescription, this.context));
|
||||
}),
|
||||
concatMap(builder => builder.run(builderConfig)),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,12 @@ describe('Protractor Builder', () => {
|
||||
).toPromise().then(done, done.fail);
|
||||
}, 60000);
|
||||
|
||||
it('works with port 0', (done) => {
|
||||
runTargetSpec(host, protractorTargetSpec, { port: 0 }).pipe(
|
||||
retry(3),
|
||||
).toPromise().then(done, done.fail);
|
||||
}, 30000);
|
||||
|
||||
// TODO: test `element-explorer` when the protractor builder emits build events with text.
|
||||
// .then(() => execAndWaitForOutputToMatch('ng', ['e2e', '--element-explorer'],
|
||||
// /Element Explorer/))
|
||||
|
Loading…
x
Reference in New Issue
Block a user