Skip to content

Commit

Permalink
chore: re-write gui/constants to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowusr committed Nov 3, 2023
1 parent 2d9249c commit 19fec10
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 52 deletions.
4 changes: 2 additions & 2 deletions lib/gui/api/facade.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const EventEmitter2 = require('eventemitter2');
const guiEvents = require('../constants/gui-events');
const {GuiEvents} = require('../constants/gui-events');

module.exports = class ApiFacade extends EventEmitter2 {
static create() {
Expand All @@ -11,6 +11,6 @@ module.exports = class ApiFacade extends EventEmitter2 {
constructor() {
super();

this.events = guiEvents;
this.events = GuiEvents;
}
};
13 changes: 0 additions & 13 deletions lib/gui/constants/client-events.js

This file was deleted.

17 changes: 17 additions & 0 deletions lib/gui/constants/client-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {ValueOf} from 'type-fest';

export const ClientEvents = {
BEGIN_SUITE: 'beginSuite',
BEGIN_STATE: 'beginState',

TEST_RESULT: 'testResult',

RETRY: 'retry',
ERROR: 'err',

END: 'end'
} as const;

export type ClientEvents = typeof ClientEvents;

export type ClientEvent = ValueOf<ClientEvents>;
6 changes: 0 additions & 6 deletions lib/gui/constants/custom-gui-control-types.js

This file was deleted.

3 changes: 3 additions & 0 deletions lib/gui/constants/custom-gui-control-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const CONTROL_TYPE_BUTTON = 'button';

export const CONTROL_TYPE_RADIOBUTTON = 'radiobutton';
6 changes: 0 additions & 6 deletions lib/gui/constants/gui-events.js

This file was deleted.

10 changes: 10 additions & 0 deletions lib/gui/constants/gui-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {ValueOf} from 'type-fest';

export const GuiEvents = {
SERVER_INIT: 'serverInit',
SERVER_READY: 'serverReady'
} as const;

export type GuiEvents = typeof GuiEvents;

export type GuiEvent = ValueOf<GuiEvents>;
7 changes: 0 additions & 7 deletions lib/gui/constants/server.js

This file was deleted.

5 changes: 5 additions & 0 deletions lib/gui/constants/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const MAX_REQUEST_SIZE = '100mb';

export const KEEP_ALIVE_TIMEOUT = 120 * 1000;

export const HEADERS_TIMEOUT = 125 * 1000;
2 changes: 1 addition & 1 deletion lib/gui/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const bodyParser = require('body-parser');
const {INTERNAL_SERVER_ERROR, OK} = require('http-codes');

const App = require('./app');
const {MAX_REQUEST_SIZE, KEEP_ALIVE_TIMEOUT, HEADERS_TIMEOUT} = require('./constants/server');
const {MAX_REQUEST_SIZE, KEEP_ALIVE_TIMEOUT, HEADERS_TIMEOUT} = require('./constants');
const {initializeCustomGui, runCustomGuiAction} = require('../server-utils');
const {logger} = require('../common-utils');
const initPluginsRoutes = require('./routes/plugins');
Expand Down
16 changes: 8 additions & 8 deletions lib/gui/tool-runner/report-subscriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const os = require('os');
const PQueue = require('p-queue');
const clientEvents = require('../constants/client-events');
const {ClientEvents} = require('../constants/client-events');
const {getSuitePath} = require('../../plugin-utils');
const {createWorkers} = require('../../workers/create-workers');
const {logError, formatTestResult} = require('../../server-utils');
Expand Down Expand Up @@ -34,7 +34,7 @@ module.exports = (hermione, reportBuilder, client, reportPath) => {
return;
}

client.emit(clientEvents.BEGIN_SUITE, {
client.emit(ClientEvents.BEGIN_SUITE, {
suiteId: getSuitePath(suite).join(' '),
status: TestStatus.RUNNING
});
Expand All @@ -47,7 +47,7 @@ module.exports = (hermione, reportBuilder, client, reportPath) => {
reportBuilder.addRunning(formattedResult);
const testBranch = reportBuilder.getTestBranch(formattedResult.id);

return client.emit(clientEvents.BEGIN_STATE, testBranch);
return client.emit(ClientEvents.BEGIN_STATE, testBranch);
});

hermione.on(hermione.events.TEST_PASS, (testResult) => {
Expand All @@ -59,7 +59,7 @@ module.exports = (hermione, reportBuilder, client, reportPath) => {
reportBuilder.addSuccess(formattedResult);

const testBranch = reportBuilder.getTestBranch(formattedResult.id);
client.emit(clientEvents.TEST_RESULT, testBranch);
client.emit(ClientEvents.TEST_RESULT, testBranch);
}).catch(logError);
});

Expand All @@ -73,7 +73,7 @@ module.exports = (hermione, reportBuilder, client, reportPath) => {
reportBuilder.addRetry(formattedResult);

const testBranch = reportBuilder.getTestBranch(formattedResult.id);
client.emit(clientEvents.TEST_RESULT, testBranch);
client.emit(ClientEvents.TEST_RESULT, testBranch);
}).catch(logError);
});

