-
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: implement adapters: test, testCollection, config
In order to support gui command for playwright
- Loading branch information
Showing
24 changed files
with
610 additions
and
156 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {TestAdapter} from '../test'; | ||
|
||
export interface BrowserConfigAdapter { | ||
readonly id: string; | ||
retry: number; | ||
} | ||
|
||
export interface ConfigAdapter { | ||
readonly tolerance: number; | ||
readonly antialiasingTolerance: number; | ||
readonly browserIds: string[]; | ||
|
||
getBrowserConfig(browserId: string): BrowserConfigAdapter; | ||
getScreenshotPath(test: TestAdapter, stateName: string): string; | ||
} |
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,37 @@ | ||
import type {Config} from 'testplane'; | ||
import type {ConfigAdapter} from './'; | ||
import {TestplaneTestAdapter} from '../test/testplane'; | ||
|
||
export class TestplaneConfigAdapter implements ConfigAdapter { | ||
private _config: Config; | ||
|
||
static create<T extends TestplaneConfigAdapter>(this: new (config: Config) => T, config: Config): T { | ||
return new this(config); | ||
} | ||
|
||
constructor(config: Config) { | ||
this._config = config; | ||
} | ||
|
||
get tolerance(): number { | ||
return this._config.tolerance; | ||
} | ||
|
||
get antialiasingTolerance(): number { | ||
return this._config.antialiasingTolerance; | ||
} | ||
|
||
get browserIds(): string[] { | ||
return this._config.getBrowserIds(); | ||
} | ||
|
||
getBrowserConfig(browserId: string): ReturnType<Config['forBrowser']> { | ||
return this._config.forBrowser(browserId); | ||
} | ||
|
||
getScreenshotPath(test: TestplaneTestAdapter, stateName: string): string { | ||
const {browserId} = test; | ||
|
||
return this._config.browsers[browserId].getScreenshotPath(test.original, stateName); | ||
} | ||
} |
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,5 @@ | ||
import type {TestAdapter} from '../test'; | ||
|
||
export interface TestCollectionAdapter { | ||
readonly tests: TestAdapter[]; | ||
} |
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,28 @@ | ||
import {TestplaneTestAdapter} from '../test/testplane'; | ||
import type {TestCollectionAdapter} from './index'; | ||
import type {TestCollection} from 'testplane'; | ||
|
||
export class TestplaneTestCollectionAdapter implements TestCollectionAdapter { | ||
private _testCollection: TestCollection; | ||
private _testAdapters: TestplaneTestAdapter[]; | ||
|
||
static create<T>( | ||
this: new (testCollection: TestCollection) => T, | ||
testCollection: TestCollection | ||
): T { | ||
return new this(testCollection); | ||
} | ||
|
||
constructor(testCollection: TestCollection) { | ||
this._testCollection = testCollection; | ||
this._testAdapters = this._testCollection.mapTests(test => TestplaneTestAdapter.create(test)); | ||
} | ||
|
||
get original(): TestCollection { | ||
return this._testCollection; | ||
} | ||
|
||
get tests(): TestplaneTestAdapter[] { | ||
return this._testAdapters; | ||
} | ||
} |
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
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 {TestStatus} from '../../constants'; | ||
import type {ReporterTestResult} from '../test-result'; | ||
import type {AssertViewResult} from '../../types'; | ||
|
||
export interface CreateTestResultOpts { | ||
status: TestStatus; | ||
attempt?: number; | ||
assertViewResults?: AssertViewResult[]; | ||
error?: Error; | ||
sessionId?: string; | ||
meta?: { | ||
url?: string; | ||
} | ||
} | ||
|
||
export interface TestAdapter { | ||
readonly id: string; | ||
readonly pending: boolean; | ||
readonly disabled: boolean; | ||
readonly silentlySkipped: boolean; | ||
readonly browserId: string; | ||
readonly fullName: string; | ||
|
||
createTestResult(opts: CreateTestResultOpts): ReporterTestResult; | ||
} |
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,68 @@ | ||
import {TestplaneTestResultAdapter} from '../test-result/testplane'; | ||
import {UNKNOWN_ATTEMPT} from '../../constants'; | ||
|
||
import type {TestAdapter, CreateTestResultOpts} from './'; | ||
import type {Test, Suite} from 'testplane'; | ||
import type {ReporterTestResult} from '../test-result'; | ||
|
||
export class TestplaneTestAdapter implements TestAdapter { | ||
private _test: Test; | ||
|
||
static create<T extends TestplaneTestAdapter>(this: new (test: Test) => T, test: Test): T { | ||
return new this(test); | ||
} | ||
|
||
constructor(test: Test) { | ||
this._test = test; | ||
} | ||
|
||
get original(): Test { | ||
return this._test; | ||
} | ||
|
||
get id(): string { | ||
return this._test.id; | ||
} | ||
|
||
get pending(): boolean { | ||
return this._test.pending; | ||
} | ||
|
||
get disabled(): boolean { | ||
return this._test.disabled; | ||
} | ||
|
||
get silentlySkipped(): boolean { | ||
return isSilentlySkipped(this._test); | ||
} | ||
|
||
get browserId(): string { | ||
return this._test.browserId; | ||
} | ||
|
||
get fullName(): string { | ||
return this._test.fullTitle(); | ||
} | ||
|
||
createTestResult(opts: CreateTestResultOpts): ReporterTestResult { | ||
const {status, assertViewResults, error, sessionId, meta, attempt = UNKNOWN_ATTEMPT} = opts; | ||
const test = this._test.clone(); | ||
|
||
[ | ||
{key: 'assertViewResults', value: assertViewResults}, | ||
{key: 'err', value: error}, | ||
{key: 'sessionId', value: sessionId}, | ||
{key: 'meta', value: meta} | ||
].forEach(({key, value}) => { | ||
if (value) { | ||
test[key] = value; | ||
} | ||
}); | ||
|
||
return TestplaneTestResultAdapter.create(test, {attempt, status}); | ||
} | ||
} | ||
|
||
function isSilentlySkipped(runnable: Test | Suite): boolean { | ||
return Boolean(runnable.silentSkip || runnable.parent && isSilentlySkipped(runnable.parent)); | ||
} |
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
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
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.