Skip to content

Commit

Permalink
fix: review issues fixes, use pwt delimiter instead of space
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowusr committed Sep 27, 2023
1 parent 1930757 commit ce509b6
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 289 deletions.
3 changes: 3 additions & 0 deletions lib/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ export * from './browser';
export * from './database';
export * from './defaults';
export * from './diff-modes';
export * from './group-tests';
export * from './paths';
export * from './tests';
export * from './plugin-events';
export * from './save-formats';
export * from './test-statuses';
export * from './tool-names';
export * from './view-modes';
1 change: 1 addition & 0 deletions lib/constants/tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const PWT_TITLE_DELIMITER = ' › ';
4 changes: 4 additions & 0 deletions lib/constants/tool-names.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum ToolName {
Hermione = 'hermione',
Playwright = 'playwright'
}
6 changes: 3 additions & 3 deletions lib/db-utils/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import NestedError from 'nested-error-stacks';
import {StaticTestsTreeBuilder} from '../tests-tree-builder/static';
import * as commonSqliteUtils from './common';
import {isUrl, fetchFile, normalizeUrls, logger} from '../common-utils';
import {DATABASE_URLS_JSON_NAME, DB_COLUMNS, LOCAL_DATABASE_NAME, TestStatus} from '../constants';
import {DATABASE_URLS_JSON_NAME, DB_COLUMNS, LOCAL_DATABASE_NAME, TestStatus, ToolName} from '../constants';
import {DbLoadResult, HandleDatabasesOptions} from './common';
import {DbUrlsJsonData, RawSuitesRow, ReporterConfig} from '../types';
import {Tree} from '../tests-tree-builder/base';
Expand Down Expand Up @@ -57,10 +57,10 @@ export async function mergeDatabases(srcDbPaths: string[], reportPath: string):
}
}

