-
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 tool-runner/runner to typescript
- Loading branch information
Showing
9 changed files
with
74 additions
and
70 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,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); | ||
} | ||
} |
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,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); | ||
}; |
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,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); | ||
} | ||
} |
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,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); | ||
}); | ||
} | ||
} |