Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: strip ansi markup for error message #589

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'}});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need await here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually no, but I added it for consistency

});

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need those awaits as far as I can tell... But of course they won't break nothing.

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
Loading