-
Notifications
You must be signed in to change notification settings - Fork 4
/
runOne.js
61 lines (52 loc) · 1.47 KB
/
runOne.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
var Mocha = require('mocha'),
fs = require('fs'),
path = require('path'),
async = require('async');
var cp = require('child_process');
// Scan the 'test' directory for all JS files
var testDir = 'test';
var allTests = fs.readdirSync(testDir).filter(function(file){
// Only keep the .js files
return file.substr(-3) === '.js';
});
var student = process.argv[2];
var testsToRun = process.argv[3].split(',');
testsToRun.push('globals');
var allOptions = [ ];
if (process.argv[4]) {
allOptions = process.argv[4].split(',');
}
allOptions.forEach(function(option) {
process.env[option.toUpperCase()] = 1;
});
var url = 'http';
var port = 0;
for (let i = 0; i < allOptions.length; i++)
{
if (allOptions[i] == 'ssl')
url += 's';
else if (allOptions[i].substr(0,4) == 'port')
{
var args = allOptions[i].split('=');
if (args.length > 1)
port = args[1];
}
}
url += '://';
url += student.replace(".", "-");
url += '.cs261.net';
if (port)
url += port;
url += '/api/v1';
process.env.TEST_ROOT_URL = url;
process.env.TEST_ENDPOINTS = testsToRun;
process.env.TEST_ADMIN = 'TestAdmin';
process.env.TEST_ADMIN_PASSWORD = 'PixarGoodGhibliBETTER';
var mocha = new Mocha();
allTests.forEach(function(file) {
var suite = file.substring(0, file.length - 3);
if (testsToRun.indexOf(suite) >= 0) {
mocha.addFile(path.join(testDir, file));
}
});
mocha.run();