UNPKG

playwright-trx-reporter

Version:

TRX reporter for playwright

76 lines (75 loc) 3.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Trx = exports.TrxMetadataManager = exports.TRX_METADATA_ATTACHMENT_CONTENT_TYPE = void 0; const test_1 = require("@playwright/test"); const assert_1 = require("./assert"); exports.TRX_METADATA_ATTACHMENT_CONTENT_TYPE = 'application/vnd.trx.metadata+json'; const TRX_METADATA_ATTACHMENT_FILE_NAME = 'trx-metadata.json'; var TrxUserConfigurable; (function (TrxUserConfigurable) { TrxUserConfigurable["owner"] = "trx-owner"; TrxUserConfigurable["workItemIds"] = "trx-wotkItemIds"; TrxUserConfigurable["priority"] = "trx-priority"; })(TrxUserConfigurable || (TrxUserConfigurable = {})); // use `annotation` to store meta info // could collect a meta data // the later one will override the previous one in attachment class TrxMetadataManager { static setInfo(key, value) { test_1.test.info().annotations.push({ type: key, description: JSON.stringify(value), }); } // collect metadata for current test // TODO: maybe we should collect from attachment, wait for the feedback from users. static collectMetadata(annotations) { const trxAnnotations = annotations.filter(annotation => annotation.type.startsWith('trx')); // the later one will override the previous one. const metadataInit = {}; return trxAnnotations.reduce((metadata, trxAnnotation) => { const key = trxAnnotation.type; const value = JSON.parse(trxAnnotation.description); switch (key) { case TrxUserConfigurable.owner: metadata.owner = value; break; case TrxUserConfigurable.workItemIds: metadata.workItemIds = value; break; case TrxUserConfigurable.priority: metadata.priority = value; break; default: (0, assert_1.assertNever)(key); } return metadata; }, metadataInit); } static addMetadataAttachment() { const testInfo = test_1.test.info(); const metadata = this.collectMetadata(testInfo.annotations); testInfo.attach(TRX_METADATA_ATTACHMENT_FILE_NAME, { contentType: exports.TRX_METADATA_ATTACHMENT_CONTENT_TYPE, body: Buffer.from(JSON.stringify(metadata), 'utf8'), }); } } exports.TrxMetadataManager = TrxMetadataManager; class Trx { // set owner for current test static owner(owner) { TrxMetadataManager.setInfo(TrxUserConfigurable.owner, owner); } // // set workItemIds for current test // static workItemIds(ids:string[]){ // TrxMetadataManager.setInfo( // TrxUserConfigurable.workItemIds, // ids, // ); // } static priority(priority) { TrxMetadataManager.setInfo(TrxUserConfigurable.priority, priority); } } exports.Trx = Trx;