Skip to content

Commit

Permalink
fix: escape some special characters if present in test name (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
devpow112 authored Nov 15, 2024
1 parent a2f957d commit e5d7268
Show file tree
Hide file tree
Showing 14 changed files with 174 additions and 55 deletions.
3 changes: 2 additions & 1 deletion src/helpers/report-builder.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { randomUUID } = require('node:crypto');
const { resolve } = require('node:path');
const { ReportConfiguration } = require('./report-configuration.cjs');
const { writeFileSync } = require('node:fs');
const { escapeSpecialCharacters } = require('./strings.cjs');

const defaultReportPath = './d2l-test-report.json';
const reportMemberPriority = [
Expand Down Expand Up @@ -186,7 +187,7 @@ class ReportDetailBuilder extends ReportBuilderBase {
}

setName(name, options) {
this._setProperty('name', name, options);
this._setProperty('name', escapeSpecialCharacters(name), options);

return this;
}
Expand Down
11 changes: 11 additions & 0 deletions src/helpers/strings.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const escapeSpecialCharacters = (str) => {
return str
.replace(/[\\]/g, '\\\\')
.replace(/[\b]/g, '\\b')
.replace(/[\f]/g, '\\f')
.replace(/[\n]/g, '\\n')
.replace(/[\r]/g, '\\r')
.replace(/[\t]/g, '\\t');
};

module.exports = { escapeSpecialCharacters };
2 changes: 2 additions & 0 deletions test/integration/data/tests/mocha/reporter-1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ describe('reporter 1', () => {

it('failed', () => { throw new Error('fail'); });

it('special/characters "(\n\r\t\b\f)"', async() => { await delay(); });

afterEach(async() => { await delay(250); });

after(async() => { await delay(250); });
Expand Down
2 changes: 2 additions & 0 deletions test/integration/data/tests/mocha/reporter-2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ describe('reporter 2', () => {

it('failed', () => { throw new Error('fail'); });

it('special/characters "(\n\r\t\b\f)"', async() => { await delay(); });

afterEach(async() => { await delay(250); });

after(async() => { await delay(250); });
Expand Down
2 changes: 2 additions & 0 deletions test/integration/data/tests/mocha/reporter-3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ describe('reporter 3', () => {

it('failed', () => { throw new Error('fail'); });

it('special/characters "(\n\r\t\b\f)"', async() => { await delay(); });

afterEach(async() => { await delay(250); });

after(async() => { await delay(250); });
Expand Down
2 changes: 2 additions & 0 deletions test/integration/data/tests/playwright/reporter-1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ test.describe('reporter 1', () => {
throw new Error('fail');
});

test('special/characters "(\n\r\t\b\f)"', async() => { await delay(); });

test.afterEach(async() => { await delay(250); });

test.afterAll(async() => { await delay(250); });
Expand Down
2 changes: 2 additions & 0 deletions test/integration/data/tests/playwright/reporter-2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ test.describe('reporter 2', () => {
throw new Error('fail');
});

test('special/characters "(\n\r\t\b\f)"', async() => { await delay(); });

test.afterEach(async() => { await delay(250); });

test.afterAll(async() => { await delay(250); });
Expand Down
2 changes: 2 additions & 0 deletions test/integration/data/tests/playwright/reporter-3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ test.describe('reporter 3', () => {
throw new Error('fail');
});

test('special/characters "(\n\r\t\b\f)"', async() => { await delay(); });

test.afterEach(async() => { await delay(250); });

test.afterAll(async() => { await delay(250); });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ describe('reporter 1', () => {

it('failed', () => { throw new Error('fail'); });

it('special/characters "(\n\r\t\b\f)"', async() => { await delay(); });

afterEach(async() => { await delay(250); });

after(async() => { await delay(250); });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ describe('reporter 2', () => {

it('failed', () => { throw new Error('fail'); });

it('special/characters "(\n\r\t\b\f)"', async() => { await delay(); });

afterEach(async() => { await delay(250); });

after(async() => { await delay(250); });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ describe('reporter 3', () => {

it('failed', () => { throw new Error('fail'); });

it('special/characters "(\n\r\t\b\f)"', async() => { await delay(); });

afterEach(async() => { await delay(250); });

after(async() => { await delay(250); });
Expand Down
25 changes: 19 additions & 6 deletions test/integration/data/validation/test-report-mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ export const testReportV2Partial = {
summary: {
status: 'failed',
framework: 'mocha',
count: {
passed: 2,
failed: 2,
skipped: 2,
flaky: 2
}
count: { passed: 4, failed: 2, skipped: 2, flaky: 2 }
},
details: [{
name: 'reporter 1 > passed',
Expand Down Expand Up @@ -82,5 +77,23 @@ export const testReportV2Partial = {
experience: 'Mocha 2 Test Framework',
type: 'integration',
retries: 3
}, {
name: 'reporter 1 > special/characters "(\\n\\r\\t\\b\\f)"',
status: 'passed',
location: { file: 'test/integration/data/tests/mocha/reporter-1.test.js' },
timeout: 2000,
tool: 'Mocha 1 Test Reporting',
experience: 'Test Framework',
type: 'ui',
retries: 0
}, {
name: 'reporter 2 > special/characters "(\\n\\r\\t\\b\\f)"',
status: 'passed',
location: { file: 'test/integration/data/tests/mocha/reporter-2.test.js' },
timeout: 2000,
tool: 'Test Reporting',
experience: 'Mocha 2 Test Framework',
type: 'integration',
retries: 0
}]
};
77 changes: 71 additions & 6 deletions test/integration/data/validation/test-report-playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ export const testReportV2Partial = {
summary: {
status: 'failed',
framework: 'playwright',
count: {
passed: 15,
failed: 5,
skipped: 30,
flaky: 5
}
count: { passed: 20, failed: 5, skipped: 30, flaky: 5 }
},
details: [{
name: '[chromium] > reporter 1 > skipped static, fixme',
Expand Down Expand Up @@ -780,5 +775,75 @@ export const testReportV2Partial = {
experience: 'Playwright 2 Test Framework',
type: 'visual diff',
retries: 0
}, {
name: '[chromium] > reporter 1 > special/characters "(\\n\\r\\t\\b\\f)"',
status: 'passed',
location: {
file: 'test/integration/data/tests/playwright/reporter-1.test.js',
line: 58,
column: 2
},
browser: 'chromium',
timeout: 30000,
tool: 'Playwright 1 Test Reporting',
experience: 'Playwright 1 Test Framework',
type: 'integration',
retries: 0
}, {
name: '[chromium] > reporter 2 > special/characters "(\\n\\r\\t\\b\\f)"',
status: 'passed',
location: {
file: 'test/integration/data/tests/playwright/reporter-2.test.js',
line: 58,
column: 2
},
browser: 'chromium',
timeout: 30000,
tool: 'Test Reporting',
experience: 'Playwright 2 Test Framework',
type: 'visual diff',
retries: 0
}, {
name: '[firefox] > reporter 2 > special/characters "(\\n\\r\\t\\b\\f)"',
status: 'passed',
location: {
file: 'test/integration/data/tests/playwright/reporter-2.test.js',
line: 58,
column: 2
},
browser: 'firefox',
timeout: 30000,
tool: 'Test Reporting',
experience: 'Playwright 2 Test Framework',
type: 'visual diff',
retries: 0
}, {
name: '[webkit] > reporter 1 > special/characters "(\\n\\r\\t\\b\\f)"',
status: 'passed',
location: {
file: 'test/integration/data/tests/playwright/reporter-1.test.js',
line: 58,
column: 2
},
browser: 'webkit',
timeout: 30000,
tool: 'Playwright 1 Test Reporting',
experience: 'Playwright 1 Test Framework',
type: 'integration',
retries: 0
}, {
name: '[webkit] > reporter 2 > special/characters "(\\n\\r\\t\\b\\f)"',
status: 'passed',
location: {
file: 'test/integration/data/tests/playwright/reporter-2.test.js',
line: 58,
column: 2
},
browser: 'webkit',
timeout: 30000,
tool: 'Test Reporting',
experience: 'Playwright 2 Test Framework',
type: 'visual diff',
retries: 0
}]
};
Loading

0 comments on commit e5d7268

Please sign in to comment.