-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
74 lines (66 loc) · 2.01 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
67
68
69
70
71
72
73
74
#!/usr/bin/env node
"use strict";
var program = require("commander");
program
.version("0.0.1")
.option("-r, --root <root>", "root folder for the files to serve")
.option("-e, --entry <entry>", "Entry html file to serve to run the mocha tests")
.option("-b, --browser <browser>", "browser to run the test on e.g. firefox")
.parse(process.argv);
var root = program.root;
var entry = program.entry;
var browser = program.browser || "firefox";
var port = 1337;
var koa = require("koa");
var app = koa();
app.use(require("koa-static")(root));
var server = app.listen(port);
var Mocha = require("mocha");
var mocha = new Mocha({
ui: 'bdd',
reporter: 'spec'
});
var EventEmitter = require("events");
var ee = new EventEmitter();
new mocha._reporter(ee);
var webdriver = require("selenium-webdriver");
var driver = new webdriver.Builder()
.usingServer("http://" + process.env.SAUCE_USERNAME + ':' + process.env.SAUCE_ACCESS_KEY + "@ondemand.saucelabs.com/wd/hub")
.forBrowser(browser)
.build();
driver.get("http://localhost:" + port + "/" + entry);
driver.wait(function() {
return driver.executeScript("return mocha.suite.pending").then(function(pending) {
return pending === false;
});
}, 10000);
var fs = require('fs');
var parseEventsScript = fs.readFileSync(__dirname + '/parseEvents.js', 'utf8');
driver
.executeScript(parseEventsScript)
.then(function (events) {
events = JSON.parse(events);
events.forEach(function (evt) {
if (evt[1] !== null) {
evt[1].slow = evt[1].slow !== null ? function () {
return evt[1].slow;
} : undefined;
evt[1]._fullTitle = evt[1].fullTitle;
evt[1].fullTitle = function () {
return evt[1]._fullTitle;
};
evt[1].slow = function () {
return evt[1]._slow;
};
}
if (evt[0] === "fail") {
ee.emit(evt[0], evt[1], evt[1].err);
} else {
ee.emit(evt[0], evt[1]);
}
if (evt[0] === "end") {
driver.quit();
server.close();
}
});
});