-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.js
75 lines (50 loc) · 1.46 KB
/
test.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
75
/*
* NodeJS Seedlink Proxy test
*
* Code that initializes the test suite
*
* Copyright: ORFEUS Data Center, 2018
* Author: Mathijs Koymans
* Licensed under MIT
*
*/
"use strict";
require("./require");
if(require.main === module) {
var { Server } = require("./lib/seedlink-websocket");
var configuration = require("./config");
// Set debug to false
configuration.__DEBUG__ = false;
new Server(configuration, function() {
console.log(this.name + " microservice has been started on " + this.host + ":" + this.port);
// Run all tests and close the socket at the end
runTests(Object.values(require("./test/testSuite")), this.close.bind(this));
});
}
function runTests(testSuite, callback) {
/*
* Function runTests
* Runs an array of asynchronous tests in sequence
*/
var next, currentTest;
var nTests = testSuite.length;
console.log("Begin running test suite with " + nTests + " tests.");
(next = function() {
var start = Date.now();
// No more tests to run
if(testSuite.length === 0) {
return callback();
}
// Pop the next test off the stack and execute
currentTest = testSuite.pop();
currentTest(function(error) {
// One test has failed
if(error) {
throw(currentTest.name + " " + error.stack);
}
console.log(currentTest.name + " succesfully completed in " + (Date.now() - start) + "ms.");
// Proceed with the next test
next();
});
})();
}