From 0988ef6d4b8ca183b2fa3c38393a42466c38fc71 Mon Sep 17 00:00:00 2001 From: shadowusr Date: Tue, 21 Nov 2023 13:52:15 +0300 Subject: [PATCH] test: fix unit and e2e tests --- lib/cli-commands/gui.js | 2 +- lib/gui/api/index.ts | 10 +++---- lib/gui/routes/plugins.ts | 2 +- test/unit/lib/gui/api/index.js | 2 +- test/unit/lib/gui/app.js | 2 +- test/unit/lib/gui/routes/plugins.js | 2 +- test/unit/lib/gui/server.js | 46 +++++++++++++++-------------- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/cli-commands/gui.js b/lib/cli-commands/gui.js index 155489e5b..fb7e0d59d 100644 --- a/lib/cli-commands/gui.js +++ b/lib/cli-commands/gui.js @@ -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; diff --git a/lib/gui/api/index.ts b/lib/gui/api/index.ts index 6a8ca29a5..06ae26609 100644 --- a/lib/gui/api/index.ts +++ b/lib/gui/api/index.ts @@ -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(this: new (hermione: Hermione & GuiFacade) => T, hermione: Hermione & GuiFacade): T { + static create(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(); } diff --git a/lib/gui/routes/plugins.ts b/lib/gui/routes/plugins.ts index bad32f4df..38eac1c23 100644 --- a/lib/gui/routes/plugins.ts +++ b/lib/gui/routes/plugins.ts @@ -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; } diff --git a/test/unit/lib/gui/api/index.js b/test/unit/lib/gui/api/index.js index 8ba58af75..87e5ee07a 100644 --- a/test/unit/lib/gui/api/index.js +++ b/test/unit/lib/gui/api/index.js @@ -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', () => { diff --git a/test/unit/lib/gui/app.js b/test/unit/lib/gui/app.js index 86079422f..61218fca3 100644 --- a/test/unit/lib/gui/app.js +++ b/test/unit/lib/gui/app.js @@ -48,7 +48,7 @@ describe('lib/gui/app', () => { App = proxyquire('lib/gui/app', { 'looks-same': looksSame - }); + }).App; sandbox.stub(ToolRunner, 'create').returns(toolRunner); }); diff --git a/test/unit/lib/gui/routes/plugins.js b/test/unit/lib/gui/routes/plugins.js index 4fe400b17..5f77b6fea 100644 --- a/test/unit/lib/gui/routes/plugins.js +++ b/test/unit/lib/gui/routes/plugins.js @@ -32,7 +32,7 @@ describe('lib/gui/routes/plugins', () => { return router; } } - }); + }).initPluginsRoutes; }); afterEach(() => sandbox.restore()); diff --git a/test/unit/lib/gui/server.js b/test/unit/lib/gui/server.js index 46f249848..7050f1f6e 100644 --- a/test/unit/lib/gui/server.js +++ b/test/unit/lib/gui/server.js @@ -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', () => { @@ -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 () => {