wdio-ms-teams-service
Version:
A WebdriverIO plugin to report to Microsoft Teams channel webhooks
84 lines (83 loc) • 3.14 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.filterPassedTests = void 0;
const incoming_webhook_1 = __importDefault(require("./incoming-webhook"));
const adaptive_card_1 = require("./adaptive-card");
const test_result_container_1 = __importDefault(require("./test-result-container"));
class MsTeamsService {
constructor(serviceOptions, capabilities, config) {
this._webhook = new incoming_webhook_1.default(serviceOptions.webhookURL, serviceOptions.timeout);
this._capabilities = capabilities;
this._config = config;
this.testResultContainer = new test_result_container_1.default();
this._failingTestsOnly = !!serviceOptions.failingTestsOnly;
this._message = serviceOptions.message;
}
before(capabilities, specs, browser) {
this._browser = browser;
}
async afterTest(test, context, result) {
const testName = test.parent || test.fullName;
const testResult = {
passed: result.passed,
error: result.error || "",
title: test.title,
description: test.description,
};
this.testResultContainer.addTest(testName, testResult);
}
async afterStep(step, scenario, result) {
const testName = scenario.name;
const testResult = {
passed: result.passed,
error: result.error || "",
title: step.text,
description: "",
};
this.testResultContainer.addTest(testName, testResult);
}
// async afterScenario(world: ITestCaseHookParameter, result: Frameworks.PickleResult): Promise<void> {
//
// }
//
// async afterFeature(uri: string, feature: Feature): Promise<void> {
//
// }
async after() {
const message = this._message ? this._message : "An automated test run just completed";
if (this._failingTestsOnly) {
if (this.testResultContainer.failedTests === 0) {
return;
}
filterPassedTests(this.testResultContainer);
if (this.testResultContainer.testNames.length === 0) {
return;
}
}
const adaptiveCard = new adaptive_card_1.AdaptiveCard(message, this.testResultContainer);
await this._webhook.send(adaptiveCard.toString());
}
}
exports.default = MsTeamsService;
/**
* Filters out any top level tests that have no failing test results. This function modifies the provided
* container parameter and doesn't return anything
* @param container
*/
function filterPassedTests(container) {
const names = [];
for (const name of container.testNames) {
const allPassed = container.testResults[name].every((result) => result.passed);
if (!allPassed) {
names.push(name);
}
else {
delete container.testResults[name];
}
}
container.testNames = names;
}
exports.filterPassedTests = filterPassedTests;