export function getTestsTreeFromDatabase(dbPath: string): Tree {
export function getTestsTreeFromDatabase(toolName: ToolName, dbPath: string): Tree {
try {
const db = new Database(dbPath, {readonly: true, fileMustExist: true});
const testsTreeBuilder = StaticTestsTreeBuilder.create();
const testsTreeBuilder = StaticTestsTreeBuilder.create({toolName});

const suitesRows = (db.prepare(commonSqliteUtils.selectAllSuitesQuery())
.raw()
Expand Down
3 changes: 2 additions & 1 deletion lib/plugin-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as utils from './server-utils';
import {cliCommands} from './cli-commands';
import {HtmlReporter} from './plugin-api';
import {HtmlReporterApi, ReporterConfig, ReporterOptions} from './types';
import {ToolName} from './constants';

type PrepareFn = (hermione: Hermione & HtmlReporterApi, reportBuilder: StaticReportBuilder, config: ReporterConfig) => Promise<void>;

Expand All @@ -33,7 +34,7 @@ export class PluginAdapter {
}

addApi(): this {
this._hermione.htmlReporter = HtmlReporter.create(this._config);
this._hermione.htmlReporter = HtmlReporter.create(this._config, {toolName: ToolName.Hermione});
return this;
}

Expand Down
24 changes: 18 additions & 6 deletions lib/plugin-api.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
import EventsEmitter2 from 'eventemitter2';
import {PluginEvents} from './constants';
import {PluginEvents, ToolName} from './constants';
import {downloadDatabases, mergeDatabases, getTestsTreeFromDatabase} from './db-utils/server';
import {LocalImagesSaver} from './local-images-saver';
import {version} from '../package.json';
import {ImagesSaver, ReporterConfig, ReportsSaver} from './types';

interface HtmlReporterValues {
toolName: ToolName;
extraItems: Record<string, string>;
metaInfoExtenders: Record<string, string>;
imagesSaver: ImagesSaver;
reportsSaver: ReportsSaver | null;
}

interface ReporterOptions {
toolName: ToolName;
}

type ParametersExceptFirst<F> = F extends (arg0: any, ...rest: infer R) => any ? R : never;

export class HtmlReporter extends EventsEmitter2 {
protected _config: ReporterConfig;
protected _values: HtmlReporterValues;
protected _version: string;

static create<T extends HtmlReporter>(this: new (config: ReporterConfig) => T, config: ReporterConfig): T {
return new this(config);
static create<T extends HtmlReporter>(
this: new (config: ReporterConfig, options: ReporterOptions) => T,
config: ReporterConfig,
options: ReporterOptions
): T {
return new this(config, options);
}

constructor(config: ReporterConfig) {
constructor(config: ReporterConfig, {toolName}: ReporterOptions) {
super();

this._config = config;
this._values = {
toolName,
extraItems: {},
metaInfoExtenders: {},
imagesSaver: LocalImagesSaver,
Expand Down Expand Up @@ -91,7 +103,7 @@ export class HtmlReporter extends EventsEmitter2 {
return mergeDatabases(...args);
}

getTestsTreeFromDatabase(...args: Parameters<typeof getTestsTreeFromDatabase>): ReturnType<typeof getTestsTreeFromDatabase> {
return getTestsTreeFromDatabase(...args);
getTestsTreeFromDatabase(...args: ParametersExceptFirst<typeof getTestsTreeFromDatabase>): ReturnType<typeof getTestsTreeFromDatabase> {
return getTestsTreeFromDatabase(this.values.toolName, ...args);
}
}
3 changes: 1 addition & 2 deletions lib/report-builder/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ import {
} from '../constants';
import {PreparedTestResult, SqliteAdapter} from '../sqlite-adapter';
import {ReporterTestResult} from '../test-adapter';
import {hasNoRefImageErrors} from '../static/modules/utils';
import {hasImage, saveStaticFilesToReportDir, writeDatabaseUrlsFile} from '../server-utils';
import {ReporterConfig} from '../types';
import {HtmlReporter} from '../plugin-api';
import {ImageHandler} from '../image-handler';
import {SqliteImageStore} from '../image-store';
import {getUrlWithBase, getError, getRelativeUrl, hasDiff} from '../common-utils';
import {getUrlWithBase, getError, getRelativeUrl, hasDiff, hasNoRefImageErrors} from '../common-utils';
import {getTestFromDb} from '../db-utils/server';

const ignoredStatuses = [RUNNING, IDLE];
Expand Down
3 changes: 2 additions & 1 deletion lib/static/modules/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export const initStaticReport = () => {
await plugins.loadAll(dataFromStaticFile.config);

performance?.mark?.(performanceMarks.PLUGINS_LOADED);
const testsTreeBuilder = StaticTestsTreeBuilder.create();
const {toolName} = dataFromStaticFile.apiValues;
const testsTreeBuilder = StaticTestsTreeBuilder.create({toolName});

if (!db || isEmpty(fetchDbDetails)) {
return dispatch({
Expand Down
218 changes: 0 additions & 218 deletions lib/static/modules/utils.js

This file was deleted.

16 changes: 11 additions & 5 deletions lib/static/modules/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

const {isEmpty, find, isFunction, flatMap} = require('lodash');
const {isIdleStatus, isSuccessStatus, isUpdatedStatus, isFailStatus, isErrorStatus, isSkippedStatus, isNoRefImageError} = require('../../../common-utils');
const {ViewMode} = require('../../constants/view-modes');
const {SECTIONS, RESULT_KEYS, KEY_DELIMITER} = require('../../constants/group-tests');
const {getUpdatedProperty} = require('./state');
const {ViewMode, SECTIONS, RESULT_KEYS, KEY_DELIMITER} = require('../../../constants');
const {applyStateUpdate, ensureDiffProperty, getUpdatedProperty} = require('./state');
const {PWT_TITLE_DELIMITER} = require('../../../constants');

const AVAILABLE_GROUP_SECTIONS = Object.values(SECTIONS);

Expand Down Expand Up @@ -51,9 +51,12 @@ function isTestNameMatchFilters(testName, testNameFilter, strictMatchFilter) {
return true;
}

const testNamePlain = testName.replaceAll(PWT_TITLE_DELIMITER, ' ');
const testNameFilterPlain = testNameFilter.replaceAll(PWT_TITLE_DELIMITER, ' ');

return strictMatchFilter
? testName === testNameFilter
: testName.includes(testNameFilter);
? testNamePlain === testNameFilterPlain
: testNamePlain.includes(testNameFilterPlain);
}

function isBrowserMatchViewMode(browser, lastResult, viewMode, diff = browser) {
Expand Down Expand Up @@ -135,6 +138,9 @@ function preloadImage(url) {
}

module.exports = {
applyStateUpdate,
ensureDiffProperty,
getUpdatedProperty,
isSuiteIdle,
isSuiteSuccessful,
isNodeFailed,
Expand Down
1 change: 0 additions & 1 deletion lib/test-adapter/cache/playwright.ts

This file was deleted.

Loading

0 comments on commit ce509b6

Please sign in to comment.