-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: re-write GUI to typescript part 3 (#521)
* chore: rename gui/app to typescript * chore: rewrite gui/app to typescript * chore: rewrite gui/routes/plugins to typescript * chore: rewrite gui server to typescript
- Loading branch information
Showing
18 changed files
with
371 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import EventEmitter2 from 'eventemitter2'; | ||
import {GuiEvents} from '../constants'; | ||
|
||
export class ApiFacade extends EventEmitter2 { | ||
events: GuiEvents; | ||
|
||
static create<T extends ApiFacade>(this: new () => T): T { | ||
return new this(); | ||
} | ||
|
||
constructor() { | ||
super(); | ||
|
||
this.events = GuiEvents; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {ApiFacade} from './facade'; | ||
import Hermione from 'hermione'; | ||
import {Express} from 'express'; | ||
|
||
export interface ServerReadyData { | ||
url: string; | ||
} | ||
|
||
type HermioneWithGui = Hermione & { gui: ApiFacade }; | ||
|
||
export class Api { | ||
private _gui: ApiFacade; | ||
|
||
static create<T extends Api>(this: new (hermione: HermioneWithGui) => T, hermione: HermioneWithGui): T { | ||
return new this(hermione); | ||
} | ||
|
||
constructor(hermione: HermioneWithGui) { | ||
this._gui = hermione.gui = ApiFacade.create(); | ||
} | ||
|
||
async initServer(server: Express): Promise<void> { | ||
await this._gui.emitAsync(this._gui.events.SERVER_INIT, server); | ||
} | ||
|
||
async serverReady(data: ServerReadyData): Promise<void> { | ||
await this._gui.emitAsync(this._gui.events.SERVER_READY, data); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import {Response} from 'express'; | ||
import _ from 'lodash'; | ||
|
||
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'; | ||
|
||
type BrowserConfig = ReturnType<Config['forBrowser']>; | ||
|
||
type AppArgs = [paths: string[], hermione: Hermione & HtmlReporterApi, configs: GuiConfigs]; | ||
|
||
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._browserConfigs = []; | ||
this._retryCache = {}; | ||
} | ||
|
||
get data(): ToolRunnerTree | null { | ||
return this._toolRunner.tree; | ||
} | ||
|
||
async initialize(): Promise<void> { | ||
return await this._toolRunner.initialize(); | ||
} | ||
|
||
async finalize(): Promise<void> { | ||
return this._toolRunner.finalize(); | ||
} | ||
|
||
async run(tests: TestSpec[]): Promise<boolean> { | ||
return _.isEmpty(tests) | ||
? this._toolRunner.run() | ||
: this._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)); | ||
} | ||
|
||
this._disableRetries(); | ||
|
||
return this._toolRunner.run(tests) | ||
.finally(() => this._restoreRetries()); | ||
} | ||
|
||
getTestsDataToUpdateRefs(imageIds: string[] = []): TestRefUpdateData[] { | ||
return this._toolRunner.getTestsDataToUpdateRefs(imageIds); | ||
} | ||
|
||
getImageDataToFindEqualDiffs(imageIds: string[] = []): TestEqualDiffsData[] { | ||
return this._toolRunner.getImageDataToFindEqualDiffs(imageIds); | ||
} | ||
|
||
async updateReferenceImage(failedTests: TestRefUpdateData[] = []): Promise<TestBranch[]> { | ||
return this._toolRunner.updateReferenceImage(failedTests); | ||
} | ||
|
||
async undoAcceptImages(imageIds: TestRefUpdateData[]): Promise<UndoAcceptImagesResult> { | ||
return this._toolRunner.undoAcceptImages(imageIds); | ||
} | ||
|
||
async findEqualDiffs(data: TestEqualDiffsData[]): Promise<string[]> { | ||
return this._toolRunner.findEqualDiffs(data); | ||
} | ||
|
||
addClient(connection: Response): void { | ||
this._toolRunner.addClient(connection); | ||
} | ||
|
||
private _disableRetries(): void { | ||
this._browserConfigs.forEach((broConfig) => { | ||
this._retryCache[broConfig.id] = broConfig.retry; | ||
broConfig.retry = 0; | ||
}); | ||
} | ||
|
||
private _restoreRetries(): void { | ||
this._browserConfigs.forEach((broConfig) => { | ||
broConfig.retry = this._retryCache[broConfig.id]; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.