1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const SilentError = require('silent-error');
|
4 | const override_options_1 = require("../utilities/override-options");
|
5 | const config_1 = require("../models/config");
|
6 | const serve_1 = require("./serve");
|
7 | const check_port_1 = require("../utilities/check-port");
|
8 | const common_tags_1 = require("common-tags");
|
9 | const Command = require('../ember-cli/lib/models/command');
|
10 | const E2eCommand = Command.extend({
|
11 | name: 'e2e',
|
12 | aliases: ['e'],
|
13 | description: 'Run e2e tests in existing project.',
|
14 | works: 'insideProject',
|
15 | availableOptions: override_options_1.overrideOptions([
|
16 | ...serve_1.baseServeCommandOptions,
|
17 | {
|
18 | name: 'config',
|
19 | type: String,
|
20 | aliases: ['c'],
|
21 | description: common_tags_1.oneLine `
|
22 | Use a specific config file.
|
23 | Defaults to the protractor config file in angular-cli.json.
|
24 | `
|
25 | },
|
26 | {
|
27 | name: 'specs',
|
28 | type: Array,
|
29 | default: [],
|
30 | aliases: ['sp'],
|
31 | description: common_tags_1.oneLine `
|
32 | Override specs in the protractor config.
|
33 | Can send in multiple specs by repeating flag (ng e2e --specs=spec1.ts --specs=spec2.ts).
|
34 | `
|
35 | },
|
36 | {
|
37 | name: 'element-explorer',
|
38 | type: Boolean,
|
39 | default: false,
|
40 | aliases: ['ee'],
|
41 | description: 'Start Protractor\'s Element Explorer for debugging.'
|
42 | },
|
43 | {
|
44 | name: 'webdriver-update',
|
45 | type: Boolean,
|
46 | default: true,
|
47 | aliases: ['wu'],
|
48 | description: 'Try to update webdriver.'
|
49 | },
|
50 | {
|
51 | name: 'serve',
|
52 | type: Boolean,
|
53 | default: true,
|
54 | aliases: ['s'],
|
55 | description: common_tags_1.oneLine `
|
56 | Compile and Serve the app.
|
57 | All non-reload related serve options are also available (e.g. --port=4400).
|
58 | `
|
59 | }
|
60 | ], [
|
61 | {
|
62 | name: 'port',
|
63 | default: 0,
|
64 | description: 'The port to use to serve the application.'
|
65 | },
|
66 | {
|
67 | name: 'watch',
|
68 | default: false,
|
69 | description: 'Run build when files change.'
|
70 | },
|
71 | ]),
|
72 | run: function (commandOptions) {
|
73 | const E2eTask = require('../tasks/e2e').E2eTask;
|
74 | this.project.ngConfig = this.project.ngConfig || config_1.CliConfig.fromProject();
|
75 | const e2eTask = new E2eTask({
|
76 | ui: this.ui,
|
77 | project: this.project
|
78 | });
|
79 | if (!commandOptions.config) {
|
80 | const e2eConfig = config_1.CliConfig.fromProject().config.e2e;
|
81 | if (!e2eConfig.protractor.config) {
|
82 | throw new SilentError('No protractor config found in .angular-cli.json.');
|
83 | }
|
84 | commandOptions.config = e2eConfig.protractor.config;
|
85 | }
|
86 | if (commandOptions.serve) {
|
87 | const ServeTask = require('../tasks/serve').default;
|
88 | const serve = new ServeTask({
|
89 | ui: this.ui,
|
90 | project: this.project,
|
91 | });
|
92 |
|
93 | return new Promise((resolve, reject) => {
|
94 | let firstRebuild = true;
|
95 | function rebuildCb() {
|
96 |
|
97 | if (firstRebuild) {
|
98 | firstRebuild = false;
|
99 | return resolve(e2eTask.run(commandOptions));
|
100 | }
|
101 | }
|
102 | check_port_1.checkPort(commandOptions.port, commandOptions.host)
|
103 | .then((port) => commandOptions.port = port)
|
104 | .then(() => serve.run(commandOptions, rebuildCb))
|
105 | .catch(reject);
|
106 | });
|
107 | }
|
108 | else {
|
109 | return e2eTask.run(commandOptions);
|
110 | }
|
111 | }
|
112 | });
|
113 | exports.default = E2eCommand;
|
114 |
|
\ | No newline at end of file |