fix(junit reporter): remove source location from classname attribute (#16499)

This commit is contained in:
Sergio Freire 2022-08-20 00:42:21 +01:00 committed by GitHub
parent ba722a2580
commit abe7cf23a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 5 deletions

View file

@ -356,10 +356,14 @@ function stepSuffix(step: TestStep | undefined) {
return stepTitles.map(t => ' ' + t).join('');
}
export function formatTestTitle(config: FullConfig, test: TestCase, step?: TestStep): string {
export function formatTestTitle(config: FullConfig, test: TestCase, step?: TestStep, omitLocation: boolean = false): string {
// root, project, file, ...describes, test
const [, projectName, , ...titles] = test.titlePath();
const location = `${relativeTestPath(config, test)}:${test.location.line}:${test.location.column}`;
let location;
if (omitLocation)
location = `${relativeTestPath(config, test)}`;
else
location = `${relativeTestPath(config, test)}:${test.location.line}:${test.location.column}`;
const projectTitle = projectName ? `[${projectName}] ` : '';
return `${projectTitle}${location} ${titles.join(' ')}${stepSuffix(step)}`;
}

View file

@ -133,7 +133,7 @@ class JUnitReporter implements Reporter {
attributes: {
// Skip root, project, file
name: test.titlePath().slice(3).join(' '),
classname: formatTestTitle(this.config, test),
classname: formatTestTitle(this.config, test, undefined, true),
time: (test.results.reduce((acc, value) => acc + value.duration, 0)) / 1000
},
children: [] as XMLEntry[]

View file

@ -212,6 +212,31 @@ test('should report skipped due to sharding', async ({ runInlineTest }) => {
expect(result.exitCode).toBe(0);
});
test('should not render projects if they dont exist', async ({ runInlineTest }) => {
const result = await runInlineTest({
'playwright.config.ts': `
module.exports = { };
`,
'a.test.js': `
const { test } = pwt;
test('one', async ({}) => {
expect(1).toBe(1);
});
`,
}, { reporter: 'junit' });
const xml = parseXML(result.output);
expect(xml['testsuites']['$']['tests']).toBe('1');
expect(xml['testsuites']['$']['failures']).toBe('0');
expect(xml['testsuites']['testsuite'].length).toBe(1);
expect(xml['testsuites']['testsuite'][0]['$']['name']).toBe('a.test.js');
expect(xml['testsuites']['testsuite'][0]['$']['tests']).toBe('1');
expect(xml['testsuites']['testsuite'][0]['$']['failures']).toBe('0');
expect(xml['testsuites']['testsuite'][0]['$']['skipped']).toBe('0');
expect(xml['testsuites']['testsuite'][0]['testcase'][0]['$']['name']).toBe('one');
expect(xml['testsuites']['testsuite'][0]['testcase'][0]['$']['classname']).toContain('a.test.js one');
expect(result.exitCode).toBe(0);
});
test('should render projects', async ({ runInlineTest }) => {
const result = await runInlineTest({
@ -235,14 +260,14 @@ test('should render projects', async ({ runInlineTest }) => {
expect(xml['testsuites']['testsuite'][0]['$']['failures']).toBe('0');
expect(xml['testsuites']['testsuite'][0]['$']['skipped']).toBe('0');
expect(xml['testsuites']['testsuite'][0]['testcase'][0]['$']['name']).toBe('one');
expect(xml['testsuites']['testsuite'][0]['testcase'][0]['$']['classname']).toContain('[project1] a.test.js:6:7 one');
expect(xml['testsuites']['testsuite'][0]['testcase'][0]['$']['classname']).toContain('[project1] a.test.js one');
expect(xml['testsuites']['testsuite'][1]['$']['name']).toBe('a.test.js');
expect(xml['testsuites']['testsuite'][1]['$']['tests']).toBe('1');
expect(xml['testsuites']['testsuite'][1]['$']['failures']).toBe('0');
expect(xml['testsuites']['testsuite'][1]['$']['skipped']).toBe('0');
expect(xml['testsuites']['testsuite'][1]['testcase'][0]['$']['name']).toBe('one');
expect(xml['testsuites']['testsuite'][1]['testcase'][0]['$']['classname']).toContain('[project2] a.test.js:6:7 one');
expect(xml['testsuites']['testsuite'][1]['testcase'][0]['$']['classname']).toContain('[project2] a.test.js one');
expect(result.exitCode).toBe(0);
});