Skip to content

Commit

Permalink
chore: move "test-adapter" to "adapters/test-result"
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaGod committed Jun 19, 2024
1 parent 4d459b1 commit b99a022
Show file tree
Hide file tree
Showing 32 changed files with 142 additions and 142 deletions.
5 changes: 5 additions & 0 deletions lib/adapters/test-result/hermione.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export {
TestplaneTestResultAdapter as HermioneTestResultAdapter,
TestplaneTestResultAdapterOptions as HermioneTestResultAdapterOptions,
getStatus
} from './testplane';
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {TestStatus} from '../constants';
import {ErrorDetails, ImageBase64, ImageFile, ImageInfoFull, TestError} from '../types';
import {TestStatus} from '../../constants';
import {ErrorDetails, ImageBase64, ImageFile, ImageInfoFull, TestError} from '../../types';

export interface ReporterTestResult {
readonly attempt: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import _ from 'lodash';
import stripAnsi from 'strip-ansi';

import {ReporterTestResult} from './index';
import {getError, getShortMD5, isImageDiffError, isNoRefImageError} from '../common-utils';
import {ERROR, FAIL, PWT_TITLE_DELIMITER, SUCCESS, TestStatus} from '../constants';
import {ErrorName} from '../errors';
import {getError, getShortMD5, isImageDiffError, isNoRefImageError} from '../../common-utils';
import {ERROR, FAIL, PWT_TITLE_DELIMITER, SUCCESS, TestStatus} from '../../constants';
import {ErrorName} from '../../errors';
import {
DiffOptions,
ErrorDetails,
Expand All @@ -16,7 +16,7 @@ import {
ImageInfoFull, ImageInfoNoRef, ImageInfoPageError, ImageInfoPageSuccess, ImageInfoSuccess,
ImageSize,
TestError
} from '../types';
} from '../../types';
import type {CoordBounds} from 'looks-same';

export type PlaywrightAttachment = PlaywrightTestResult['attachments'][number];
Expand Down Expand Up @@ -127,7 +127,7 @@ const getImageData = (attachment: PlaywrightAttachment | undefined): ImageFile |
};
};

