Skip to content

Commit

Permalink
Add entry points to testrail reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
schipiga committed Dec 10, 2018
1 parent b57f829 commit f765a2b
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 28 deletions.
150 changes: 126 additions & 24 deletions lib/reporter/testrail.js
@@ -1,6 +1,7 @@
"use strict";
/**
* TestRail reporter.
* [TestRail](https://www.gurock.com/testrail) reporter publishs test results
* to remote testrail server via its API.
*
* @module
*/
Expand All @@ -16,7 +17,7 @@ const TestCase = require("../testing").TestCase;

for (const opt in CONF.testrail) {
expect(CONF.testrail[opt],
`TestRail option '${opt}' isn't specified in config`)
`TestRail option '${opt}' is not specified in config`)
.to.exist;
}

Expand All @@ -38,7 +39,7 @@ const Results = {
const cases = {};
let report = Promise.resolve();

module.exports = {
const Reporter = {
/**
* Called on tests start.
*
Expand Down Expand Up @@ -102,35 +103,26 @@ module.exports = {
}

const testResult = { status_id: Results.PASSED, comment: "" };
testResult.comment = Reporter.setComment();

if (CONF.test.curCase.status === TestCase.SKIPPED) {
testResult.status_id = Results.BLOCKED;
}
if (CONF.test.curCase.screenshots.length) {
testResult.comment += "Screenshots:";
for (const screen of CONF.test.curCase.screenshots) {
testResult.comment += "\n" + screen;
}
testResult.comment += Reporter.processScreens(CONF.test.curCase.screenshots);
}
if (CONF.test.curCase.videos.length) {
testResult.comment += "\n\nVideos:";
for (const video of CONF.test.curCase.videos) {
testResult.comment += "\n" + video;
}
}
if (CONF.test.curCase.rawInfo.length) {
testResult.comment += "\n\nExtra details:";
for (const info of CONF.test.curCase.rawInfo) {
testResult.comment += "\n" + info;
}
}
if (CONF.test.curCase.status === TestCase.SKIPPED) {
testResult.status_id = Results.BLOCKED;
testResult.comment += Reporter.processVideos(CONF.test.curCase.videos);
}
if (CONF.test.curCase.status === TestCase.FAILED) {
testResult.status_id = Results.FAILED;
testResult.comment += "\n\nErrors:";
for (const error of CONF.test.curCase.errors) {
testResult.comment += "\n" + error;
}
testResult.comment += Reporter.processErrors(CONF.test.curCase.errors);
}
if (CONF.test.curCase.rawInfo.length) {
testResult.comment += Reporter.processExtras(CONF.test.curCase.rawInfo);
}

testResult.comment = testResult.comment.trim();

report = report.then(() => {
return testrail.addResultForCase(
Expand All @@ -149,3 +141,113 @@ module.exports = {
*/
done: () => report,
};

/**
* Entry point to set comment of test before testrail publication.
* Can be overridden with custom function.
*
* @memberOf module:reporter/testrail
* @instance
* @function setComment
* @return {string} - Test comment.
*
* @example <caption><b>Overriding with custom function</b></caption>
* // should be after configuration but before tests run
* const testrail = require("glace-core/lib/reporter/testrail");
* testrail.setComment = myFuncToSetComment;
*/
Reporter.setComment = () => "";

/**
* Entry point to process test screenshot paths before testrail publication.
* Can be overridden with custom function.
*
* @memberOf module:reporter/testrail
* @instance
* @function processScreens
* @arg {string[]} screens - List of screenshot paths.
* @return {string} - Test screenshots info, attaching to test comment.
*
* @example <caption><b>Overriding with custom function</b></caption>
* // should be after configuration but before tests run
* const testrail = require("glace-core/lib/reporter/testrail");
* testrail.processScreens = myFuncToProcessScreens;
*/
Reporter.processScreens = screens => {
let result = "\n\nScreenshots:";
screens.forEach((screen, i) => {
result += `\n${i + 1}. ${screen}`;
});
return result;
};

/**
* Entry point to process test video paths before testrail publication.
* Can be overridden with custom function.
*
* @memberOf module:reporter/testrail
* @instance
* @function processVideos
* @arg {string[]} videos - List of video paths.
* @return {string} - Test videos info, attaching to test comment.
*
* @example <caption><b>Overriding with custom function</b></caption>
* // should be after configuration but before tests run
* const testrail = require("glace-core/lib/reporter/testrail");
* testrail.processVideos = myFuncToProcessVideos;
*/
Reporter.processVideos = videos => {
let result = "\n\nVideos:";
videos.forEach((video, i) => {
result += `\n${i + 1}. ${video}`;
});
return result;
};

/**
* Entry point to process test errors before testrail publication.
* Can be overridden with custom function.
*
* @memberOf module:reporter/testrail
* @instance
* @function processErrors
* @arg {string[]} errors - List of test errors.
* @return {string} - Test errors info, attaching to test comment.
*
* @example <caption><b>Overriding with custom function</b></caption>
* // should be after configuration but before tests run
* const testrail = require("glace-core/lib/reporter/testrail");
* testrail.processErrors = myFuncToProcessErrors;
*/
Reporter.processErrors = errors => {
let result = "\n\nErrors:";
errors.forEach((error, i) => {
result += `${i ? "\n" : ""}\n${i + 1}. ${error}`;
});
return result;
};

/**
* Entry point to process test extra details before testrail publication.
* Can be overridden with custom function.
*
* @memberOf module:reporter/testrail
* @instance
* @function processExtras
* @arg {string[]} extras - List of extra details.
* @return {string} - Test extra details, attaching to test comment.
*
* @example <caption><b>Overriding with custom function</b></caption>
* // should be after configuration but before tests run
* const testrail = require("glace-core/lib/reporter/testrail");
* testrail.processExtras = myFuncToProcessExtras;
*/
Reporter.processExtras = extras => {
let result = "\n\nExtra details:";
extras.forEach((extra, i) => {
result += `${i ? "\n" : ""}\n${i + 1}. ${extra}`;
});
return result;
};

module.exports = Reporter;
6 changes: 3 additions & 3 deletions lib/steps/timer.js
Expand Up @@ -33,7 +33,7 @@ var TimerSteps = {
* @arg {number} timeout - Pause time, sec.
* @arg {string} message - Pause reason.
* @return {Promise<void>}
* @throws {AssertionError} If pause message isn't defined.
* @throws {AssertionError} If pause message is not defined.
* @example
*
* await $.pause(1, "wait for server start");
Expand Down Expand Up @@ -91,7 +91,7 @@ var TimerSteps = {
* @method getTimer
* @instance
* @return {number} Number of seconds since timer starts.
* @throws {AssertionError} If timer isn't started.
* @throws {AssertionError} If timer is not started.
* @example
*
* $.startTimer();
Expand All @@ -100,7 +100,7 @@ var TimerSteps = {
*/

A.step("Get timer value");
expect(this._timer, "Timer isn't started").to.exist;
expect(this._timer, "Timer is not started").to.exist;
var result = (new Date() - this._timer) / 1000;
A.pass();
return result;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/testReporterTestrail.js
Expand Up @@ -30,7 +30,7 @@ suite("reporter/testrail", () => {

chunk(`throws exception if no testrail ${opt}`, () => {
CONF.testrail[opt] = null;
expect(() => rewire(TESTRAIL_PATH)).to.throw(`'${opt}' isn't specified`);
expect(() => rewire(TESTRAIL_PATH)).to.throw(`'${opt}' is not specified`);
});
});
});
Expand Down

0 comments on commit f765a2b

Please sign in to comment.