-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathindex.js
66 lines (50 loc) · 2.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Expose the gulp-angular-protractor plugin
*
* @author Julien Roche
* @version 0.0.1
* @since 0.0.1
*/
'use strict';
// Import required API
const fs = require('fs');
const path = require('path');
const _ = require('lodash');
const log = require('fancy-log');
const PluginError = require('plugin-error');
// Import internal API
const webDriverFactory = require('./gulp-angular-protractor/web-driver');
const gulpStream = require('./gulp-angular-protractor/gulp-stream');
const defaultOptions = require('./gulp-angular-protractor/default-options.json');
// Constants
const PLUGIN_NAME = require('./gulp-angular-protractor/constants.json').PLUGIN_NAME;
module.exports = function (options) {
log(PLUGIN_NAME + ' - The plugin is retrieved and will start soon');
let mergedOptions = _.extend({ }, defaultOptions, options);
let webDriver = webDriverFactory(mergedOptions.protractorModulePath);
var
protractorConfiguration,
webDriverUrl = webDriver.DEFAULT_WEB_DRIVER_URL;
if (!mergedOptions.configFile) {
throw new PluginError(PLUGIN_NAME, '`configFile` required');
}
if (!fs.existsSync(mergedOptions.configFile)) {
throw new PluginError(PLUGIN_NAME, 'The protractor configuration file specified by `configFile` does not exist');
}
if (mergedOptions.autoStartStopServer) {
log(PLUGIN_NAME + ' - We will try to start and stop automatically the WebDriver server');
protractorConfiguration = require(path.resolve(mergedOptions.configFile));
if (!protractorConfiguration || !protractorConfiguration.config) {
throw new PluginError(PLUGIN_NAME, 'No protractor configuration was exported');
}
if (protractorConfiguration.config.seleniumAddress) {
webDriverUrl = protractorConfiguration.config.seleniumAddress;
}
log(PLUGIN_NAME + ' - The selenium address is: ' + protractorConfiguration.config.seleniumAddress);
log(PLUGIN_NAME + ' - The selenium address used is: ' + webDriverUrl);
return gulpStream(mergedOptions, webDriverUrl, true, webDriver);
} else {
log(PLUGIN_NAME + ' - Basic use (as the gulp-protractor plugin).');
return gulpStream(mergedOptions, webDriverUrl, false, webDriver);
}
};