Expand All @@ -89,7 +89,7 @@ module.exports = (hermione, reportBuilder, client, reportPath) => {
: reportBuilder.addError(formattedResult);

const testBranch = reportBuilder.getTestBranch(formattedResult.id);
client.emit(clientEvents.TEST_RESULT, testBranch);
client.emit(ClientEvents.TEST_RESULT, testBranch);
}).catch(logError);
});

Expand All @@ -102,14 +102,14 @@ module.exports = (hermione, reportBuilder, client, reportPath) => {
reportBuilder.addSkipped(formattedResult);

const testBranch = reportBuilder.getTestBranch(formattedResult.id);
client.emit(clientEvents.TEST_RESULT, testBranch);
client.emit(ClientEvents.TEST_RESULT, testBranch);
}).catch(logError);
});

hermione.on(hermione.events.RUNNER_END, async () => {
try {
await queue.onIdle();
client.emit(clientEvents.END);
client.emit(ClientEvents.END);
} catch (err) {
logError(err);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/static/components/gui.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Loading from './loading';
import ModalContainer from '../containers/modal';
import MainTree from './main-tree';
import CustomScripts from './custom-scripts';
import clientEvents from '../../gui/constants/client-events';
import {ClientEvents} from '../../gui/constants/client-events';
import FaviconChanger from './favicon-changer';
import ExtensionPoint from './extension-point';
import BottomProgressBar from './bottom-progress-bar';
Expand Down Expand Up @@ -40,24 +40,24 @@ class Gui extends Component {
const {actions} = this.props;
const eventSource = new EventSource('/events');

eventSource.addEventListener(clientEvents.BEGIN_SUITE, (e) => {
eventSource.addEventListener(ClientEvents.BEGIN_SUITE, (e) => {
const data = JSON.parse(e.data);
actions.suiteBegin(data);
});

eventSource.addEventListener(clientEvents.BEGIN_STATE, (e) => {
eventSource.addEventListener(ClientEvents.BEGIN_STATE, (e) => {
const data = JSON.parse(e.data);
actions.testBegin(data);
});

[clientEvents.TEST_RESULT, clientEvents.ERROR].forEach((eventName) => {
[ClientEvents.TEST_RESULT, ClientEvents.ERROR].forEach((eventName) => {
eventSource.addEventListener(eventName, (e) => {
const data = JSON.parse(e.data);
actions.testResult(data);
});
});

eventSource.addEventListener(clientEvents.END, () => {
eventSource.addEventListener(ClientEvents.END, () => {
actions.testsEnd();
});
}
Expand Down
8 changes: 4 additions & 4 deletions test/unit/lib/gui/api/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

Expand All @@ -20,7 +20,7 @@ describe('lig/gui/api', () => {

Api.create(tool);

assert.deepEqual(tool.gui.events, guiEvents);
assert.deepEqual(tool.gui.events, GuiEvents);
});
});

Expand All @@ -29,7 +29,7 @@ describe('lig/gui/api', () => {
const tool = stubTool();
const api = Api.create(tool);
const onServerInit = sinon.spy().named('onServerInit');
tool.gui.on(guiEvents.SERVER_INIT, onServerInit);
tool.gui.on(GuiEvents.SERVER_INIT, onServerInit);

api.initServer({foo: 'bar'});

Expand All @@ -42,7 +42,7 @@ describe('lig/gui/api', () => {
const tool = stubTool();
const api = Api.create(tool);
const onServerReady = sinon.spy().named('onServerReady');
tool.gui.on(guiEvents.SERVER_READY, onServerReady);
tool.gui.on(GuiEvents.SERVER_READY, onServerReady);

api.serverReady({url: 'http://my.server'});

Expand Down

0 comments on commit 19fec10

Please sign in to comment.