forked from superdesk/superdesk-client-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-end-to-end-tests.js
60 lines (50 loc) · 1.82 KB
/
run-end-to-end-tests.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
const execSync = require('child_process').execSync;
function ensurePackageInstalled() {
return new Promise((resolve, reject) => {
try {
require.resolve('webdriver-manager');
resolve();
} catch (_) {
reject('Package "webdriver-manager" was not found. Run `yarn install` to install all packages.');
}
});
}
function installWebdriverDriver() {
return new Promise((resolve, reject) => {
try {
require.resolve('webdriver-manager/selenium/update-config.json');
resolve();
} catch (_) {
// driver not installed, installing:
let version = null;
try {
version = execSync('chromium-browser --product-version').toString();
} catch (_) {
// Chromium not installed
}
if (version == null) {
try {
version = execSync('google-chrome --product-version --product-version').toString();
} catch (_) {
// Google Chrome not installed
}
}
if (version == null) {
return reject('To launch the test server either Chromium or Google Chrome has to be installed.');
}
console.info('Installing webdriver...', version);
execSync(`npx webdriver-manager update --gecko false --standalone false --versions.chrome=${version}`);
resolve();
}
});
}
ensurePackageInstalled()
.then(installWebdriverDriver)
.then(() => {
const argumentsToForward = process.argv.slice(2).join(' ');
return execSync(`npx protractor protractor.conf.js ${argumentsToForward}`, {stdio: 'inherit'});
})
.catch((e) => {
console.error(e);
process.exitCode = 1;
});