Skip to content

Commit

Permalink
Check testrail consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
schipiga committed Mar 21, 2018
1 parent 845cd85 commit 369c3b4
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -105,7 +105,7 @@ glace [options] [sequence-of-test-files-or-folders]
- `--xunit-suite-name [name]` - Tests suite name in xUnit report. By default it's the same as session name.

`TestRail`
- `--testrail` - Activate testrail reporter.
- `--testrail` - Activate TestRail reporter.
- `--testrail-host <host>` - TestRail host.
- `--testrail-user <user>` - TestRail username or email.
- `--testrail-token <token>` - TestRail token.
Expand All @@ -115,6 +115,7 @@ glace [options] [sequence-of-test-files-or-folders]
- `--testrail-run-desc <description>` - TestRail run description.

`Tools`
- `--testrail-check` - Check TestRail cases consistency with implemented tests.
- `--list-steps [filter]` - Only list available steps.
- `--list-tests [filter]` - Only list collected tests.
- `--list-fixtures [filter]` - Only list available fixtures.
Expand Down
1 change: 1 addition & 0 deletions lib/config.js
Expand Up @@ -115,6 +115,7 @@ config.xunit.suiteName = U.defVal(args.xunitSuiteName, config.sessionName);

config.testrail = U.defVal(config.testrail, {});
config.testrail.use = U.defVal(args.testrail, false);
config.testrail.check = U.defVal(args.testrailCheck, false);
config.testrail.host = U.defVal(args.testrailHost);
config.testrail.user = U.defVal(args.testrailUser);
config.testrail.token = U.defVal(args.testrailToken);
Expand Down
9 changes: 8 additions & 1 deletion lib/help.js
Expand Up @@ -142,7 +142,7 @@ module.exports = (d, cb) => {
},
/* testrail */
"testrail": {
describe: d("Activate testrail reporter."),
describe: d("Activate TestRail reporter."),
type: "boolean",
group: "TestRail:",
},
Expand Down Expand Up @@ -181,6 +181,13 @@ module.exports = (d, cb) => {
type: "string",
group: "TestRail:",
},
/* tools */
"testrail-check": {
describe: d("Check TestRail cases consistency with",
"implemented tests."),
type: "boolean",
group: "Tools:",
},
"list-steps [filter]": {
describe: d("Only list available steps."),
group: "Tools:",
Expand Down
2 changes: 2 additions & 0 deletions lib/run.js
Expand Up @@ -82,6 +82,8 @@ var glaceRun = cb => {
} else if (CONF.testsList) {
tools.listTests(CONF.testsFilter);
cb();
} else if (CONF.testrail.check) {
tools.checkTestrail(cb);
} else {
run(cb);
}
Expand Down
78 changes: 78 additions & 0 deletions lib/tools.js
Expand Up @@ -10,8 +10,10 @@ var util = require("util");

require("colors");
var _ = require("lodash");
var expect = require("chai").expect;
var highlight = require("cli-highlight").highlight;
var natural = require("natural");
var Testrail = require("testrail-api");
var U = require("glace-utils");

var d = U.switchColor();
Expand Down Expand Up @@ -114,6 +116,82 @@ self.listTests = filter => {
};
};

self.checkTestrail = cb => {
var noErrors = true;
var conf = require("./config");

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

load();

var testrail = new Testrail({
host: conf.testrail.host,
user: conf.testrail.user,
password: conf.testrail.token });

testrail.getCases(
conf.testrail.projectId,
{ suite_id: conf.testrail.suiteId },
(err, response, cases) => {

if (err) {
console.log(err);
cb(1);
return;
}

var t;
var testrailNames = [], testrailDups = [];

cases.forEach(t => {
if (testrailNames.includes(t.title)) {
testrailDups.push(t.title);
} else {
testrailNames.push(t.title);
}
});

testrailDups = _.uniq(testrailDups);

if (testrailDups.length) {
noErrors = false;
console.log("TestRail duplicated cases:".magenta);
for (t of testrailDups) {
console.log(` - ${t}`.cyan);
}
}

var testNames = conf.testCase.map(t => t.name);
var absentTests = _.difference(testrailNames, testNames);
var absentCases = _.difference(testNames, testrailNames);

if (absentTests.length) {
noErrors = false;
console.log("Not implemented TestRail cases:".magenta);
for (t of absentTests) {
console.log(` - ${t}`.cyan);
}
}

if (absentCases.length) {
noErrors = false;
console.log("Absent TestRail cases:".magenta);
for (t of absentCases) {
console.log(` - ${t}`.cyan);
}
}

if (noErrors) {
console.log("TestRail cases correspond current tests");
}
cb(noErrors ? 0 : 1);
});
};

self.listFixtures = (filter, namesOnly) => {
namesOnly = namesOnly || false;

Expand Down

0 comments on commit 369c3b4

Please sign in to comment.