Skip to content

Commit

Permalink
test: fix e2e and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowusr committed Sep 22, 2023
1 parent 2526ed7 commit d8f6150
Show file tree
Hide file tree
Showing 17 changed files with 1,025 additions and 509 deletions.
16 changes: 10 additions & 6 deletions lib/common-utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import crypto from 'crypto';
import {pick, isEmpty} from 'lodash';
import {pick, isEmpty, omitBy} from 'lodash';
import url from 'url';
import axios, {AxiosRequestConfig} from 'axios';
import {SUCCESS, FAIL, ERROR, SKIPPED, UPDATED, IDLE, RUNNING, QUEUED, TestStatus} from './constants';

import {UNCHECKED, INDETERMINATE, CHECKED} from './constants/checked-statuses';
import {AssertViewResult, ImageInfoFull, TestError, ImageInfoError} from './types';
import {AssertViewResult, ImageData, ImageBase64, ImageInfoFull, TestError, ImageInfoError} from './types';
import {ErrorName, ImageDiffError, NoRefImageError} from './errors';
export const getShortMD5 = (str: string): string => {
return crypto.createHash('md5').update(str, 'ascii').digest('hex').substr(0, 7);
Expand Down Expand Up @@ -96,8 +96,8 @@ export const isImageDiffError = (error?: unknown): error is ImageDiffError => {
return (error as {name?: string})?.name === ErrorName.IMAGE_DIFF;
};

export const isNoRefImageError = (assertResult: AssertViewResult): assertResult is NoRefImageError => {
return (assertResult as NoRefImageError).name === ErrorName.NO_REF_IMAGE;
export const isNoRefImageError = (error?: unknown): error is NoRefImageError => {
return (error as {name?: string})?.name === ErrorName.NO_REF_IMAGE;
};

export const hasNoRefImageErrors = ({assertViewResults = []}: {assertViewResults?: AssertViewResult[]}): boolean => {
Expand All @@ -123,7 +123,11 @@ export const getError = (error?: TestError): undefined | Pick<TestError, 'name'
};

export const hasDiff = (assertViewResults: AssertViewResult[]): boolean => {
return assertViewResults.some((result) => isImageDiffError(result));
return assertViewResults.some((result) => isImageDiffError(result as {name?: string}));
};

export const isBase64Image = (image: ImageData | ImageBase64 | undefined): image is ImageBase64 => {
return Boolean((image as ImageBase64 | undefined)?.base64);
};

export const isUrl = (str: string): boolean => {
Expand All @@ -138,7 +142,7 @@ export const isUrl = (str: string): boolean => {

export const buildUrl = (href: string, {host, protocol}: {host?: string, protocol?: string} = {}): string => {
return host
? url.format(Object.assign(url.parse(href), {host, protocol}))
? url.format(Object.assign(url.parse(href), omitBy({host, protocol}, isEmpty)))
: href;
};

Expand Down
10 changes: 8 additions & 2 deletions lib/report-builder/static.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class StaticReportBuilder {
}

protected _addErrorResult(formattedResult: ReporterTestResult): ReporterTestResult {
return this._addTestResult(formattedResult, {status: ERROR, error: getError(formattedResult.error)});
return this._addTestResult(formattedResult, {status: ERROR});
}

protected _addTestResult(formattedResult: ReporterTestResult, props: {status: TestStatus} & Partial<PreparedTestResult>): ReporterTestResult {
Expand Down Expand Up @@ -147,13 +147,19 @@ export class StaticReportBuilder {

const {baseHost, saveErrorDetails} = this._pluginConfig;
const suiteUrl: string = getAbsoluteUrl(result.url, baseHost);
const metaInfo = _.merge(_.cloneDeep(result.meta), {url: getRelativeUrl(suiteUrl) ?? '', file, sessionId});
const metaInfoFull = _.merge(_.cloneDeep(result.meta), {url: getRelativeUrl(suiteUrl) ?? '', file, sessionId});
const metaInfo = _.omitBy(metaInfoFull, _.isEmpty);

const testResult: PreparedTestResult = Object.assign({
suiteUrl, name: browserId, metaInfo, description, history,
imagesInfo, screenshot: Boolean(screenshot), multipleTabs
}, props);

const error = getError(result.error);
if (!_.isEmpty(error)) {
testResult.error = error;
}

if (saveErrorDetails && errorDetails) {
testResult.errorDetails = _.pick(errorDetails, ['title', 'filePath']);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/static/components/retry-switcher/item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export default connect(
const matchedSelectedGroup = get(tree.results.stateById[resultId], 'matchedSelectedGroup', false); // everything's ok until...
const {status, attempt, error} = result;

console.log(result);
console.log(error);
console.log(status);
console.log(hasUnrelatedToScreenshotsErrors(status, error));
console.log(hasUnrelatedToScreenshotsErrors(status, error) ? `${status}_${ERROR}` : status);

return {
status: hasUnrelatedToScreenshotsErrors(status, error) ? `${status}_${ERROR}` : status,
attempt,
Expand Down
243 changes: 0 additions & 243 deletions lib/test-adapter/playwright.ts

This file was deleted.

Loading

0 comments on commit d8f6150

Please sign in to comment.