Skip to content

Commit

Permalink
fix: various screenshot and skipped tests displaying fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowusr committed Sep 21, 2023
1 parent 9c9f8cb commit 2526ed7
Show file tree
Hide file tree
Showing 6 changed files with 18,585 additions and 21,912 deletions.
18 changes: 13 additions & 5 deletions lib/static/components/retry-switcher/item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import classNames from 'classnames';
import {connect} from 'react-redux';
import {get} from 'lodash';
import {ERROR} from '../../../constants';
import {isAssertViewError, isFailStatus, isImageDiffError, isNoRefImageError} from '../../../common-utils';
import {
isAssertViewError,
isFailStatus,
isImageDiffError,
isNoRefImageError
} from '../../../common-utils';

class RetrySwitcherItem extends Component {
static propTypes = {
Expand All @@ -30,7 +35,7 @@ class RetrySwitcherItem extends Component {
{'tab-switcher__button_non-matched': keyToGroupTestsBy && !matchedSelectedGroup}
);

return <button title={title} className={className} onClick={onClick}>{attempt + 1}</button>;
return <button title={title} className={className} onClick={onClick} data-test-id='retry-switcher'>{attempt + 1}</button>;
}
}

Expand All @@ -41,14 +46,17 @@ export default connect(
const {status, attempt, error} = result;

return {
status: hasScreenAndAssertErrors(status, error) ? `${status}_${ERROR}` : status,
status: hasUnrelatedToScreenshotsErrors(status, error) ? `${status}_${ERROR}` : status,
attempt,
keyToGroupTestsBy,
matchedSelectedGroup
};
}
)(RetrySwitcherItem);

function hasScreenAndAssertErrors(status, error) {
return isFailStatus(status) && error && !isNoRefImageError(error) && !isImageDiffError(error) && !isAssertViewError(error);
function hasUnrelatedToScreenshotsErrors(status, error) {
return isFailStatus(status) &&
!isNoRefImageError(error) &&
!isImageDiffError(error) &&
!isAssertViewError(error);
}
7 changes: 4 additions & 3 deletions lib/static/components/section/section-browser.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {Component, Fragment} from 'react';
import {last} from 'lodash';
import {last, isEmpty} from 'lodash';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import Parser from 'html-react-parser';
Expand All @@ -25,7 +25,8 @@ class SectionBrowser extends Component {
status: PropTypes.string.isRequired,
error: PropTypes.object,
imageIds: PropTypes.arrayOf(PropTypes.string).isRequired,
skipReason: PropTypes.string
skipReason: PropTypes.string,
history: PropTypes.arrayOf(PropTypes.string)
}).isRequired,
shouldBeShown: PropTypes.bool.isRequired,
shouldBeOpened: PropTypes.bool.isRequired,
Expand Down Expand Up @@ -64,7 +65,7 @@ class SectionBrowser extends Component {
: browser.name;

// Detect executed test but failed and skipped
const isExecutedResult = hasRetries || lastResult.error || lastResult.imageIds.length > 0;
const isExecutedResult = hasRetries || !isEmpty(lastResult.history) || lastResult.error || lastResult.imageIds.length > 0;
const isSkipped = isSkippedLastResult && !isExecutedResult;

const body = isSkipped || !shouldBeOpened
Expand Down
15 changes: 9 additions & 6 deletions lib/test-adapter/playwright.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {TestCase as PlaywrightTestCase, TestResult as PlaywrightTestResult} from '@playwright/test/reporter';
import sizeOf from 'image-size';
import {ReporterTestResult} from './index';
import {TestStatus} from '../constants';
import {FAIL, TestStatus} from '../constants';
import {
AssertViewResult,
ErrorDetails,
Expand All @@ -15,7 +15,7 @@ import path from 'path';
import * as utils from '../server-utils';
import {testsAttempts} from './cache/playwright';
import _ from 'lodash';
import {getShortMD5, mkTestId} from '../common-utils';
import {getShortMD5, isAssertViewError, isImageDiffError, isNoRefImageError, mkTestId} from '../common-utils';
import {ImagesInfoFormatter} from '../image-handler';
import stripAnsi from 'strip-ansi';
import {ErrorName} from '../errors';
Expand Down Expand Up @@ -49,7 +49,7 @@ const getStatus = (result: PlaywrightTestResult): TestStatus => {
result.status as PwtTestStatus
)
) {
return TestStatus.FAIL;
return TestStatus.ERROR;
}

return TestStatus.SKIPPED;
Expand Down Expand Up @@ -115,9 +115,9 @@ export class PlaywrightTestAdapter implements ReporterTestResult {

get assertViewResults(): AssertViewResult[] {
return Object.entries(this._attachmentsByState).map(([state, attachments]): AssertViewResult | null => {
const refImg = getImageData(attachments.find(a => a.path?.endsWith(ImageTitleEnding.Expected)));
const diffImg = getImageData(attachments.find(a => a.path?.endsWith(ImageTitleEnding.Diff)));
const currImg = getImageData(attachments.find(a => a.path?.endsWith(ImageTitleEnding.Actual)));
const refImg = getImageData(attachments.find(a => a.name?.endsWith(ImageTitleEnding.Expected)));
const diffImg = getImageData(attachments.find(a => a.name?.endsWith(ImageTitleEnding.Diff)));
const currImg = getImageData(attachments.find(a => a.name?.endsWith(ImageTitleEnding.Actual)));

if (this.error?.name === ErrorName.IMAGE_DIFF && refImg && diffImg && currImg) {
return {
Expand Down Expand Up @@ -218,6 +218,9 @@ export class PlaywrightTestAdapter implements ReporterTestResult {
}

get status(): TestStatus {
if (isNoRefImageError(this.error) || isImageDiffError(this.error) || isAssertViewError(this.error)) {
return FAIL;
}
return getStatus(this._testResult);
}

Expand Down
Loading

0 comments on commit 2526ed7

Please sign in to comment.