-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support jasmine out of the box
- Loading branch information
Showing
6 changed files
with
266 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// https://github.com/larrymyers/jasmine-reporters/blob/master/src/tap_reporter.js | ||
(function(global) { | ||
function trim(str) { return str.replace(/^\s+/, "").replace(/\s+$/, ""); } | ||
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 extend(dupe, obj) { // performs a shallow copy of all props of `obj` onto `dupe` | ||
for (var prop in obj) { | ||
if (obj.hasOwnProperty(prop)) { | ||
dupe[prop] = obj[prop]; | ||
} | ||
} | ||
return dupe; | ||
} | ||
function log(str) { | ||
var con = global.console || console; | ||
if (con && con.log) { | ||
con.log(str); | ||
} | ||
} | ||
|
||
/** | ||
* TAP (http://en.wikipedia.org/wiki/Test_Anything_Protocol) reporter. | ||
* outputs spec results to the console. | ||
*/ | ||
var TapReporter = function() { | ||
var self = this; | ||
self.started = false; | ||
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" | ||
}; | ||
|
||
var __suites = {}, __specs = {}; | ||
function getSuite(suite) { | ||
__suites[suite.id] = extend(__suites[suite.id] || {}, suite); | ||
return __suites[suite.id]; | ||
} | ||
function getSpec(spec, suite) { | ||
__specs[spec.id] = extend(__specs[spec.id] || {}, spec); | ||
var ret = __specs[spec.id]; | ||
if (suite && !ret._suite) { | ||
ret._suite = suite; | ||
} | ||
return ret; | ||
} | ||
|
||
self.jasmineStarted = function(summary) { | ||
log("TAP version 13"); | ||
self.started = true; | ||
totalSpecsDefined = summary && summary.totalSpecsDefined || NaN; | ||
startTime = new Date(); | ||
}; | ||
self.suiteStarted = function(suite) { | ||
suite = getSuite(suite); | ||
currentSuite = suite; | ||
}; | ||
self.specStarted = function() { | ||
if (!currentSuite) { | ||
// focused spec (fit) -- suiteStarted was never called | ||
self.suiteStarted(fakeFocusedSuite); | ||
} | ||
totalSpecsExecuted++; | ||
}; | ||
self.specDone = function(spec) { | ||
spec = getSpec(spec, currentSuite); | ||
var resultStr = "ok " + totalSpecsExecuted + " - " + spec._suite.description + " : " + spec.description; | ||
if (isFailed(spec)) { | ||
totalSpecsFailed++; | ||
resultStr = "not " + resultStr; | ||
for (var i = 0, failure; i < spec.failedExpectations.length; i++) { | ||
failure = spec.failedExpectations[i]; | ||
resultStr += "\n # Failure: " + trim(failure.message); | ||
if (failure.stack && failure.stack !== failure.message) { | ||
resultStr += "\n # === STACK TRACE ==="; | ||
resultStr += "\n # " + failure.stack.replace(/\n/mg, "\n # "); | ||
resultStr += "\n # === END STACK TRACE ==="; | ||
} | ||
} | ||
} | ||
if (isSkipped(spec)) { | ||
totalSpecsSkipped++; | ||
resultStr += " # SKIP disabled by xit or similar"; | ||
} | ||
if (isDisabled(spec)) { | ||
totalSpecsDisabled++; | ||
resultStr += " # SKIP disabled by xit, ?spec=xyz or similar"; | ||
} | ||
log(resultStr); | ||
}; | ||
self.suiteDone = function(suite) { | ||
suite = getSuite(suite); | ||
if (suite._parent === undefined) { | ||
// disabled suite (xdescribe) -- suiteStarted was never called | ||
self.suiteStarted(suite); | ||
} | ||
currentSuite = suite._parent; | ||
}; | ||
self.jasmineDone = function() { | ||
if (currentSuite) { | ||
// focused spec (fit) -- suiteDone was never called | ||
self.suiteDone(fakeFocusedSuite); | ||
} | ||
endTime = new Date(); | ||
var dur = elapsed(startTime, endTime), | ||
totalSpecs = totalSpecsDefined || totalSpecsExecuted, | ||
disabledSpecs = totalSpecs - totalSpecsExecuted + totalSpecsDisabled; | ||
|
||
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 += ", " + totalSpecsSkipped + " skipped"; | ||
diagStr += ", " + disabledSpecs + " disabled"; | ||
diagStr += " in " + dur + "s."; | ||
log(diagStr); | ||
log("# NOTE: disabled specs are usually a result of xdescribe."); | ||
|
||
self.finished = true; | ||
}; | ||
}; | ||
|
||
global.jasmine.getEnv().addReporter(new TapReporter()); | ||
})(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const TapParser = require('tap-parser'); | ||
|
||
module.exports = function(keepOpen) { | ||
const parser = new TapParser(results => { | ||
if (keepOpen) return; | ||
process.exit(results.ok ? 0 : 1); | ||
}); | ||
|
||
parser.on('bailout', m => { | ||
console.error(m); // eslint-disable-line no-console | ||
process.exit(1); | ||
}); | ||
|
||
let count, done = 0; | ||
parser.on('plan', p => { | ||
count = p.end - p.start + 1; | ||
check(); | ||
}); | ||
|
||
parser.on('assert', () => { | ||
done++; | ||
check(); | ||
}); | ||
|
||
let finished = false; | ||
function check() { | ||
if (finished) return; | ||
if (!count || done < count) return; | ||
finished = true; | ||
setTimeout(() => parser.end(), 1000); | ||
} | ||
|
||
return parser; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters