Skip to content

Commit

Permalink
fix: fix wrong jasmine report on fit/fdescribe
Browse files Browse the repository at this point in the history
closes #3
  • Loading branch information
3cp committed Oct 1, 2020
1 parent 1875ce5 commit 3a1f72e
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 24 deletions.
46 changes: 22 additions & 24 deletions jasmine-tap-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
function elapsed(start, end) { return (end - start)/1000; }
function isFailed(obj) { return obj.status === "failed"; }
function isSkipped(obj) { return obj.status === "pending"; }
function isDisabled(obj) { return obj.status === "disabled"; }
function isExcluded(obj) { return obj.status === "excluded" || obj.status === "disabled"; }
function extend(dupe, obj) { // performs a shallow copy of all props of `obj` onto `dupe`
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
Expand All @@ -30,19 +30,18 @@
self.finished = false;

var startTime,
endTime,
currentSuite = null,
totalSpecsExecuted = 0,
totalSpecsSkipped = 0,
totalSpecsDisabled = 0,
totalSpecsFailed = 0,
totalSpecsDefined,
// when use use fit, jasmine never calls suiteStarted / suiteDone, so make a fake one to use
fakeFocusedSuite = {
id: "focused",
description: "focused specs",
fullName: "focused specs"
};
endTime,
currentSuite = null,
totalSpecsExecuted = 0,
totalSpecsSkipped = 0,
totalSpecsFailed = 0,
totalSpecsDefined,
// when use use fit, jasmine never calls suiteStarted / suiteDone, so make a fake one to use
fakeFocusedSuite = {
id: "focused",
description: "focused specs",
fullName: "focused specs"
};

var __suites = {}, __specs = {};
function getSuite(suite) {
Expand Down Expand Up @@ -92,12 +91,14 @@
}
}
if (isSkipped(spec)) {
totalSpecsExecuted--;
totalSpecsSkipped++;
resultStr += " # SKIP disabled by xit or similar";
resultStr = "# Skipped (xit or xdescribe): " + spec._suite.description + " : " + spec.description;
}
if (isDisabled(spec)) {
totalSpecsDisabled++;
resultStr += " # SKIP disabled by xit, ?spec=xyz or similar";
if (isExcluded(spec)) {
totalSpecsExecuted--;
totalSpecsSkipped++;
resultStr = "# Excluded (by fit or fdescribe on other spec): " + spec._suite.description + " : " + spec.description;
}
log(resultStr);
};
Expand All @@ -116,22 +117,19 @@
}
endTime = new Date();
var dur = elapsed(startTime, endTime),
totalSpecs = totalSpecsDefined || totalSpecsExecuted,
disabledSpecs = totalSpecs - totalSpecsExecuted + totalSpecsDisabled;
totalSpecs = totalSpecsDefined || totalSpecsExecuted;

if (totalSpecsExecuted === 0) {
log("1..0 # All tests disabled");
} else {
log("1.." + totalSpecsExecuted);
}
var diagStr = "#";
diagStr = "# " + totalSpecs + " spec" + (totalSpecs === 1 ? "" : "s");
diagStr += ", " + totalSpecsFailed + " failure" + (totalSpecsFailed === 1 ? "" : "s");
diagStr = "# " + totalSpecs + " spec" + (totalSpecs < 2 ? "" : "s");
diagStr += ", " + totalSpecsFailed + " failure" + (totalSpecsFailed < 2 ? "" : "s");
diagStr += ", " + totalSpecsSkipped + " skipped";
diagStr += ", " + disabledSpecs + " disabled";
diagStr += " in " + dur + "s.";
log(diagStr);
log("# NOTE: disabled specs are usually a result of xdescribe.");

self.finished = true;
};
Expand Down
28 changes: 28 additions & 0 deletions test/e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@ browsers.forEach(browser => {
});
});

test(`browser-do:${browser} supports jasmine fit tests`, t => {
exec('npx browserify test/samples/_jasmine-fit.js | node bin/browser-do.js --jasmine' + browserArg, error => {
t.notOk(error);
t.end();
});
});

test(`browser-do:${browser} supports jasmine fdescribe tests`, t => {
exec('npx browserify test/samples/_jasmine-fdescribe.js | node bin/browser-do.js --jasmine' + browserArg, error => {
t.notOk(error);
t.end();
});
});

test(`browser-do:${browser} supports jasmine xit tests`, t => {
exec('npx browserify test/samples/_jasmine-xit.js | node bin/browser-do.js --jasmine' + browserArg, error => {
t.notOk(error);
t.end();
});
});

test(`browser-do:${browser} supports jasmine xdescribe tests`, t => {
exec('npx browserify test/samples/_jasmine-xdescribe.js | node bin/browser-do.js --jasmine' + browserArg, error => {
t.notOk(error);
t.end();
});
});

test(`browser-do:${browser} detects passed mocha tests`, t => {
exec('npx browserify test/samples/_mocha-good.js | node bin/browser-do.js --mocha' + browserArg, error => {
t.notOk(error);
Expand Down
15 changes: 15 additions & 0 deletions test/samples/_jasmine-fdescribe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* global describe, it, expect, fdescribe */
fdescribe('scope1', function() {
it('test1', function() {
expect(1).toBe(1);
});
});

describe('scope2', function() {
it('test2', function(done) {
setTimeout(function() {
expect(2).toBe(1);
done();
}, 200);
});
});
15 changes: 15 additions & 0 deletions test/samples/_jasmine-fit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* global describe, it, expect, fit */
describe('scope1', function() {
fit('test1', function() {
expect(1).toBe(1);
});
});

describe('scope2', function() {
it('test2', function(done) {
setTimeout(function() {
expect(2).toBe(1);
done();
}, 200);
});
});
15 changes: 15 additions & 0 deletions test/samples/_jasmine-xdescribe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* global describe, it, expect, xdescribe */
describe('scope1', function() {
it('test1', function() {
expect(1).toBe(1);
});
});

xdescribe('scope2', function() {
it('test2', function(done) {
setTimeout(function() {
expect(2).toBe(1);
done();
}, 200);
});
});
15 changes: 15 additions & 0 deletions test/samples/_jasmine-xit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* global describe, it, expect, xit */
describe('scope1', function() {
it('test1', function() {
expect(1).toBe(1);
});
});

describe('scope2', function() {
xit('test2', function(done) {
setTimeout(function() {
expect(2).toBe(1);
done();
}, 200);
});
});

0 comments on commit 3a1f72e

Please sign in to comment.