Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix incorrect behavior for diff and no ref errors
Browse files Browse the repository at this point in the history
shadowusr committed Sep 20, 2023
1 parent 55e9ddd commit d482e7f
Showing 10 changed files with 21 additions and 9 deletions.
8 changes: 6 additions & 2 deletions lib/common-utils.ts
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ 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, ImageData, ImageBase64, ImageInfoFull, TestError} 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);
@@ -87,6 +87,10 @@ export const mkTestId = (fullTitle: string, browserId: string): string => {
return fullTitle + '.' + browserId;
};

export const isAssertViewError = (error?: unknown): boolean => {
return (error as {name?: string})?.name === ErrorName.ASSERT_VIEW;
};

export const isImageDiffError = (error?: unknown): error is ImageDiffError => {
return (error as {name?: string})?.name === ErrorName.IMAGE_DIFF;
};
@@ -102,7 +106,7 @@ export const hasNoRefImageErrors = ({assertViewResults = []}: {assertViewResults
const hasFailedImages = (result: {imagesInfo?: ImageInfoFull[]}): boolean => {
const {imagesInfo = []} = result;

return imagesInfo.some((imageInfo: ImageInfoFull) => isErroredStatus(imageInfo.status) || isFailStatus(imageInfo.status));
return imagesInfo.some((imageInfo: ImageInfoFull) => !isAssertViewError((imageInfo as ImageInfoError).error) && (isErroredStatus(imageInfo.status) || isFailStatus(imageInfo.status)));
};

export const hasResultFails = (testResult: {status: TestStatus, imagesInfo?: ImageInfoFull[]}): boolean => {
3 changes: 2 additions & 1 deletion lib/errors/index.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,8 @@ import {ValueOf} from 'type-fest';

export const ErrorName = {
IMAGE_DIFF: 'ImageDiffError',
NO_REF_IMAGE: 'NoRefImageError'
NO_REF_IMAGE: 'NoRefImageError',
ASSERT_VIEW: 'AssertViewError'
} as const;
export type ErrorName = ValueOf<typeof ErrorName>;
export type ErrorNames = typeof ErrorName;
2 changes: 1 addition & 1 deletion lib/image-handler.ts
Original file line number Diff line number Diff line change
@@ -132,7 +132,7 @@ export class ImageHandler extends EventEmitter2 implements ImagesInfoFormatter {
status = FAIL;
} else if (isNoRefImageError(assertResult)) {
status = ERROR;
error = _.pick(assertResult, ['message', 'stack']);
error = _.pick(assertResult, ['message', 'name', 'stack']);
} else {
status = SUCCESS;
}
4 changes: 2 additions & 2 deletions lib/static/components/retry-switcher/item.jsx
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import classNames from 'classnames';
import {connect} from 'react-redux';
import {get} from 'lodash';
import {ERROR} from '../../../constants/test-statuses';
import {isFailStatus, isImageDiffError, isNoRefImageError} from '../../../common-utils';
import {isAssertViewError, isFailStatus, isImageDiffError, isNoRefImageError} from '../../../common-utils';

class RetrySwitcherItem extends Component {
static propTypes = {
@@ -50,5 +50,5 @@ export default connect(
)(RetrySwitcherItem);

function hasScreenAndAssertErrors(status, error) {
return isFailStatus(status) && error && !isNoRefImageError(error) && !isImageDiffError(error);
return isFailStatus(status) && error && !isNoRefImageError(error) && !isImageDiffError(error) && !isAssertViewError(error);
}
1 change: 1 addition & 0 deletions lib/static/components/section/body/tabs.jsx
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ export default class Tabs extends Component {
? null
: this._drawTab({key: errorTabId});
}
console.log(result.imageIds);

const tabs = result.imageIds.map((imageId) => this._drawTab({key: imageId, imageId}));

4 changes: 2 additions & 2 deletions lib/static/components/state/state-error.jsx
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import ResizedScreenshot from './screenshot/resized';
import ErrorDetails from './error-details';
import Details from '../details';
import {ERROR_TITLE_TEXT_LENGTH} from '../../../constants/errors';
import {isImageDiffError, isNoRefImageError} from '../../../common-utils';
import {isAssertViewError, isImageDiffError, isNoRefImageError} from '../../../common-utils';

class StateError extends Component {
static propTypes = {
@@ -95,7 +95,7 @@ class StateError extends Component {
}

_shouldDrawErrorInfo(error) {
return !isImageDiffError(error);
return !isImageDiffError(error) && !isAssertViewError(error);
}

render() {
2 changes: 1 addition & 1 deletion lib/test-adapter/playwright.ts
Original file line number Diff line number Diff line change
@@ -160,7 +160,7 @@ export class PlaywrightTestAdapter implements ReporterTestResult {
result.stack = stack;
}

if (message.includes('snapshot doesn\'t exist') && message.endsWith('.png.')) {
if (message.includes('snapshot doesn\'t exist') && message.includes('.png')) {
result.name = ErrorName.NO_REF_IMAGE;
} else if (message.includes('Screenshot comparison failed')) {
result.name = ErrorName.IMAGE_DIFF;
6 changes: 6 additions & 0 deletions test/func/fixtures/hermione/failed-describe.hermione.js
Original file line number Diff line number Diff line change
@@ -11,6 +11,12 @@ describe('failed describe', function() {
await browser.assertView('header', 'header');
});

it('test with diff', async ({browser}) => {
await browser.url(browser.options.baseUrl);

await browser.assertView('header', 'header');
});

it('test with long error message', async () => {
throw new Error(`long_error_message ${'0123456789'.repeat(20)}\n message content`);
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d482e7f

Please sign in to comment.