Skip to content

Commit

Permalink
Report skipped tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schipiga committed Dec 27, 2017
1 parent 6999d51 commit ca22c76
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
17 changes: 9 additions & 8 deletions lib/globals.js
Expand Up @@ -192,6 +192,7 @@ global.session = (name, ctx, fixtures, func) => {
* @arg {string} name - Name of test case.
* @arg {object} [opts] - Options.
* @arg {boolean} [opts.skip=false] - Flag to skip test.
* @arg {string} [opts.skipReason=null] - Skip reason if test is marked as skipped.
* @arg {number} [opts.retry=0] - Number of retries on failure. May be managed
* in config.
* @arg {?number} [opts.chunkTimeout=null] - Time to execute chunk or hook, sec.
Expand All @@ -202,10 +203,9 @@ var baseTest = (names => {
return (name, opts, fixtures, func) => {

if (names.includes(name)) {
LOG.warn(`Test case '${name}' is added already.`,
`Test case with the same name will be omitted.`);
return;
throw new Error(`Test case '${name}' is added already`);
};
names.push(name);

if (opts instanceof Function) {
func = opts;
Expand All @@ -220,20 +220,21 @@ var baseTest = (names => {
fixtures = fixtures || [];

opts.skip = U.defVal(opts.skip, false);
opts.skipReason = U.defVal(opts.skipReason);
opts.retry = U.defVal(opts.retry, CONF.testRetries, 0);
opts.chunkTimeout = U.defVal(opts.chunkTimeout);

var testCase = new TestCase(name);
CONF.testCases.push(testCase);

if (opts.skip) {
LOG.warn(`Test '${name}' is marked as skipped and will be omitted`);
testCase.status = TestCase.SKIPPED;
if (opts.skipReason) testCase.addDetails(opts.skipReason);
return;
};
names.push(name);

var testCase = new TestCase(name);
var retries = opts.retry;

CONF.testCases.push(testCase);

var testFunc = ctxs => {
ctxs = ctxs || [{}];

Expand Down
19 changes: 19 additions & 0 deletions lib/reporter/stdout.js
Expand Up @@ -33,6 +33,7 @@ var epilogue = () => {

var passedTests = [];
var failedTests = [];
var skippedTests = [];

for (var testCase of CONF.testCases) {
if (testCase.status === TestCase.FAILED) {
Expand All @@ -41,6 +42,9 @@ var epilogue = () => {
if (testCase.status === TestCase.PASSED) {
passedTests.push(testCase);
};
if (testCase.status === TestCase.SKIPPED) {
skippedTests.push(testCase);
};
};

if (passedTests.length !== 0) {
Expand Down Expand Up @@ -71,6 +75,21 @@ var epilogue = () => {
`${execTime} sec`.white.bold);
};

if (skippedTests.length !== 0) {
var msg = "skipped test" + (skippedTests.length === 1 ? "" : "s");
stdout();
stdout((indent + "# " +
String(skippedTests.length).bold + " " + msg).gray);

for (var skip of skippedTests) {
var msg = `* '${skip.name}'`;
if (skip.rawInfo[0]) {
msg += " - " + skip.rawInfo[0].bold;
};
stdout(indent + indent + msg.gray);
};
};

if (failedTests.length) {
stdout();
stdout("TEST FAILURES:".bold)
Expand Down
3 changes: 3 additions & 0 deletions lib/reporter/testrail.js
Expand Up @@ -128,6 +128,9 @@ var testrailReporter = module.exports = {
testResult.comment += "\n" + info;
};
};
if (testCase.status === TestCase.SKIPPED) {
testResult.status_id = Results.BLOCKED;
};
if (testCase.status === TestCase.FAILED) {
testResult.status_id = Results.FAILED;
testResult.comment += "\n\nErrors:";
Expand Down
4 changes: 3 additions & 1 deletion lib/reporter/xunit.js
Expand Up @@ -34,7 +34,7 @@ var xunitReporter = module.exports = {
tests: CONF.testCases.length,
failures: CONF.testCases.filter(t => t.status === TestCase.FAILED).length,
errors: CONF.testCases.filter(t => t.status === TestCase.FAILED).length,
skipped: 0, // FIXME support skipped tests in report.
skipped: CONF.testCases.filter(t => t.status === TestCase.SKIPPED).length,
timestamp: new Date().toUTCString(),
time: (CONF.testCases.map(t => t.duration).reduce((a, b) => a + b, 0) / 1000) || 0
}, false));
Expand Down Expand Up @@ -73,6 +73,8 @@ var writeTest = test => {
if (test.status === TestCase.FAILED) {
var err = test.errors.join("\n");
write(tag('testcase', attrs, false, tag('failure', {}, false, escape(err))));
} else if (test.status === TestCase.SKIPPED) {
write(tag('testcase', attrs, false, tag('skipped', {}, true)));
} else {
write(tag('testcase', attrs, true));
};
Expand Down
2 changes: 2 additions & 0 deletions lib/testing.js
Expand Up @@ -28,6 +28,7 @@ var TestCase = module.exports.TestCase = function (name) {
this.name = name;
this.status = TestCase.NOT_STARTED;
this.chunks = [];
this.reset();
};
/**
* Starts test case.
Expand Down Expand Up @@ -130,3 +131,4 @@ TestCase.NOT_STARTED = "not started";
TestCase.IN_PROGRESS = "in progress";
TestCase.FAILED = "failed";
TestCase.PASSED = "passed";
TestCase.SKIPPED = "skipped";
8 changes: 7 additions & 1 deletion tests/e2e/testBasic.js
Expand Up @@ -66,7 +66,13 @@ test("It should involve fixture in iterator", ctx => {
});
});

test("It should be skipped and absent in report", { skip: true }, () => {
test("It should be skipped with reason",
{ skip: true,
skipReason: "bug https://bug.tracker.io/BUG-1001" }, () => {
chunk(() => {});
});

test("It should be skipped without reason", { skip: true }, () => {
chunk(() => {});
});

Expand Down

0 comments on commit ca22c76

Please sign in to comment.