Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/lib/browser/client-scripts/calibrate.min.js
/build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
build
*.log
/lib/browser/client-scripts/calibrate.min.js
27 changes: 0 additions & 27 deletions index.js

This file was deleted.

26 changes: 26 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export { default as BaseStats } from "./lib/base-stats";
export { default as SetsBuilder } from "./lib/sets-builder";

import options from "./lib/config/options";
export const config = { options };
Comment on lines +4 to +5

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Такая махинация нужна, чтобы сохранить API, но понял, что можно сделать лучше так:

  • добавить файл ./lib/config/index.ts с содержимым export * as options from "./options";
  • здесь оставить лишь export * as config from "./lib/config";


export { default as Calibrator } from "./lib/calibrator";
export * as BrowserPool from "./lib/browser-pool";
export { default as BrowserAgent } from "./lib/browser-agent";
export { default as Image } from "./lib/image";
export * as temp from "./lib/temp";
export * as errors from "./lib/errors";
export * as events from "./lib/events";
export * as promiseUtils from "./lib/promise-utils";
export * as clientBridge from "./lib/client-bridge";

import * as coverageLevel from "./lib/coverage/coverage-level";
export const coverage = { coverageLevel };

import Camera from "./lib/browser/camera";
export const browser = { Camera };
export { Camera };

export { default as ScreenShooter } from "./lib/screen-shooter";
export { default as Viewport } from "./lib/screen-shooter/viewport";
export { default as CoordValidator } from "./lib/screen-shooter/viewport/coord-validator";
61 changes: 0 additions & 61 deletions lib/base-stats/index.js

This file was deleted.

72 changes: 72 additions & 0 deletions lib/base-stats/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import _ from "lodash";

type StatNames<T extends string = 'passed' | 'failed' | 'skipped'> = Record<Uppercase<T>, Lowercase<T>>;

type Stats = { [StatName in StatNames[keyof StatNames]]: number };
type StatsResult = Stats & {
total: number;
retries: number;
};

export default class BaseStats {
private _tests: Set<string>;
private _retries: number;
private _statNames: StatNames;
private _stats: Stats;

public static create(statNames: StatNames): BaseStats {
return new this(statNames);
}

constructor(statNames: StatNames) {
this._tests = new Set();
this._retries = 0;
this._statNames = statNames;

this._stats = this._fillEmptyStats();
}

public addPassed(test: unknown) {
this._addStat(this._statNames.PASSED, test);
}

public addFailed(test: unknown) {
this._addStat(this._statNames.FAILED, test);
}

public addSkipped(test: unknown) {
this._addStat(this._statNames.SKIPPED, test);
}

public addRetries() {
this._retries++;
}

private _addStat(stat: StatNames[keyof StatNames], test: unknown, statsStorage = this._stats, testsStorage = this._tests) {
const key = `${this._buildSuiteKey(test)} ${this._buildStateKey(test)}`;

statsStorage[stat]++;
testsStorage.add(key);
}

private _fillEmptyStats(): Stats {
const statValues = _.values(this._statNames);

return _.zipObject(statValues, Array(statValues.length).fill(0)) as Stats;
}

private _buildStateKey(_test: unknown): string {
throw new Error('Method must be implemented in child classes');
}

private _buildSuiteKey(_test: unknown): string {
throw new Error('Method must be implemented in child classes');
}

public getResult(): StatsResult {
return _.extend(this._stats, {
total: this._tests.size,
retries: this._retries
});
}
};
31 changes: 0 additions & 31 deletions lib/browser-agent/index.js

This file was deleted.

34 changes: 34 additions & 0 deletions lib/browser-agent/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import _ from 'lodash';

import type { Pool } from '../types/pool';
import type { NewBrowser } from '../types/new-browser';

export default class BrowserAgent {
private _sessions: Array<string>;

public static create(browserId: string, pool: Pool): BrowserAgent {
return new BrowserAgent(browserId, pool);
}

constructor(public browserId: string, private _pool: Pool) {
this._sessions = [];
}

public async getBrowser(opts: any): Promise<NewBrowser> {
const browser = await this._pool.getBrowser(this.browserId, opts);

if (_.includes(this._sessions, browser.sessionId)) {
await this.freeBrowser(browser, {force: true});

return this.getBrowser(opts);
}

this._sessions.push(browser.sessionId);

return browser;
}

public async freeBrowser(browser: NewBrowser, opts: any): Promise<void> {
return this._pool.freeBrowser(browser, opts);
}
}
65 changes: 0 additions & 65 deletions lib/browser-pool/basic-pool.js

This file was deleted.

Loading