source: trip-planner-front/node_modules/@angular-devkit/build-angular/src/protractor/index.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 6.2 KB
Line 
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 */
9var __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}));
16var __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});
21var __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};
28Object.defineProperty(exports, "__esModule", { value: true });
29exports.execute = void 0;
30const architect_1 = require("@angular-devkit/architect");
31const core_1 = require("@angular-devkit/core");
32const path_1 = require("path");
33const url = __importStar(require("url"));
34const utils_1 = require("../utils");
35function 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}
53async 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 */
85async 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}
162exports.execute = execute;
163exports.default = architect_1.createBuilder(execute);
Note: See TracBrowser for help on using the repository browser.