1 | "use strict";
|
---|
2 | /**
|
---|
3 | * @license
|
---|
4 | * Copyright Google LLC All Rights Reserved.
|
---|
5 | *
|
---|
6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
7 | * found in the LICENSE file at https://angular.io/license
|
---|
8 | */
|
---|
9 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
---|
10 | if (k2 === undefined) k2 = k;
|
---|
11 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
---|
12 | }) : (function(o, m, k, k2) {
|
---|
13 | if (k2 === undefined) k2 = k;
|
---|
14 | o[k2] = m[k];
|
---|
15 | }));
|
---|
16 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
---|
17 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
---|
18 | }) : function(o, v) {
|
---|
19 | o["default"] = v;
|
---|
20 | });
|
---|
21 | var __importStar = (this && this.__importStar) || function (mod) {
|
---|
22 | if (mod && mod.__esModule) return mod;
|
---|
23 | var result = {};
|
---|
24 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
---|
25 | __setModuleDefault(result, mod);
|
---|
26 | return result;
|
---|
27 | };
|
---|
28 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
29 | exports.execute = void 0;
|
---|
30 | const architect_1 = require("@angular-devkit/architect");
|
---|
31 | const core_1 = require("@angular-devkit/core");
|
---|
32 | const path_1 = require("path");
|
---|
33 | const url = __importStar(require("url"));
|
---|
34 | const utils_1 = require("../utils");
|
---|
35 | function runProtractor(root, options) {
|
---|
36 | const additionalProtractorConfig = {
|
---|
37 | baseUrl: options.baseUrl,
|
---|
38 | specs: options.specs && options.specs.length ? options.specs : undefined,
|
---|
39 | suite: options.suite,
|
---|
40 | jasmineNodeOpts: {
|
---|
41 | grep: options.grep,
|
---|
42 | invertGrep: options.invertGrep,
|
---|
43 | },
|
---|
44 | };
|
---|
45 | // TODO: Protractor manages process.exit itself, so this target will allways quit the
|
---|
46 | // process. To work around this we run it in a subprocess.
|
---|
47 | // https://github.com/angular/protractor/issues/4160
|
---|
48 | return utils_1.runModuleAsObservableFork(root, 'protractor/built/launcher', 'init', [
|
---|
49 | path_1.resolve(root, options.protractorConfig),
|
---|
50 | additionalProtractorConfig,
|
---|
51 | ]).toPromise();
|
---|
52 | }
|
---|
53 | async function updateWebdriver() {
|
---|
54 | // The webdriver-manager update command can only be accessed via a deep import.
|
---|
55 | const webdriverDeepImport = 'webdriver-manager/built/lib/cmds/update';
|
---|
56 | let path;
|
---|
57 | try {
|
---|
58 | const protractorPath = require.resolve('protractor');
|
---|
59 | path = require.resolve(webdriverDeepImport, { paths: [protractorPath] });
|
---|
60 | }
|
---|
61 | catch (error) {
|
---|
62 | if (error.code !== 'MODULE_NOT_FOUND') {
|
---|
63 | throw error;
|
---|
64 | }
|
---|
65 | }
|
---|
66 | if (!path) {
|
---|
67 | throw new Error(core_1.tags.stripIndents `
|
---|
68 | Cannot automatically find webdriver-manager to update.
|
---|
69 | Update webdriver-manager manually and run 'ng e2e --no-webdriver-update' instead.
|
---|
70 | `);
|
---|
71 | }
|
---|
72 | const webdriverUpdate = await Promise.resolve().then(() => __importStar(require(path)));
|
---|
73 | // const webdriverUpdate = await import(path) as typeof import ('webdriver-manager/built/lib/cmds/update');
|
---|
74 | // run `webdriver-manager update --standalone false --gecko false --quiet`
|
---|
75 | // if you change this, update the command comment in prev line
|
---|
76 | return webdriverUpdate.program.run({
|
---|
77 | standalone: false,
|
---|
78 | gecko: false,
|
---|
79 | quiet: true,
|
---|
80 | });
|
---|
81 | }
|
---|
82 | /**
|
---|
83 | * @experimental Direct usage of this function is considered experimental.
|
---|
84 | */
|
---|
85 | async function execute(options, context) {
|
---|
86 | context.logger.warn('Protractor has been deprecated including its support in the Angular CLI. For additional information and alternatives, please see https://github.com/angular/protractor/issues/5502.');
|
---|
87 | // ensure that only one of these options is used
|
---|
88 | if (options.devServerTarget && options.baseUrl) {
|
---|
89 | throw new Error(core_1.tags.stripIndents `
|
---|
90 | The 'baseUrl' option cannot be used with 'devServerTarget'.
|
---|
91 | When present, 'devServerTarget' will be used to automatically setup 'baseUrl' for Protractor.
|
---|
92 | `);
|
---|
93 | }
|
---|
94 | if (options.webdriverUpdate) {
|
---|
95 | await updateWebdriver();
|
---|
96 | }
|
---|
97 | let baseUrl = options.baseUrl;
|
---|
98 | let server;
|
---|
99 | if (options.devServerTarget) {
|
---|
100 | const target = architect_1.targetFromTargetString(options.devServerTarget);
|
---|
101 | const serverOptions = await context.getTargetOptions(target);
|
---|
102 | const overrides = {
|
---|
103 | watch: false,
|
---|
104 | liveReload: false,
|
---|
105 | };
|
---|
106 | if (options.host !== undefined) {
|
---|
107 | overrides.host = options.host;
|
---|
108 | }
|
---|
109 | else if (typeof serverOptions.host === 'string') {
|
---|
110 | options.host = serverOptions.host;
|
---|
111 | }
|
---|
112 | else {
|
---|
113 | options.host = overrides.host = 'localhost';
|
---|
114 | }
|
---|
115 | if (options.port !== undefined) {
|
---|
116 | overrides.port = options.port;
|
---|
117 | }
|
---|
118 | else if (typeof serverOptions.port === 'number') {
|
---|
119 | options.port = serverOptions.port;
|
---|
120 | }
|
---|
121 | server = await context.scheduleTarget(target, overrides);
|
---|
122 | const result = await server.result;
|
---|
123 | if (!result.success) {
|
---|
124 | return { success: false };
|
---|
125 | }
|
---|
126 | if (typeof serverOptions.publicHost === 'string') {
|
---|
127 | let publicHost = serverOptions.publicHost;
|
---|
128 | if (!/^\w+:\/\//.test(publicHost)) {
|
---|
129 | publicHost = `${serverOptions.ssl ? 'https' : 'http'}://${publicHost}`;
|
---|
130 | }
|
---|
131 | const clientUrl = url.parse(publicHost);
|
---|
132 | baseUrl = url.format(clientUrl);
|
---|
133 | }
|
---|
134 | else if (typeof result.baseUrl === 'string') {
|
---|
135 | baseUrl = result.baseUrl;
|
---|
136 | }
|
---|
137 | else if (typeof result.port === 'number') {
|
---|
138 | baseUrl = url.format({
|
---|
139 | protocol: serverOptions.ssl ? 'https' : 'http',
|
---|
140 | hostname: options.host,
|
---|
141 | port: result.port.toString(),
|
---|
142 | });
|
---|
143 | }
|
---|
144 | }
|
---|
145 | // Like the baseUrl in protractor config file when using the API we need to add
|
---|
146 | // a trailing slash when provide to the baseUrl.
|
---|
147 | if (baseUrl && !baseUrl.endsWith('/')) {
|
---|
148 | baseUrl += '/';
|
---|
149 | }
|
---|
150 | try {
|
---|
151 | return await runProtractor(context.workspaceRoot, { ...options, baseUrl });
|
---|
152 | }
|
---|
153 | catch {
|
---|
154 | return { success: false };
|
---|
155 | }
|
---|
156 | finally {
|
---|
157 | if (server) {
|
---|
158 | await server.stop();
|
---|
159 | }
|
---|
160 | }
|
---|
161 | }
|
---|
162 | exports.execute = execute;
|
---|
163 | exports.default = architect_1.createBuilder(execute);
|
---|