Skip to content

Commit

Permalink
Merge pull request #589 from gemini-testing/sp.fix-ansi
Browse files Browse the repository at this point in the history
fix: strip ansi markup for error message
  • Loading branch information
sipayRT authored Aug 9, 2024
2 parents 0e43b10 + a60522e commit 6b214cd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/static/components/state/state-error.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {isEmpty, map, isFunction} from 'lodash';
import ReactHtmlParser from 'html-react-parser';
import escapeHtml from 'escape-html';
import ansiHtml from 'ansi-html-community';
import stripAnsi from 'strip-ansi';
import * as actions from '../../modules/actions';
import ResizedScreenshot from './screenshot/resized';
import ErrorDetails from './error-details';
Expand Down Expand Up @@ -95,7 +96,7 @@ class StateError extends Component {
content = isFunction(value) ? value : () => value;
}

const title = <Fragment><span className="error__item-key">{key}: </span>{titleText}</Fragment>;
const title = <Fragment><span className="error__item-key">{key}: </span>{stripAnsi(titleText)}</Fragment>;
const asHtml = typeof content === 'string';

return <Details
Expand Down
4 changes: 4 additions & 0 deletions test/func/fixtures/testplane/failed-describe.testplane.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ describe('failed describe', function() {
throw new Error('Some error');
});

it('failed test with ansi markup', async () => {
await expect({a: {b: 'c'}}).toMatchObject({c: {b: 'a'}});
});

it.skip('test skipped', async ({browser}) => {
await browser.url(browser.options.baseUrl);
});
Expand Down
19 changes: 14 additions & 5 deletions test/func/tests/common/test-results-appearance.testplane.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('Test results appearance', () => {

it('should display 3 images', async ({browser}) => {
for (const imageStatus of ['Expected', 'Actual', 'Diff']) {
const imageElement = browser.$(
const imageElement = await browser.$(
getTestSectionByNameSelector('test with image comparison diff') +
getImageSectionSelector(imageStatus) +
'//img'
Expand All @@ -57,7 +57,7 @@ describe('Test results appearance', () => {

it('should not display error info', async ({browser}) => {
for (const field of ['message', 'name', 'stack']) {
const errorMessage = browser.$(
const errorMessage = await browser.$(
getTestSectionByNameSelector('test with image comparison diff') +
getTestStateByNameSelector('header') +
getElementWithTextSelector('span', field) + '/..'
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('Test results appearance', () => {

it('should display error message, name and stack', async ({browser}) => {
for (const field of ['message', 'name', 'stack']) {
const errorMessage = browser.$(
const errorMessage = await browser.$(
getTestSectionByNameSelector('test without screenshot') +
getTestStateByNameSelector('header') +
getElementWithTextSelector('span', field) + '/..'
Expand All @@ -97,7 +97,7 @@ describe('Test results appearance', () => {
});

it('should display actual screenshot', async ({browser}) => {
const imageElement = browser.$(
const imageElement = await browser.$(
getTestSectionByNameSelector('test without screenshot') +
'//' + getSpoilerByNameSelector('header') +
'//img'
Expand All @@ -124,14 +124,23 @@ describe('Test results appearance', () => {

it('should display error message, name and stack', async ({browser}) => {
for (const field of ['message', 'name', 'stack']) {
const errorMessage = browser.$(
const errorMessage = await browser.$(
getTestSectionByNameSelector('test with long error message') +
getElementWithTextSelector('span', field) + '/..'
);

await expect(errorMessage).toBeDisplayed();
}
});

it('should show message without ansi markup', async ({browser}) => {
const expectedErrorText = 'expect(received).toMatchObject(expected)';
const testElem = await browser.$(getTestSectionByNameSelector('failed test with ansi markup'));

const errorText = await testElem.$('.tab .error__item.details__summary').getText();

assert.equal(errorText, `message: ${expectedErrorText}`);
});
});

describe('Test with successful assertView and error', () => {
Expand Down

0 comments on commit 6b214cd

Please sign in to comment.