Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: re-write GUI to typescript part 3 #521

Merged
merged 5 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 38 additions & 28 deletions lib/gui/app.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
'use strict';
import {Response} from 'express';
import _ from 'lodash';

const _ = require('lodash');
const {ToolRunner} = require('./tool-runner');
import {ToolRunner, ToolRunnerTree, UndoAcceptImagesResult} from './tool-runner';
import {HtmlReporterApi} from '../types';
import Hermione, {Config} from 'hermione';
import {GuiConfigs} from './index';
import {TestSpec} from './tool-runner/runner/runner';
import {TestBranch, TestEqualDiffsData, TestRefUpdateData} from '../tests-tree-builder/gui';

module.exports = class App {
static create(paths, hermione, configs) {
return new this(paths, hermione, configs);
}
type BrowserConfig = ReturnType<Config['forBrowser']>;
shadowusr marked this conversation as resolved.
Show resolved Hide resolved

type AppArgs = [paths: string[], hermione: Hermione & HtmlReporterApi, configs: GuiConfigs];

constructor(paths, hermione, configs) {
const {pluginConfig} = configs;
export class App {
private _toolRunner: ToolRunner;
private _browserConfigs: BrowserConfig[];
private _retryCache: Record<string, number>;

static create<T extends App>(this: new (...args: AppArgs) => T, ...args: AppArgs): T {
return new this(...args);
}

constructor(...[paths, hermione, configs]: AppArgs) {
this._toolRunner = ToolRunner.create(paths, hermione, configs);
this._pluginConfig = pluginConfig;

this._browserConfigs = [];
this._retryCache = {};
}

async initialize() {
get data(): ToolRunnerTree | null {
return this._toolRunner.tree;
}

async initialize(): Promise<void> {
return await this._toolRunner.initialize();
}

finalize() {
this._toolRunner.finalize();
async finalize(): Promise<void> {
return this._toolRunner.finalize();
}

run(tests) {
async run(tests: TestSpec[]): Promise<boolean> {
return _.isEmpty(tests)
? this._toolRunner.run()
: this._runWithoutRetries(tests);
}

_runWithoutRetries(tests) {
private async _runWithoutRetries(tests: TestSpec[]): Promise<boolean> {
if (_.isEmpty(this._browserConfigs)) {
this._browserConfigs = _.map(this._toolRunner.config.getBrowserIds(), (id) => this._toolRunner.config.forBrowser(id));
}
Expand All @@ -43,44 +57,40 @@ module.exports = class App {
.finally(() => this._restoreRetries());
}

getTestsDataToUpdateRefs(imageIds = []) {
getTestsDataToUpdateRefs(imageIds: string[] = []): TestRefUpdateData[] {
return this._toolRunner.getTestsDataToUpdateRefs(imageIds);
}

getImageDataToFindEqualDiffs(imageIds = []) {
getImageDataToFindEqualDiffs(imageIds: string[] = []): TestEqualDiffsData[] {
return this._toolRunner.getImageDataToFindEqualDiffs(imageIds);
}

updateReferenceImage(failedTests = []) {
async updateReferenceImage(failedTests: TestRefUpdateData[] = []): Promise<TestBranch[]> {
return this._toolRunner.updateReferenceImage(failedTests);
}

undoAcceptImages(imageIds) {
async undoAcceptImages(imageIds: TestRefUpdateData[]): Promise<UndoAcceptImagesResult> {
shadowusr marked this conversation as resolved.
Show resolved Hide resolved
return this._toolRunner.undoAcceptImages(imageIds);
}

async findEqualDiffs(data) {
async findEqualDiffs(data: TestEqualDiffsData[]): Promise<string[]> {
return this._toolRunner.findEqualDiffs(data);
}

addClient(connection) {
addClient(connection: Response): void {
this._toolRunner.addClient(connection);
}

get data() {
return this._toolRunner.tree;
}

_disableRetries() {
private _disableRetries(): void {
this._browserConfigs.forEach((broConfig) => {
this._retryCache[broConfig.id] = broConfig.retry;
broConfig.retry = 0;
});
}

_restoreRetries() {
private _restoreRetries(): void {
this._browserConfigs.forEach((broConfig) => {
broConfig.retry = this._retryCache[broConfig.id];
});
}
};
}
2 changes: 1 addition & 1 deletion lib/gui/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Promise = require('bluebird');
const bodyParser = require('body-parser');
const {INTERNAL_SERVER_ERROR, OK} = require('http-codes');

const App = require('./app');
const {App} = require('./app');
const {MAX_REQUEST_SIZE, KEEP_ALIVE_TIMEOUT, HEADERS_TIMEOUT} = require('./constants');
const {initializeCustomGui, runCustomGuiAction} = require('../server-utils');
const {logger} = require('../common-utils');
Expand Down
2 changes: 1 addition & 1 deletion lib/gui/tool-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {ImagesInfoFormatter} from '../../image-handler';

type ToolRunnerArgs = [paths: string[], hermione: Hermione & HtmlReporterApi, configs: GuiConfigs];

type ToolRunnerTree = GuiReportBuilderResult & Pick<GuiCliOptions, 'autoRun'>;
export type ToolRunnerTree = GuiReportBuilderResult & Pick<GuiCliOptions, 'autoRun'>;

interface HermioneTestExtended extends HermioneTest {
assertViewResults: {stateName: string, refImg: ImageData, currImg: ImageData};
Expand Down