mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-18 03:23:57 +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,
|
BuilderContext,
|
||||||
BuilderDescription,
|
BuilderDescription,
|
||||||
} from '@angular-devkit/architect';
|
} from '@angular-devkit/architect';
|
||||||
|
import { DevServerResult } from '@angular-devkit/build-webpack';
|
||||||
import { Path, getSystemPath, normalize, resolve, tags } from '@angular-devkit/core';
|
import { Path, getSystemPath, normalize, resolve, tags } from '@angular-devkit/core';
|
||||||
import { Observable, from, of } from 'rxjs';
|
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 * as url from 'url';
|
||||||
import { requireProjectModule } from '../angular-cli-files/utilities/require-project-module';
|
import { requireProjectModule } from '../angular-cli-files/utilities/require-project-module';
|
||||||
import { DevServerBuilderOptions } from '../dev-server';
|
import { DevServerBuilderOptions } from '../dev-server';
|
||||||
@ -70,9 +71,15 @@ export class ProtractorBuilder implements Builder<ProtractorBuilderOptions> {
|
|||||||
|
|
||||||
return architect.getBuilderDescription(builderConfig).pipe(
|
return architect.getBuilderDescription(builderConfig).pipe(
|
||||||
tap(description => devServerDescription = description),
|
tap(description => devServerDescription = description),
|
||||||
concatMap(devServerDescription => architect.validateBuilderOptions(
|
concatMap(devServerDescription =>
|
||||||
builderConfig, devServerDescription)),
|
architect.validateBuilderOptions(builderConfig, devServerDescription)),
|
||||||
concatMap(() => {
|
map(() => this.context.architect.getBuilder(devServerDescription, this.context)),
|
||||||
|
concatMap(builder => builder.run(builderConfig)),
|
||||||
|
tap(buildEvent => {
|
||||||
|
if (!buildEvent.success) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Compute baseUrl from devServerOptions.
|
// Compute baseUrl from devServerOptions.
|
||||||
if (options.devServerTarget && builderConfig.options.publicHost) {
|
if (options.devServerTarget && builderConfig.options.publicHost) {
|
||||||
let publicHost = builderConfig.options.publicHost;
|
let publicHost = builderConfig.options.publicHost;
|
||||||
@ -84,19 +91,18 @@ export class ProtractorBuilder implements Builder<ProtractorBuilderOptions> {
|
|||||||
const clientUrl = url.parse(publicHost);
|
const clientUrl = url.parse(publicHost);
|
||||||
baseUrl = url.format(clientUrl);
|
baseUrl = url.format(clientUrl);
|
||||||
} else if (options.devServerTarget) {
|
} else if (options.devServerTarget) {
|
||||||
|
const result: DevServerResult | undefined = buildEvent.result;
|
||||||
|
|
||||||
baseUrl = url.format({
|
baseUrl = url.format({
|
||||||
protocol: builderConfig.options.ssl ? 'https' : 'http',
|
protocol: builderConfig.options.ssl ? 'https' : 'http',
|
||||||
hostname: options.host,
|
hostname: options.host,
|
||||||
port: builderConfig.options.port.toString(),
|
port: result && result.port.toString(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the computed baseUrl back so that Protractor can use it.
|
// Save the computed baseUrl back so that Protractor can use it.
|
||||||
options.baseUrl = baseUrl;
|
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);
|
).toPromise().then(done, done.fail);
|
||||||
}, 60000);
|
}, 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.
|
// TODO: test `element-explorer` when the protractor builder emits build events with text.
|
||||||
// .then(() => execAndWaitForOutputToMatch('ng', ['e2e', '--element-explorer'],
|
// .then(() => execAndWaitForOutputToMatch('ng', ['e2e', '--element-explorer'],
|
||||||
// /Element Explorer/))
|
// /Element Explorer/))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user