mirror of
https://github.com/bpatrik/pigallery2.git
synced 2025-01-08 04:03:48 +02:00
Improving integration tests.
This commit is contained in:
parent
78b72e2528
commit
ed0ea40758
@ -36,7 +36,7 @@ export class ExtensionManager implements IObjectManager {
|
||||
return;
|
||||
}
|
||||
this.router = express.Router();
|
||||
Server.getInstance().app.use(ExtensionManager.EXTENSION_API_PATH, this.router);
|
||||
Server.instance?.app.use(ExtensionManager.EXTENSION_API_PATH, this.router);
|
||||
this.loadExtensionsList();
|
||||
await this.initExtensions();
|
||||
}
|
||||
@ -163,7 +163,7 @@ export class ExtensionManager implements IObjectManager {
|
||||
}
|
||||
this.initEvents(); // reset events
|
||||
await this.cleanUpExtensions();
|
||||
Server.getInstance().app.use(ExtensionManager.EXTENSION_API_PATH, express.Router());
|
||||
Server.instance?.app.use(ExtensionManager.EXTENSION_API_PATH, this.router);
|
||||
this.extObjects = {};
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ export class Server {
|
||||
public app: express.Express;
|
||||
private server: HttpServer;
|
||||
|
||||
static instance: Server = null;
|
||||
public static instance: Server = null;
|
||||
|
||||
public static getInstance(): Server {
|
||||
if (!this.instance) {
|
||||
@ -148,18 +148,21 @@ export class Server {
|
||||
this.server.on('close', this.onClose);
|
||||
|
||||
// Sigterm handler
|
||||
process.on('SIGTERM', () => {
|
||||
Logger.info(LOG_TAG, 'SIGTERM signal received');
|
||||
this.server.close(() => {
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
process.removeAllListeners('SIGTERM');
|
||||
process.on('SIGTERM', this.SIGTERM);
|
||||
|
||||
if (!listen) {
|
||||
this.onStarted.trigger();
|
||||
}
|
||||
}
|
||||
|
||||
private SIGTERM = () =>{
|
||||
Logger.info(LOG_TAG, 'SIGTERM signal received');
|
||||
this.server.close(() => {
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener for HTTP server "error" event.
|
||||
*/
|
||||
|
@ -2,11 +2,10 @@
|
||||
import {ServerConfig} from './PrivateConfig';
|
||||
import * as crypto from 'crypto';
|
||||
import * as path from 'path';
|
||||
import {ConfigClass, ConfigClassBuilder} from 'typeconfig/node';
|
||||
import {ConfigClass} from 'typeconfig/node';
|
||||
import {IConfigClass} from 'typeconfig/common';
|
||||
import {PasswordHelper} from '../../../backend/model/PasswordHelper';
|
||||
import {TAGS} from '../public/ClientConfig';
|
||||
import {NotificationManager} from '../../../backend/model/NotifocationManager';
|
||||
|
||||
declare const process: any;
|
||||
const upTime = new Date().toISOString();
|
||||
|
@ -50,7 +50,6 @@ describe('PublicRouter', () => {
|
||||
await SQLConnection.close();
|
||||
};
|
||||
const tearDown = async () => {
|
||||
await server.Stop();
|
||||
await ObjectManagers.reset();
|
||||
await fs.promises.rm(TestHelper.TMP_DIR, {recursive: true, force: true});
|
||||
};
|
||||
|
@ -12,6 +12,7 @@ import {RouteTestingHelper} from './RouteTestingHelper';
|
||||
import {QueryParams} from '../../../../src/common/QueryParams';
|
||||
import {ErrorCodes} from '../../../../src/common/entities/Error';
|
||||
import {DatabaseType} from '../../../../src/common/config/private/PrivateConfig';
|
||||
import {ProjectPath} from '../../../../src/backend/ProjectPath';
|
||||
|
||||
|
||||
process.env.NODE_ENV = 'test';
|
||||
@ -38,6 +39,7 @@ describe('SharingRouter', () => {
|
||||
Config.Sharing.enabled = true;
|
||||
Config.Database.type = DatabaseType.sqlite;
|
||||
Config.Database.dbFolder = tempDir;
|
||||
ProjectPath.reset();
|
||||
|
||||
server = new Server(false);
|
||||
await server.onStarted.wait();
|
||||
@ -47,7 +49,6 @@ describe('SharingRouter', () => {
|
||||
await SQLConnection.close();
|
||||
};
|
||||
const tearDown = async () => {
|
||||
await server.Stop();
|
||||
await ObjectManagers.reset();
|
||||
await fs.promises.rm(tempDir, {recursive: true, force: true});
|
||||
};
|
||||
|
@ -39,7 +39,6 @@ describe('UserRouter', () => {
|
||||
Config.Database.dbFolder = tempDir;
|
||||
ProjectPath.reset();
|
||||
|
||||
|
||||
server = new Server(false);
|
||||
await server.onStarted.wait();
|
||||
await ObjectManagers.getInstance().init();
|
||||
@ -47,7 +46,6 @@ describe('UserRouter', () => {
|
||||
await SQLConnection.close();
|
||||
};
|
||||
const tearDown = async () => {
|
||||
await server.Stop();
|
||||
await ObjectManagers.reset();
|
||||
await fs.promises.rm(tempDir, {recursive: true, force: true});
|
||||
};
|
||||
|
@ -1,4 +1,3 @@
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import {Config} from '../../../../../src/common/config/private/Config';
|
||||
import {Server} from '../../../../../src/backend/server';
|
||||
@ -9,8 +8,6 @@ import {ObjectManagers} from '../../../../../src/backend/model/ObjectManagers';
|
||||
import {UserRoles} from '../../../../../src/common/entities/UserDTO';
|
||||
import {ExtensionConfigWrapper} from '../../../../../src/backend/model/extension/ExtensionConfigWrapper';
|
||||
import {TestHelper} from '../../../../TestHelper';
|
||||
import {Utils} from '../../../../../src/common/Utils';
|
||||
import {SQLConnection} from '../../../../../src/backend/model/database/SQLConnection';
|
||||
|
||||
process.env.NODE_ENV = 'test';
|
||||
const chai: any = require('chai');
|
||||
@ -29,13 +26,11 @@ describe('SettingsRouter', () => {
|
||||
|
||||
server = new Server(false);
|
||||
await server.onStarted.wait();
|
||||
console.log('done');
|
||||
await ObjectManagers.getInstance().init();
|
||||
});
|
||||
|
||||
|
||||
afterEach(async () => {
|
||||
await server.Stop();
|
||||
await ObjectManagers.reset();
|
||||
await fs.promises.rm(TestHelper.TMP_DIR, {recursive: true, force: true});
|
||||
});
|
||||
@ -44,9 +39,8 @@ describe('SettingsRouter', () => {
|
||||
it('it should GET the settings', async () => {
|
||||
Config.Users.authenticationRequired = false;
|
||||
Config.Users.unAuthenticatedUserRole = UserRoles.Admin;
|
||||
const originalSettings = await ExtensionConfigWrapper.original();
|
||||
const originalSettings = await ExtensionConfigWrapper.original();
|
||||
|
||||
console.log('testing');
|
||||
const result = await chai.request(server.Server)
|
||||
.get(Config.Server.apiPath + '/settings');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user