I'm using playwright to run my e2e tests, and i've installed monocart-reporter https://www.npmjs.com/package/monocart-reporter#examples to try to add the "owner" tag for each test, so that when a specific test fails a specific owner gets emailed.
However, I cannot figure out how to add the @owner tag which should be pretty straightforward according to the monocart-reporter docs.
This is in my playwright config:
export function createConfig(options: ICreatePlaywrightConfig): PlaywrightTestConfig {
...(other info here)....
reporter: [
['monocart-reporter', {
name: "My Test Report",
outputFile: './test-results/report.html',
embedAnnotationsAsProperties: true,
// custom columns
columns: (defaultColumns) => {
// insert custom column(s) before a default column
const index = defaultColumns.findIndex((column) => column.id === 'duration');
defaultColumns.splice(index, 0, {
// define the column in reporter
id: 'owner',
name: 'Owner',
align: 'center',
searchable: true,
styleMap: {
'font-weight': 'normal'
}
}, {
// another column for JIRA link
id: 'jira',
name: 'JIRA Key',
width: 100,
searchable: true,
styleMap: 'font-weight:normal;',
formatter: (v, rowItem, columnItem) => {
const key = rowItem[columnItem.id];
return `<a href="https://your-jira-url/${key}" target="_blank">${v}</a>`;
}
});
}
}]
]
};
return config;
}
and this is my test: (test-name.spec.ts)
import { test, expect } from "@playwright/test";
import { goToPage, waitForSuccessApi } from "../../common/testUtils";
import { customReporter, addWorkItem } from "../../common/custom-reporter"; // hackathon
import type { TestResult } from '@playwright/test/reporter';
/*
* @owner Kevin
* @jira MCR-16888
*/
test.describe("HomePage", () => {
// @owner Steve
test("should load the homepage with a user id", async ({ page }) => {
// @owner Steve
await goToPage(page, "/mainpage");
await page.locator("'Search using a User Id'").waitFor();
await expect(page.locator('h2:has-text("Welcome to HomePage")')).toBeVisible();
});
});
^ all the owner tags are me trying to append the owner tag to this test to no avail
monocart is working (I am able to see reports and failures after running a test, but no owners in sight).
Add this after the "Columns"
visitor: (data: any, metadata: any, collect: any) => {
// auto collect data from comments
const parserOptions = {
// Indicate the mode the code should be parsed in.
// Can be one of "script", "module", or "unambiguous". Defaults to "script".
sourceType: 'module',
// enable typescript syntax. more https://babeljs.io/docs/babel-parser
plugins: ['typescript']
};
const comments = collect.comments(parserOptions);
if (comments) {
Object.assign(data, comments);
}
if (metadata.annotations) {
const jiraItem = metadata.annotations.find((item: {
type: string;
}) => item.type === 'jira');
if (jiraItem && jiraItem.description) {
data.jira = jiraItem.description;
}
const ownerItem = metadata.annotations.find((item: {
type: string;
}) => item.type === 'owner');
if (ownerItem && ownerItem.description) {
data.owner = ownerItem.description;
}
}
delete data.annotations;
},