This repository was archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
84 lines (77 loc) · 3.18 KB
/
app.js
File metadata and controls
84 lines (77 loc) · 3.18 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict'
const fs = require('fs'),
fsExtra = require('fs-extra'),
sleep = require('system-sleep'),
spawn = require('child_process').exec,
shell = require('shelljs'),
path = require('path'),
fileExists = require('file-exists');
var testToRun = process.argv[2] || 'EndToEnd';
//Setup Selenium
var logdir = new Date().getTime();
try{
fs.mkdirSync("logs");
fs.mkdirSync("screenshots");
} catch(e){
console.info("logs already created");
}
fs.mkdirSync("logs/"+logdir);
spawn("./node_modules/.bin/selenium-standalone install && ./node_modules/.bin/selenium-standalone start > logs/"+logdir+"/selenium.log");
spawn("xvfb-run --server-args='-screen 0, 1024x768x16' ./node_modules/chromedriver/bin/chromedriver --port=19515 --verbose > logs/"+logdir+"/chromedriver.log");
function runTests(loopCount){
if (fileExists("logs/"+logdir+"/selenium.log")) {
//Get Available Tests
function getDirectories() {
return fs.readdirSync('testStories').filter(function(file) {
return fs.statSync(path.join('test', file)).isDirectory();
});
}
var testList = getDirectories();
var failedRun = false;
if(testList.indexOf(testToRun) == -1){
console.error("Running Tests End To End Tests ");
let startTest = function(testIndex){
if(!testList[testIndex]){
if(failedRun){
process.exit(1);
}else{
process.exit(0);
}
}
let test = testList[testIndex];
fsExtra.remove("screenshots/"+test, function(){
fs.mkdirSync("screenshots/"+test)
});;
shell.exec("./node_modules/mocha/bin/_mocha test/"+test+"/test.js --reporter mochawesome --reporter-options reportDir=mochawesome-reports/"+test+",reportName="+test+",reportTitle="+test+",inlineAssets=false", function(){
let resultReport = require('./mochawesome-reports/'+test+'/'+test+'.json');
if(resultReport.stats.failures > 0){
failedRun = true;
}
startTest((testIndex+1))
});
};
startTest(0)
}else{
console.error("Running Tests Just for: "+ testToRun);
try{
fsExtra.emptyDir("screenshots/"+testToRun);
fs.mkdirSync("screenshots/"+testToRun);
}catch(e){
console.error('Directory screenshots/'+testToRun+ ' is Setup.')
}
shell.exec("./node_modules/mocha/bin/_mocha test/"+testToRun+"/test.js --reporter mochawesome", function(){
let resultReport = require('./mochawesome-reports/mochawesome.json');
process.exit(resultReport.stats.failures);
});
}
}else if(loopCount > 60){
console.error('Selenium Server Never started');
process.exit('0');
}else{
sleep(1000);
console.error('Checking if Selenium has started ('+logdir+') - Check: #' + loopCount);
runTests(loopCount+1);
}
}
//runTests
runTests(0);