export class PlaywrightTestAdapter implements ReporterTestResult {
export class PlaywrightTestResultAdapter implements ReporterTestResult {
private readonly _testCase: PlaywrightTestCase;
private readonly _testResult: PlaywrightTestResult;
private _attempt: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {TestStatus} from '../constants';
import {TestError, ErrorDetails, ImageInfoFull, ImageBase64, ImageFile} from '../types';
import {TestStatus} from '../../constants';
import {TestError, ErrorDetails, ImageInfoFull, ImageBase64, ImageFile} from '../../types';
import {ReporterTestResult} from './index';
import _ from 'lodash';
import {extractErrorDetails} from './utils';
import {getShortMD5, getTestHash} from '../common-utils';
import {getShortMD5, getTestHash} from '../../common-utils';

// This class is primarily useful when cloning ReporterTestResult.
// It allows to override some properties while keeping computable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'lodash';
import {DB_COLUMN_INDEXES, TestStatus} from '../constants';
import {DB_COLUMN_INDEXES, TestStatus} from '../../constants';
import {
AssertViewResult,
TestError,
Expand All @@ -8,10 +8,10 @@ import {
ImageBase64,
ImageFile,
RawSuitesRow
} from '../types';
} from '../../types';
import {ReporterTestResult} from './index';
import {Writable} from 'type-fest';
import {getTestHash} from '../common-utils';
import {getTestHash} from '../../common-utils';

const tryParseJson = (json: string): unknown | undefined => {
try {
Expand All @@ -21,16 +21,16 @@ const tryParseJson = (json: string): unknown | undefined => {
}
};

interface SqliteTestAdapterOptions {
interface SqliteTestResultAdapterOptions {
titleDelimiter: string;
}

export class SqliteTestAdapter implements ReporterTestResult {
export class SqliteTestResultAdapter implements ReporterTestResult {
private _testResult: RawSuitesRow;
private _parsedTestResult: Writable<Partial<ReporterTestResult>>;
private _titleDelimiter: string;

constructor(testResult: RawSuitesRow, attempt: number, options: SqliteTestAdapterOptions) {
constructor(testResult: RawSuitesRow, attempt: number, options: SqliteTestResultAdapterOptions) {
this._testResult = testResult;
this._parsedTestResult = {attempt};
this._titleDelimiter = options.titleDelimiter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type Testplane from 'testplane';
import type {Test as TestplaneTest} from 'testplane';
import {ValueOf} from 'type-fest';

import {getCommandsHistory} from '../history-utils';
import {ERROR, FAIL, SUCCESS, TestStatus, UNKNOWN_SESSION_ID, UPDATED} from '../constants';
import {getError, hasFailedImages, isImageDiffError, isNoRefImageError, wrapLinkByTag} from '../common-utils';
import {getCommandsHistory} from '../../history-utils';
import {ERROR, FAIL, SUCCESS, TestStatus, UNKNOWN_SESSION_ID, UPDATED} from '../../constants';
import {getError, hasFailedImages, isImageDiffError, isNoRefImageError, wrapLinkByTag} from '../../common-utils';
import {
ErrorDetails,
TestplaneSuite,
Expand All @@ -21,9 +21,9 @@ import {
ImageInfoSuccess,
ImageInfoUpdated,
TestError
} from '../types';
} from '../../types';
import {ReporterTestResult} from './index';
import {getSuitePath} from '../plugin-utils';
import {getSuitePath} from '../../plugin-utils';
import {extractErrorDetails} from './utils';

export const getStatus = (eventName: ValueOf<Testplane['events']>, events: Testplane['events'], testResult: TestplaneTestResult): TestStatus => {
Expand All @@ -47,23 +47,23 @@ const wrapSkipComment = (skipComment: string | null | undefined): string => {
return skipComment ? wrapLinkByTag(skipComment) : 'Unknown reason';
};

export interface TestplaneTestAdapterOptions {
export interface TestplaneTestResultAdapterOptions {
attempt: number;
status: TestStatus;
}

export class TestplaneTestAdapter implements ReporterTestResult {
export class TestplaneTestResultAdapter implements ReporterTestResult {
private _testResult: TestplaneTest | TestplaneTestResult;
private _errorDetails: ErrorDetails | null;
private _timestamp: number | undefined;
private _attempt: number;
private _status: TestStatus;

static create<T extends TestplaneTestAdapter>(this: new (testResult: TestplaneTestResult, options: TestplaneTestAdapterOptions) => T, testResult: TestplaneTestResult, options: TestplaneTestAdapterOptions): T {
static create<T extends TestplaneTestResultAdapter>(this: new (testResult: TestplaneTestResult, options: TestplaneTestResultAdapterOptions) => T, testResult: TestplaneTestResult, options: TestplaneTestResultAdapterOptions): T {
return new this(testResult, options);
}

constructor(testResult: TestplaneTest | TestplaneTestResult, {attempt, status}: TestplaneTestAdapterOptions) {
constructor(testResult: TestplaneTest | TestplaneTestResult, {attempt, status}: TestplaneTestResultAdapterOptions) {
this._testResult = testResult;
this._errorDetails = null;
this._timestamp = (this._testResult as TestplaneTestResult).timestamp ??
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ReporterTestResult} from '../index';
import {DbTestResult} from '../../sqlite-client';
import {getError, getRelativeUrl, getUrlWithBase} from '../../common-utils';
import {DbTestResult} from '../../../sqlite-client';
import {getError, getRelativeUrl, getUrlWithBase} from '../../../common-utils';
import _ from 'lodash';

interface Options {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ReporterTestResult} from '../index';
import _ from 'lodash';
import {BaseTreeTestResult} from '../../tests-tree-builder/base';
import {BaseTreeTestResult} from '../../../tests-tree-builder/base';
import {DbTestResultTransformer} from './db';
import {extractErrorDetails} from '../utils';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import _ from 'lodash';
import {ReporterTestResult} from '../index';
import {TupleToUnion} from 'type-fest';
import {ErrorDetails, ImageInfoDiff, ImageInfoFull} from '../../types';
import {ERROR_DETAILS_PATH} from '../../constants';
import {ErrorDetails, ImageInfoDiff, ImageInfoFull} from '../../../types';
import {ERROR_DETAILS_PATH} from '../../../constants';
import {ReporterTestAdapter} from '../reporter';
import {getDetailsFileName, isImageBufferData} from '../../common-utils';
import {getDetailsFileName, isImageBufferData} from '../../../common-utils';

export const copyAndUpdate = (
original: ReporterTestResult,
Expand Down
2 changes: 1 addition & 1 deletion lib/adapters/tool/testplane/test-results-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {TestStatus} from '../../../constants';
import {GuiReportBuilder} from '../../../report-builder/gui';
import {EventSource} from '../../../gui/event-source';
import {TestplaneTestResult} from '../../../types';
import {getStatus} from '../../../test-adapter/testplane';
import {getStatus} from '../../test-result/testplane';

export const handleTestResults = (testplane: Testplane, reportBuilder: GuiReportBuilder, client: EventSource): void => {
const queue = new PQueue({concurrency: os.cpus().length});
Expand Down
2 changes: 1 addition & 1 deletion lib/common-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
TestError
} from './types';
import {ErrorName, ImageDiffError, NoRefImageError} from './errors';
import {ReporterTestResult} from './test-adapter';
import type {ReporterTestResult} from './adapters/test-result';

export const getShortMD5 = (str: string): string => {
return crypto.createHash('md5').update(str, 'ascii').digest('hex').substr(0, 7);
Expand Down
2 changes: 1 addition & 1 deletion lib/db-utils/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {DATABASE_URLS_JSON_NAME, DB_COLUMNS, LOCAL_DATABASE_NAME, TestStatus, To
import {DbLoadResult, HandleDatabasesOptions} from './common';
import {DbUrlsJsonData, RawSuitesRow, ReporterConfig} from '../types';
import {Tree} from '../tests-tree-builder/base';
import {ReporterTestResult} from '../test-adapter';
import {ReporterTestResult} from '../adapters/test-result';
import {SqliteClient} from '../sqlite-client';

export * from './common';
Expand Down
2 changes: 1 addition & 1 deletion lib/gui/tool-runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {

import type {GuiCliOptions, ServerArgs} from '../index';
import type {TestBranch, TestEqualDiffsData, TestRefUpdateData} from '../../tests-tree-builder/gui';
import type {ReporterTestResult} from '../../test-adapter';
import type {ReporterTestResult} from '../../adapters/test-result';
import type {Tree, TreeImage} from '../../tests-tree-builder/base';
import type {TestSpec} from '../../adapters/tool/types';
import type {
Expand Down
4 changes: 2 additions & 2 deletions lib/images-info-saver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import _ from 'lodash';
import PQueue from 'p-queue';

import {RegisterWorkers} from './workers/create-workers';
import {ReporterTestResult} from './test-adapter';
import {ReporterTestResult} from './adapters/test-result';
import {
DiffOptions, ImageBase64, ImageBuffer,
ImageFile,
Expand All @@ -16,7 +16,7 @@ import {
ImageInfoFull,
ImageSize, TestSpecByPath
} from './types';
import {copyAndUpdate, removeBufferFromImagesInfo} from './test-adapter/utils';
import {copyAndUpdate, removeBufferFromImagesInfo} from './adapters/test-result/utils';
import {cacheDiffImages} from './image-cache';
import {NEW_ISSUE_LINK, PluginEvents, TestStatus, UPDATED} from './constants';
import {createHash, getCurrentPath, getDiffPath, getReferencePath, getTempPath, makeDirFor} from './server-utils';
Expand Down
4 changes: 2 additions & 2 deletions lib/report-builder/gui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import {StaticReportBuilder, StaticReportBuilderOptions} from './static';
import {GuiTestsTreeBuilder, TestBranch, TestEqualDiffsData, TestRefUpdateData} from '../tests-tree-builder/gui';
import {UPDATED, DB_COLUMNS, ToolName, TestStatus, TESTPLANE_TITLE_DELIMITER, SKIPPED, SUCCESS} from '../constants';
import {ConfigForStaticFile, getConfigForStaticFile} from '../server-utils';
import {ReporterTestResult} from '../test-adapter';
import {ReporterTestResult} from '../adapters/test-result';
import {Tree, TreeImage} from '../tests-tree-builder/base';
import {ImageInfoFull, ImageInfoWithState, ReporterConfig} from '../types';
import {determineStatus, isUpdatedStatus} from '../common-utils';
import {HtmlReporter, HtmlReporterValues} from '../plugin-api';
import {SkipItem} from '../tests-tree-builder/static';
import {copyAndUpdate} from '../test-adapter/utils';
import {copyAndUpdate} from '../adapters/test-result/utils';

interface UndoAcceptImageResult {
updatedImage: TreeImage | undefined;
Expand Down
4 changes: 2 additions & 2 deletions lib/report-builder/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import {
PluginEvents, UNKNOWN_ATTEMPT, UPDATED
} from '../constants';
import type {SqliteClient} from '../sqlite-client';
import {ReporterTestResult} from '../test-adapter';
import {ReporterTestResult} from '../adapters/test-result';
import {saveErrorDetails, saveStaticFilesToReportDir, writeDatabaseUrlsFile} from '../server-utils';
import {ReporterConfig} from '../types';
import {HtmlReporter} from '../plugin-api';
import {getTestFromDb} from '../db-utils/server';
import {TestAttemptManager} from '../test-attempt-manager';
import {copyAndUpdate} from '../test-adapter/utils';
import {copyAndUpdate} from '../adapters/test-result/utils';
import {RegisterWorkers} from '../workers/create-workers';
import {ImagesInfoSaver} from '../images-info-saver';

Expand Down
4 changes: 2 additions & 2 deletions lib/reporter-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import tmp from 'tmp';
import _ from 'lodash';
import {getShortMD5, isImageInfoWithState} from './common-utils';
import * as utils from './server-utils';
import {ReporterTestResult} from './test-adapter';
import {ReporterTestResult} from './adapters/test-result';
import {getImagesInfoByStateName} from './server-utils';
import {copyAndUpdate} from './test-adapter/utils';
import {copyAndUpdate} from './adapters/test-result/utils';
import {ImageInfoFull, ImageInfoUpdated} from './types';
import {UPDATED} from './constants';

Expand Down
6 changes: 3 additions & 3 deletions lib/server-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import tmp from 'tmp';
import {getShortMD5, logger, mkTestId} from './common-utils';
import {UPDATED, RUNNING, IDLE, SKIPPED, IMAGES_PATH, TestStatus, UNKNOWN_ATTEMPT} from './constants';
import type {HtmlReporter} from './plugin-api';
import type {ReporterTestResult} from './test-adapter';
import type {ReporterTestResult} from './adapters/test-result';
import {
TestplaneTestResult,
ImageInfoWithState,
ReporterConfig,
TestSpecByPath
} from './types';
import {TestplaneTestAdapter} from './test-adapter/testplane';
import {TestplaneTestResultAdapter} from './adapters/test-result/testplane';

const DATA_FILE_NAME = 'data.js';

Expand Down Expand Up @@ -295,7 +295,7 @@ export const formatTestResult = (
status: TestStatus,
attempt: number = UNKNOWN_ATTEMPT
): ReporterTestResult => {
return new TestplaneTestAdapter(rawResult, {attempt, status});
return new TestplaneTestResultAdapter(rawResult, {attempt, status});
};

export const saveErrorDetails = async (testResult: ReporterTestResult, reportPath: string): Promise<void> => {
Expand Down
4 changes: 2 additions & 2 deletions lib/sqlite-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {TestStatus, DB_SUITES_TABLE_NAME, SUITES_TABLE_COLUMNS, LOCAL_DATABASE_N
import {createTablesQuery} from './db-utils/common';
import type {ImageInfoFull, TestError} from './types';
import {HtmlReporter} from './plugin-api';
import {ReporterTestResult} from './test-adapter';
import {DbTestResultTransformer} from './test-adapter/transformers/db';
import {ReporterTestResult} from './adapters/test-result';
import {DbTestResultTransformer} from './adapters/test-result/transformers/db';

const debug = makeDebug('html-reporter:sqlite-client');

Expand Down
5 changes: 0 additions & 5 deletions lib/test-adapter/hermione.ts

This file was deleted.

2 changes: 1 addition & 1 deletion lib/test-attempt-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ReporterTestResult} from './test-adapter';
import {ReporterTestResult} from './adapters/test-result';
import {IDLE, RUNNING, TestStatus} from './constants';

type TestSpec = Pick<ReporterTestResult, 'fullName' | 'browserId'>
Expand Down
4 changes: 2 additions & 2 deletions lib/tests-tree-builder/base.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import _ from 'lodash';
import {determineFinalStatus} from '../common-utils';
import {BrowserVersions, PWT_TITLE_DELIMITER, TESTPLANE_TITLE_DELIMITER, TestStatus, ToolName} from '../constants';
import {ReporterTestResult} from '../test-adapter';
import {ReporterTestResult} from '../adapters/test-result';
import {ErrorDetails, ImageInfoFull} from '../types';
import {TreeTestResultTransformer} from '../test-adapter/transformers/tree';
import {TreeTestResultTransformer} from '../adapters/test-result/transformers/tree';
import {DbTestResult} from '../sqlite-client';

export type BaseTreeTestResult = Omit<DbTestResult, 'imagesInfo'> & {
Expand Down
6 changes: 3 additions & 3 deletions lib/tests-tree-builder/static.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import _ from 'lodash';
import {BaseTestsTreeBuilder, BaseTestsTreeBuilderOptions, Tree} from './base';
import {BrowserVersions, DB_COLUMN_INDEXES, TestStatus} from '../constants';
import {ReporterTestResult} from '../test-adapter';
import {SqliteTestAdapter} from '../test-adapter/sqlite';
import {ReporterTestResult} from '../adapters/test-result';
import {SqliteTestResultAdapter} from '../adapters/test-result/sqlite';
import {getTitleDelimiter} from '../common-utils';
import {RawSuitesRow} from '../types';

Expand Down Expand Up @@ -70,7 +70,7 @@ export class StaticTestsTreeBuilder extends BaseTestsTreeBuilder {
attemptsMap.set(browserId, attemptsMap.has(browserId) ? attemptsMap.get(browserId) as number + 1 : 0);
const attempt = attemptsMap.get(browserId) as number;

const formattedResult = new SqliteTestAdapter(row, attempt, {titleDelimiter: getTitleDelimiter(this._toolName)});
const formattedResult = new SqliteTestResultAdapter(row, attempt, {titleDelimiter: getTitleDelimiter(this._toolName)});

addBrowserVersion(browsers, formattedResult);

Expand Down
4 changes: 2 additions & 2 deletions playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {ReporterConfig, TestSpecByPath} from './lib/types';
import {parseConfig} from './lib/config';
import {PluginEvents, ToolName, UNKNOWN_ATTEMPT} from './lib/constants';
import {RegisterWorkers} from './lib/workers/create-workers';
import {PlaywrightTestAdapter} from './lib/test-adapter/playwright';
import {PlaywrightTestResultAdapter} from './lib/adapters/test-result/playwright';
import {SqliteClient} from './lib/sqlite-client';
import {SqliteImageStore} from './lib/image-store';
import {ImagesInfoSaver} from './lib/images-info-saver';
Expand Down Expand Up @@ -70,7 +70,7 @@ class MyReporter implements Reporter {

const staticReportBuilder = this._staticReportBuilder as StaticReportBuilder;

const formattedResult = new PlaywrightTestAdapter(test, result, UNKNOWN_ATTEMPT);
const formattedResult = new PlaywrightTestResultAdapter(test, result, UNKNOWN_ATTEMPT);

await staticReportBuilder.addTestResult(formattedResult);
});
Expand Down
Loading

0 comments on commit b99a022

Please sign in to comment.