feat: addition of tags to JSON reporter output (#8920)

This commit is contained in:
Darrell Breeden 2021-09-15 15:30:22 -04:00 committed by GitHub
parent fc972fcadd
commit d82cb9a2ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View File

@ -44,6 +44,7 @@ export interface JSONReportSuite {
suites?: JSONReportSuite[];
}
export interface JSONReportSpec {
tags: string[],
title: string;
ok: boolean;
tests: JSONReportTest[];
@ -203,6 +204,7 @@ class JSONReporter implements Reporter {
return {
title: test.title,
ok: test.ok(),
tags: (test.title.match(/@[\S]+/g) || []).map(t => t.substring(1)),
tests: [ this._serializeTest(test) ],
...this._relativeLocation(test.location),
};

View File

@ -139,6 +139,35 @@ test('should show steps', async ({ runInlineTest }) => {
expect(result.report.suites[0].specs[0].tests[0].results[0].steps[1].error).not.toBeUndefined();
});
test('should display tags separately from title', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.js': `
const { test } = pwt;
test('math works! @USR-MATH-001 @USR-MATH-002', async ({}) => {
expect(1 + 1).toBe(2);
await test.step('math works in a step', async () => {
expect(2 + 2).toBe(4);
await test.step('nested step', async () => {
expect(2 + 2).toBe(4);
await test.step('deeply nested step', async () => {
expect(2 + 2).toBe(4);
});
})
})
});
`
});
expect(result.exitCode).toBe(0);
expect(result.report.suites.length).toBe(1);
expect(result.report.suites[0].specs.length).toBe(1);
// Ensure the length is as expected
expect(result.report.suites[0].specs[0].tags.length).toBe(2);
// Ensure that the '@' value is stripped
expect(result.report.suites[0].specs[0].tags[0]).toBe('USR-MATH-001');
expect(result.report.suites[0].specs[0].tags[1]).toBe('USR-MATH-002');
});
test('should have relative always-posix paths', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.js': `