Skip to content

Commit

Permalink
test: fix unit and e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowusr committed Nov 21, 2023
1 parent 6477f53 commit 0988ef6
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion lib/cli-commands/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const {cliCommands} = require('.');
const runGui = require('../gui').default;
const Api = require('../gui/api');
const {Api} = require('../gui/api');

const {GUI: commandName} = cliCommands;

Expand Down
10 changes: 4 additions & 6 deletions lib/gui/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@ import {ApiFacade} from './facade';
import Hermione from 'hermione';
import {Express} from 'express';

interface GuiFacade {
gui: ApiFacade;
}

export interface ServerReadyData {
url: string;
}

type HermioneWithGui = Hermione & { gui: ApiFacade };

export class Api {
private _gui: ApiFacade;

static create<T extends Api>(this: new (hermione: Hermione & GuiFacade) => T, hermione: Hermione & GuiFacade): T {
static create<T extends Api>(this: new (hermione: HermioneWithGui) => T, hermione: HermioneWithGui): T {
return new this(hermione);
}

constructor(hermione: Hermione & GuiFacade) {
constructor(hermione: HermioneWithGui) {
this._gui = hermione.gui = ApiFacade.create();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/gui/routes/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from '../../server-utils';
import {ReporterConfig} from '../../types';

export const initPluginsRoutes = (router: Router, pluginConfig: ReporterConfig): Router =>{
export const initPluginsRoutes = (router: Router, pluginConfig: ReporterConfig): Router => {
if (!pluginConfig.pluginsEnabled) {
return router;
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/gui/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const EventEmitter2 = require('eventemitter2');
const {GuiEvents} = require('lib/gui/constants/gui-events');
const Api = require('lib/gui/api');
const {Api} = require('lib/gui/api');
const {stubTool} = require('../../../utils');

describe('lig/gui/api', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/gui/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('lib/gui/app', () => {

App = proxyquire('lib/gui/app', {
'looks-same': looksSame
});
}).App;

sandbox.stub(ToolRunner, 'create').returns(toolRunner);
});
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/gui/routes/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('lib/gui/routes/plugins', () => {
return router;
}
}
});
}).initPluginsRoutes;
});

afterEach(() => sandbox.restore());
Expand Down
46 changes: 24 additions & 22 deletions test/unit/lib/gui/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const _ = require('lodash');
const proxyquire = require('proxyquire');
const App = require('lib/gui/app');
const {App} = require('lib/gui/app');
const {stubTool} = require('../../utils');

describe('lib/gui/server', () => {
Expand Down Expand Up @@ -60,47 +60,49 @@ describe('lib/gui/server', () => {
Router: () => RouterStub
}),
'body-parser': bodyParserStub,
'signal-exit': sandbox.stub().yields(),
'signal-exit': {onExit: sandbox.stub().yields()},
'../common-utils': {logger: {log: sandbox.stub()}},
'./routes/plugins': initPluginRoutesStub
'./routes/plugins': {initPluginsRoutes: initPluginRoutesStub}
});
});

afterEach(() => sandbox.restore());
afterEach(() => {
sandbox.restore();
});

it('should init server from api', () => {
it('should init server from api', async () => {
const guiApi = mkApi_();

return startServer({guiApi})
.then(() => {
assert.calledOnceWith(guiApi.initServer, expressStub);
assert.calledOnceWith(guiApi.serverReady, {url: 'http://localhost:4444'});
});
await startServer({guiApi});

assert.calledOnceWith(guiApi.initServer, expressStub);
assert.calledOnceWith(guiApi.serverReady, {url: 'http://localhost:4444'});
});

it('should init server only after body is parsed', () => {
it('should init server only after body is parsed', async () => {
const guiApi = mkApi_();

return startServer({guiApi})
.then(() => assert.callOrder(bodyParserStub.json, guiApi.initServer, guiApi.serverReady));
await startServer({guiApi});

assert.callOrder(bodyParserStub.json, guiApi.initServer, guiApi.serverReady);
});

it('should init server before any static middleware starts', () => {
it('should init server before any static middleware starts', async () => {
const guiApi = mkApi_();

return startServer({guiApi})
.then(() => assert.callOrder(guiApi.initServer, staticMiddleware, guiApi.serverReady));
await startServer({guiApi});

assert.callOrder(guiApi.initServer, staticMiddleware, guiApi.serverReady);
});

it('should properly complete app working', () => {
it('should properly complete app working', async () => {
sandbox.stub(process, 'kill');

return startServer()
.then(() => {
process.emit('SIGTERM');
await startServer();

process.emit('SIGTERM');

assert.calledOnce(App.prototype.finalize);
});
assert.calledOnce(App.prototype.finalize);
});

it('should correctly set json replacer', async () => {
Expand Down

0 comments on commit 0988ef6

Please sign in to comment.