wdio-ms-teams-service
Version:
A WebdriverIO plugin to report to Microsoft Teams channel webhooks
81 lines (80 loc) • 2.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdaptiveCard = void 0;
class AdaptiveCard {
constructor(message, resultContainer) {
const body = [];
body.push(AdaptiveCard._generateTextBlock("Automated test results | WebdriverIO", true, "bolder"));
body.push(AdaptiveCard._generateTextBlock(message, true, "default"));
for (const test of resultContainer.testNames) {
const results = resultContainer.testResults[test];
body.push(AdaptiveCard._generateTextBlock(test, false, "bolder"));
for (const result of results) {
body.push(createTestResultRichTextBox(result));
}
}
body.push(AdaptiveCard._generateFactSet(AdaptiveCard._generateFactsOverview(resultContainer)));
this._card = {
type: "message",
attachments: [
{
contentType: "application/vnd.microsoft.card.adaptive",
contentUrl: null,
content: {
$schema: "http://adaptivecards.io/schemas/adaptive-card.json",
type: "AdaptiveCard",
version: "1.2",
body: body,
msteams: {
width: "full",
},
},
},
],
};
}
content() {
return this._card;
}
toString() {
return JSON.stringify(this.content());
}
static _generateFactsOverview(resultContainer) {
const total = { title: "Total tests", value: resultContainer.totalTests.toString(10) };
const passed = { title: "Passed", value: resultContainer.passedTests.toString(10) };
const failed = { title: "Failed", value: resultContainer.failedTests.toString(10) };
return [total, passed, failed];
}
static _generateTextBlock(message, wrap, weight) {
return {
type: "TextBlock",
text: message,
wrap: wrap,
weight: weight,
};
}
static _generateFactSet(facts) {
return {
type: "FactSet",
facts: facts,
spacing: "extraLarge",
};
}
}
exports.AdaptiveCard = AdaptiveCard;
function createTestResultRichTextBox(result) {
const block = {
type: "RichTextBlock",
inlines: [],
horizontalAlignment: "left",
};
const textRun = {
type: "TextRun",
text: result.passed ? "✓ " : "✖ ",
color: result.passed ? "good" : "warning",
weight: "bolder",
fontType: "monospace",
};
block.inlines.push(textRun, result.title);
return block;
}