Skip to content

Commit

Permalink
chore: re-write tool-runner/runner to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowusr committed Nov 3, 2023
1 parent b48a866 commit 2d9249c
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 70 deletions.
16 changes: 4 additions & 12 deletions lib/gui/tool-runner/index.ts → lib/gui/tool-runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const chalk = require('chalk');
const Promise = require('bluebird');
const looksSame = require('looks-same');

const Runner = require('./runner');
const {createTestRunner} = require('./runner');
const subscribeOnToolEvents = require('./report-subscriber');
const {GuiReportBuilder} = require('../../report-builder/gui');
const GuiReportBuilder = require('../../report-builder/gui');
const EventSource = require('../event-source');
const {logger} = require('../../common-utils');
const reporterHelper = require('../../reporter-helpers');
Expand Down Expand Up @@ -202,7 +202,7 @@ module.exports = class ToolRunner {
run(tests = []) {
const {grep, set: sets, browser: browsers} = this._globalOpts;

return Runner.create(this._collection, tests)
return createTestRunner(this._collection, tests)
.run((collection) => this._hermione.run(collection, {grep, sets, browsers}));
}

Expand Down Expand Up @@ -250,15 +250,7 @@ module.exports = class ToolRunner {
return _.extend(imageInfo, {expectedImg: refImg});
});

const res = _.merge({}, rawTest, {
assertViewResults,
imagesInfo,
sessionId,
attempt,
err: test.error,
meta: {url},
updated: true
});
const res = _.merge({}, rawTest, {assertViewResults, imagesInfo, sessionId, attempt, origAttempt: attempt, meta: {url}, updated: true});

// _.merge can't fully clone test object since hermione@7+
// TODO: use separate object to represent test results. Do not extend test object with test results
Expand Down
11 changes: 0 additions & 11 deletions lib/gui/tool-runner/runner/all-test-runner.js

This file was deleted.

9 changes: 9 additions & 0 deletions lib/gui/tool-runner/runner/all-test-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {BaseRunner, TestCollection} from './runner';

export class AllTestRunner extends BaseRunner {
override run<U>(runHandler: (testCollection: TestCollection) => U): U {
this._collection.enableAll();

return super.run(runHandler);
}
}
11 changes: 0 additions & 11 deletions lib/gui/tool-runner/runner/index.js

This file was deleted.

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

import {TestCollection, TestRunner, TestSpec} from './runner';
import {AllTestRunner} from './all-test-runner';
import {SpecificTestRunner} from './specific-test-runner';

export const createTestRunner = (collection: TestCollection, tests: TestSpec[]): TestRunner => {
return _.isEmpty(tests)
? new AllTestRunner(collection)
: new SpecificTestRunner(collection, tests);
};
11 changes: 0 additions & 11 deletions lib/gui/tool-runner/runner/runner.js

This file was deleted.

25 changes: 25 additions & 0 deletions lib/gui/tool-runner/runner/runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Hermione from 'hermione';
import {AsyncReturnType} from 'type-fest';

export type TestCollection = AsyncReturnType<Hermione['readTests']>

export interface TestRunner {
run<U>(handler: (testCollection: TestCollection) => U): U;
}

export interface TestSpec {
testName: string;
browserName: string;
}

export class BaseRunner implements TestRunner {
protected _collection: TestCollection;

constructor(collection: TestCollection) {
this._collection = collection;
}

run<U>(runHandler: (testCollection: TestCollection) => U): U {
return runHandler(this._collection);
}
}
25 changes: 0 additions & 25 deletions lib/gui/tool-runner/runner/specific-test-runner.js

This file was deleted.

25 changes: 25 additions & 0 deletions lib/gui/tool-runner/runner/specific-test-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {BaseRunner, TestCollection, TestSpec} from './runner';

export class SpecificTestRunner extends BaseRunner {
private _tests: TestSpec[];

constructor(collection: TestCollection, tests: TestSpec[]) {
super(collection);

this._tests = tests;
}

override run<U>(runHandler: (testCollection: TestCollection) => U): U {
this._filter();

return super.run(runHandler);
}

private _filter(): void {
this._collection.disableAll();

this._tests.forEach(({testName, browserName}) => {
this._collection.enableTest(testName, browserName);
});
}
}

0 comments on commit 2d9249c

Please sign in to comment.