mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-10 13:37:01 +03:00
Make tests pass running with postgres
This commit is contained in:
70
test/test.ts
70
test/test.ts
@@ -10,44 +10,48 @@ import {ImportMock} from 'ts-mock-imports';
|
||||
import * as rateLimitMiddlewareModule from '../src/middleware/requestRateLimit';
|
||||
import rateLimit from 'express-rate-limit';
|
||||
|
||||
ImportMock.mockFunction(rateLimitMiddlewareModule, 'rateLimitMiddleware', rateLimit({
|
||||
skip: () => {
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
async function init() {
|
||||
ImportMock.mockFunction(rateLimitMiddlewareModule, 'rateLimitMiddleware', rateLimit({
|
||||
skip: () => {
|
||||
return true;
|
||||
}
|
||||
}));
|
||||
|
||||
// delete old test database
|
||||
if (fs.existsSync(config.db)) fs.unlinkSync(config.db)
|
||||
if (fs.existsSync(config.privateDB)) fs.unlinkSync(config.privateDB);
|
||||
// delete old test database
|
||||
if (fs.existsSync(config.db)) fs.unlinkSync(config.db)
|
||||
if (fs.existsSync(config.privateDB)) fs.unlinkSync(config.privateDB);
|
||||
|
||||
initDb();
|
||||
await initDb();
|
||||
|
||||
// Instantiate a Mocha instance.
|
||||
const mocha = new Mocha();
|
||||
// Instantiate a Mocha instance.
|
||||
const mocha = new Mocha();
|
||||
|
||||
const testDir = './test/cases';
|
||||
const testDir = './test/cases';
|
||||
|
||||
// Add each .ts file to the mocha instance
|
||||
fs.readdirSync(testDir)
|
||||
.filter(function(file) {
|
||||
// Only keep the .ts files
|
||||
return file.substr(-3) === '.ts';
|
||||
})
|
||||
.forEach(function(file) {
|
||||
mocha.addFile(
|
||||
path.join(testDir, file)
|
||||
);
|
||||
});
|
||||
// Add each .ts file to the mocha instance
|
||||
fs.readdirSync(testDir)
|
||||
.filter(function(file) {
|
||||
// Only keep the .ts files
|
||||
return file.substr(-3) === '.ts';
|
||||
})
|
||||
.forEach(function(file) {
|
||||
mocha.addFile(
|
||||
path.join(testDir, file)
|
||||
);
|
||||
});
|
||||
|
||||
const mockServer = createMockServer(() => {
|
||||
Logger.info("Started mock HTTP Server");
|
||||
const server = createServer(() => {
|
||||
Logger.info("Started main HTTP server");
|
||||
// Run the tests.
|
||||
mocha.run((failures) => {
|
||||
mockServer.close();
|
||||
server.close();
|
||||
process.exitCode = failures ? 1 : 0; // exit with non-zero status if there were failures
|
||||
const mockServer = createMockServer(() => {
|
||||
Logger.info("Started mock HTTP Server");
|
||||
const server = createServer(() => {
|
||||
Logger.info("Started main HTTP server");
|
||||
// Run the tests.
|
||||
mocha.run((failures) => {
|
||||
mockServer.close();
|
||||
server.close();
|
||||
process.exitCode = failures ? 1 : 0; // exit with non-zero status if there were failures
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
init();
|
||||
Reference in New Issue
Block a user