Added testing

This commit is contained in:
Joe-Dowd
2020-04-01 21:04:04 +01:00
parent 1bff019a64
commit 5369d48eae
23 changed files with 1388 additions and 517 deletions

35
test.js Normal file
View File

@@ -0,0 +1,35 @@
var Mocha = require('mocha'),
fs = require('fs'),
path = require('path');
var createServer = require('./src/app.js');
var createMockServer = require('./test/mocks.js');
// Instantiate a Mocha instance.
var mocha = new Mocha();
var testDir = './test/cases'
// Add each .js file to the mocha instance
fs.readdirSync(testDir).filter(function(file) {
// Only keep the .js files
return file.substr(-3) === '.js';
}).forEach(function(file) {
mocha.addFile(
path.join(testDir, file)
);
});
var mockServer = createMockServer(() => {
console.log("Started mock HTTP Server");
var server = createServer(() => {
console.log("Started main HTTP server");
// Run the tests.
mocha.run(function(failures) {
mockServer.close();
server.close();
process.exitCode = failures ? 1 : 0; // exit with non-zero status if there were failures
});
});
});