cenfun / monocart-reporter

A playwright test reporter (Node.js)
https://cenfun.github.io/monocart-reporter/
MIT License
194 stars 11 forks source link

[Question] Put Style Tags in new column #119

Closed jensencp7 closed 4 months ago

jensencp7 commented 4 months ago

Hi Cen ,

How do i put the tags in a new column instead of infront of the test title as seen in screenshot. For example i would like to move it to a new column after the JIRA # column.

below is my reporter config

reporter: [['line'],['monocart-reporter', { name: "Infinity Test Report", outputFile: 'test-results/report.html', tags: { 'Positive': { style: { background: '#0000FF' }, description: 'This is Smoke Test' }, Negative: { background: '#FFA500' } }, // 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 #',
        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>`;
        }

    });

}

}]],

image
cenfun commented 4 months ago

Please try new version 2.4.7:

columns: (defaultColumns) => {

                // disable title tags
                defaultColumns.find((column) => column.id === 'title').titleTagsDisabled = true;

                // add tags column
                const index = defaultColumns.findIndex((column) => column.id === 'type');
                defaultColumns.splice(index, 0, {
                    id: 'tags',
                    name: 'Tags',
                    width: 150,
                    formatter: 'tags'
                });
            }

see example: https://github.com/cenfun/monocart-reporter-examples/tree/main/tests/tags-column

image

jensencp7 commented 4 months ago

tested on my side works great. just a side note we should probably move tags to the annotations instead of test title.. In your screenshot above the @positive in the test title becomes redundant if we have a separate column for tags. Your choice , let me know.

thanks again !

cenfun commented 4 months ago

Yes, it is because the tag is part of the title, personally, I don't think it should be removed. However we can use the new syntax to separate the tag from the title.

test('test', {  tag: ['@Negative']  }, async () => {

});

see https://playwright.dev/docs/test-annotations#tag-tests

jensencp7 commented 4 months ago

happy , please close :)