-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
39 lines (37 loc) · 961 Bytes
/
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
exports.executeTest = (event, context, callback) => {
let testUrl;
testUrl = getTestUrl(event, testUrl);
process.env["baseUrl"] = testUrl;
runMochaTests();
callback(null, { body: "Execution completed..." });
};
async function runMochaTests() {
var Mocha = require("mocha"),
fs = require("fs"),
path = require("path");
var mocha = new Mocha({
reporter: "mochawesome",
reporterOptions: {
reportDir: "/tmp"
}
});
var testDir = "./test/";
fs
.readdirSync(testDir)
.filter(function(file) {
return file.substr(-3) === ".js";
})
.forEach(function(file) {
mocha.addFile(path.join(testDir, file));
});
await mocha.run();
delete require.cache[require.resolve("./test/sampleWebdriver.js")];
}
function getTestUrl(event, testUrl) {
if (event.queryStringParameters.url === null) {
testUrl = event.url;
} else {
testUrl = event.queryStringParameters.url;
}
return testUrl;
}