fix(junit reporter): remove source location from classname attribute (#16499)
This commit is contained in:
parent
ba722a2580
commit
abe7cf23a7
|
|
@ -356,10 +356,14 @@ function stepSuffix(step: TestStep | undefined) {
|
||||||
return stepTitles.map(t => ' › ' + t).join('');
|
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
|
// root, project, file, ...describes, test
|
||||||
const [, projectName, , ...titles] = test.titlePath();
|
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}] › ` : '';
|
const projectTitle = projectName ? `[${projectName}] › ` : '';
|
||||||
return `${projectTitle}${location} › ${titles.join(' › ')}${stepSuffix(step)}`;
|
return `${projectTitle}${location} › ${titles.join(' › ')}${stepSuffix(step)}`;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ class JUnitReporter implements Reporter {
|
||||||
attributes: {
|
attributes: {
|
||||||
// Skip root, project, file
|
// Skip root, project, file
|
||||||
name: test.titlePath().slice(3).join(' '),
|
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
|
time: (test.results.reduce((acc, value) => acc + value.duration, 0)) / 1000
|
||||||
},
|
},
|
||||||
children: [] as XMLEntry[]
|
children: [] as XMLEntry[]
|
||||||
|
|
|
||||||
|
|
@ -212,6 +212,31 @@ test('should report skipped due to sharding', async ({ runInlineTest }) => {
|
||||||
expect(result.exitCode).toBe(0);
|
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 }) => {
|
test('should render projects', async ({ runInlineTest }) => {
|
||||||
const result = await 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]['$']['failures']).toBe('0');
|
||||||
expect(xml['testsuites']['testsuite'][0]['$']['skipped']).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]['$']['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]['$']['name']).toBe('a.test.js');
|
||||||
expect(xml['testsuites']['testsuite'][1]['$']['tests']).toBe('1');
|
expect(xml['testsuites']['testsuite'][1]['$']['tests']).toBe('1');
|
||||||
expect(xml['testsuites']['testsuite'][1]['$']['failures']).toBe('0');
|
expect(xml['testsuites']['testsuite'][1]['$']['failures']).toBe('0');
|
||||||
expect(xml['testsuites']['testsuite'][1]['$']['skipped']).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]['$']['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);
|
expect(result.exitCode).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue