Skip to content

Commit 6b214cd

Browse files
authored
Merge pull request #589 from gemini-testing/sp.fix-ansi
fix: strip ansi markup for error message
2 parents 0e43b10 + a60522e commit 6b214cd

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

lib/static/components/state/state-error.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {isEmpty, map, isFunction} from 'lodash';
88
import ReactHtmlParser from 'html-react-parser';
99
import escapeHtml from 'escape-html';
1010
import ansiHtml from 'ansi-html-community';
11+
import stripAnsi from 'strip-ansi';
1112
import * as actions from '../../modules/actions';
1213
import ResizedScreenshot from './screenshot/resized';
1314
import ErrorDetails from './error-details';
@@ -95,7 +96,7 @@ class StateError extends Component {
9596
content = isFunction(value) ? value : () => value;
9697
}
9798

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

101102
return <Details

test/func/fixtures/testplane/failed-describe.testplane.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ describe('failed describe', function() {
2929
throw new Error('Some error');
3030
});
3131

32+
it('failed test with ansi markup', async () => {
33+
await expect({a: {b: 'c'}}).toMatchObject({c: {b: 'a'}});
34+
});
35+
3236
it.skip('test skipped', async ({browser}) => {
3337
await browser.url(browser.options.baseUrl);
3438
});

test/func/tests/common/test-results-appearance.testplane.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('Test results appearance', () => {
4242

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

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

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

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

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

132132
await expect(errorMessage).toBeDisplayed();
133133
}
134134
});
135+
136+
it('should show message without ansi markup', async ({browser}) => {
137+
const expectedErrorText = 'expect(received).toMatchObject(expected)';
138+
const testElem = await browser.$(getTestSectionByNameSelector('failed test with ansi markup'));
139+
140+
const errorText = await testElem.$('.tab .error__item.details__summary').getText();
141+
142+
assert.equal(errorText, `message: ${expectedErrorText}`);
143+
});
135144
});
136145

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

0 commit comments

Comments
 (0)