SponsorBlockServer/test.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-04-01 22:04:04 +02:00
var Mocha = require('mocha'),
fs = require('fs'),
path = require('path');
2020-04-07 02:17:49 +02:00
var config = require('./src/config.js');
// delete old test database
2020-04-07 02:26:01 +02:00
if (fs.existsSync(config.db)) fs.unlinkSync(config.db);
if (fs.existsSync(config.privateDB)) fs.unlinkSync(config.privateDB);
2020-04-07 02:17:49 +02:00
2020-04-01 22:04:04 +02:00
var createServer = require('./src/app.js');
var createMockServer = require('./test/mocks.js');
2020-08-22 03:14:19 +02:00
const logger = require('./src/utils/logger.js');
2020-04-01 22:04:04 +02:00
// 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(() => {
2020-08-22 03:14:19 +02:00
logger.info("Started mock HTTP Server");
2020-04-01 22:04:04 +02:00
var server = createServer(() => {
2020-08-22 03:14:19 +02:00
logger.info("Started main HTTP server");
2020-04-01 22:04:04 +02:00
// Run the tests.
2020-09-08 18:37:29 +02:00
mocha.run((failures) => {
2020-04-01 22:04:04 +02:00
mockServer.close();
server.close();
2020-04-23 18:48:02 +02:00
process.exitCode = failures ? 1 : 0; // exit with non-zero status if there were failures
2020-04-01 22:04:04 +02:00
});
});
});