mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-06 19:47:00 +03:00
migrate to typescript
This commit is contained in:
committed by
Dainius Dauksevicius
parent
c462323dd5
commit
08d27265fc
44
test.ts
Normal file
44
test.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import Mocha from 'mocha';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import {config} from './src/config';
|
||||
import {createServer} from './src/app';
|
||||
import {createMockServer} from './test/mocks';
|
||||
import {Logger} from './src/utils/logger';
|
||||
import {initDb} from './src/databases/databases';
|
||||
|
||||
// delete old test database
|
||||
if (fs.existsSync(config.db)) fs.unlinkSync(config.db)
|
||||
if (fs.existsSync(config.privateDB)) fs.unlinkSync(config.privateDB);
|
||||
|
||||
initDb();
|
||||
|
||||
// Instantiate a Mocha instance.
|
||||
const mocha = new Mocha();
|
||||
|
||||
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)
|
||||
);
|
||||
});
|
||||
|
||||
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
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user