Comparing version 0.0.3 to 0.0.4
exports.dotmatrix = require("./dot"); | ||
exports.spec = require("./spec"); | ||
exports.coverage = require("./coverage.js"); | ||
exports.coverageHtml = require("./coverage-html.js"); |
147
lib/it.js
@@ -36,3 +36,3 @@ "use strict"; | ||
var errorHandler = function (err) { | ||
if(!isCallback){ | ||
if (!isCallback) { | ||
isCallback = true; | ||
@@ -94,2 +94,7 @@ ret.errback(err); | ||
var describeIt = function (description, sub, level) { | ||
function getSummary(err) { | ||
} | ||
var it = { | ||
@@ -113,2 +118,7 @@ | ||
as:function (mod) { | ||
mod.exports = this; | ||
return this; | ||
}, | ||
beforeAll:function (cb) { | ||
@@ -140,3 +150,5 @@ this.__ba.push(setUpCb(cb, this)); | ||
it.ignoreProcessError = this.ignoreProcessError; | ||
it.__formatter = this.__formatter; | ||
it.__defineGetter__("__formatter", function () { | ||
return this.__formatter; | ||
}.bind(this)); | ||
var summaries = this.__summaries; | ||
@@ -146,4 +158,4 @@ "function" === typeof cb && cb(it); | ||
var ret = new comb.Promise(); | ||
it.run(this.__level + 1).both(function (summary) { | ||
summaries[description] = summary; | ||
it.run().both(function (summary) { | ||
summaries[description] = comb.merge(summaries[description] || {}, summary); | ||
ret.callback(); | ||
@@ -162,3 +174,5 @@ }); | ||
it.ignoreProcessError = this.ignoreProcessError; | ||
it.__formatter = this.__formatter; | ||
it.__defineGetter__("__formatter", function () { | ||
return this.__formatter; | ||
}.bind(this)); | ||
var summaries = this.__summaries; | ||
@@ -168,4 +182,4 @@ "function" === typeof cb && cb(it); | ||
var ret = new comb.Promise(); | ||
it.run(this.__level).both(function (summary) { | ||
summaries[description] = summary; | ||
it.run().both(function (summary) { | ||
comb.merge(summaries, summary.summaries); | ||
ret.callback(); | ||
@@ -180,3 +194,4 @@ }); | ||
description = description || "Should " + this.__shoulds.length + 1; | ||
var summaries = this.__summaries, stopOnError = this.stopOnError; | ||
var summaries = this.__summaries, | ||
stopOnError = this.stopOnError; | ||
var level = this.__level + 1; | ||
@@ -189,8 +204,7 @@ this.__shoulds.push(hitch(this, function () { | ||
// this test is pending (read: not defined yet) | ||
var sum = { | ||
description : description, | ||
start : start, | ||
end : start, | ||
duration : 0, // test is pending | ||
status : 'pending' | ||
var sum = {description:description, | ||
start:start, | ||
end:start, | ||
duration:0, // test is pending | ||
status:'pending' | ||
}; | ||
@@ -201,26 +215,16 @@ summaries[description] = sum; | ||
} else { | ||
setUpCb(cb, this)().then(function () { | ||
setUpCb(cb, this)().classic(function (err) { | ||
var end = new Date(); | ||
var sum = {description:description, start:start, end:end, duration:end - start, status:"passed", error:false}; | ||
var sum = {description:description, start:start, end:end, duration:end - start, status:err ? "failed" : "passed", error:err || false}; | ||
summaries[description] = sum; | ||
formatter.printSuccess(sum, level); | ||
ret.callback(); | ||
}, function (err) { | ||
var end = new Date(); | ||
var sum = { | ||
description:description, | ||
start:start, end:end, | ||
duration:end - start, | ||
status:"failed", | ||
error:err | ||
}; | ||
var formatErr = formatter.printError(sum, level, err); | ||
if (comb.isDefined(formatErr)) { | ||
sum.status = formatErr === false ? "passed" : "failed"; | ||
sum.error = formatErr === false ? false : err; | ||
if (err) { | ||
var formatErr = formatter.printError(sum, level, err); | ||
if (comb.isDefined(formatErr)) { | ||
sum.status = formatErr === false ? "passed" : "failed"; | ||
sum.error = formatErr === false ? false : err; | ||
} | ||
} else { | ||
formatter.printSuccess(sum, level); | ||
} | ||
summaries[description] = sum; | ||
ret[stopOnError ? "errback" : "callback"](err); | ||
ret[err && stopOnError ? "errback" : "callback"](summaries); | ||
}); | ||
@@ -233,13 +237,17 @@ } | ||
_processSummary:function (summary, ret, method) { | ||
var formatter = this.__formatter; | ||
this.__summaries = summary; | ||
_processSummary:function (summary, promise, method) { | ||
var formatter = this.__formatter, ret = {}; | ||
if (!this.__level && description) { | ||
ret[description] = summary; | ||
this.__summaries = ret; | ||
} else { | ||
this.__summaries = ret = summary; | ||
} | ||
!sub && formatter.printSummary(summary.summaries, summary.duration); | ||
ret[method](this.__summaries); | ||
promise[method](ret); | ||
}, | ||
run:function (level) { | ||
var ret = new comb.Promise(); | ||
if (!this.__run) { | ||
this.__run = true; | ||
run:function () { | ||
var ret = this.__runPromise; | ||
if (!ret) { | ||
if (sub) { | ||
@@ -263,2 +271,3 @@ level = level || 1; | ||
var summaries = this.__summaries; | ||
ret = this.__runPromise = new comb.Promise(); | ||
comb.serial(funcs).then(comb.hitch(this, function () { | ||
@@ -273,6 +282,4 @@ var duration = new Date() - start; | ||
})); | ||
} else { | ||
ret.callback(this.__summaries); | ||
} | ||
return ret; | ||
return ret.promise(); | ||
} | ||
@@ -307,2 +314,26 @@ }; | ||
function printSummary(its) { | ||
formatter.printTitle("Summary"); | ||
var summary = {}; | ||
var keys = Object.keys(its), length; | ||
Object.keys(its).forEach(function (k) { | ||
var itSummary = its[k]; | ||
if (itSummary) { | ||
summary[k] = itSummary; | ||
length++; | ||
} | ||
}); | ||
//console.log(summary); | ||
if (length < keys.length) { | ||
formatter.printError(new Error("Async Error")); | ||
} | ||
formatter.printSummary(summary); | ||
} | ||
exports.printSummary = printSummary; | ||
exports.printCoverage = function (type, coverage, out) { | ||
return formatters[type].showCoverage(coverage, out); | ||
}; | ||
exports.run = function (opts) { | ||
@@ -312,22 +343,12 @@ var ret = comb.serial(Object.keys(its).map(function (k) { | ||
return its[k].run(); | ||
} | ||
}; | ||
})); | ||
comb.listenForExit(function () { | ||
formatter.printTitle("Summary"); | ||
var summary = {}; | ||
var keys = Object.keys(its), length; | ||
Object.keys(its).forEach(function (k) { | ||
var itSummary = its[k].__summaries; | ||
if (itSummary) { | ||
summary[k] = itSummary; | ||
length++; | ||
} | ||
ret.then(function (results) { | ||
var its = {}; | ||
results.forEach(function (summary) { | ||
comb.merge(its, summary); | ||
}); | ||
printSummary(its); | ||
}); | ||
//console.log(summary); | ||
if (summary.length < keys.length) { | ||
formatter.printError(new Error("Async Error")); | ||
} | ||
formatter.printSummary(summary); | ||
}); | ||
@@ -334,0 +355,0 @@ return ret; |
{ | ||
"name": "it", | ||
"description": "A testing framework for node", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "testing", |
@@ -193,2 +193,3 @@ It | ||
* -r, --reporter : The reporter to use when running the tests | ||
* --cov-html : create coverage output in html, if an output path is included then the file will be written to that file otherwise it will defalt to `./coverage.html` | ||
* --reporters : Display a list of reporters that are available | ||
@@ -229,4 +230,7 @@ * -h, --help : Displays help. | ||
###Code Coverage | ||
If you use [node-jscoverage](https://github.com/visionmedia/node-jscoverage) to generate coverage then by default `it` will output a coverage report. You may also output coverage to an `HTML` file by passing in the `--cov-html` flag to the executable. For example out put see [patio test coverage](http://pollenware.github.com/patio/coverage.html). | ||
###Reporters | ||
@@ -233,0 +237,0 @@ |
var it = require("../index"), assert = require("assert"), comb = require("comb"); | ||
it.describe("it", function (it) { | ||
it.describe("it",function (it) { | ||
@@ -20,2 +20,3 @@ it.should("not be null", function () { | ||
assert.isFunction(it.describe); | ||
assert.isFunction(it.context); | ||
}); | ||
@@ -584,5 +585,5 @@ | ||
}); | ||
})(str, summary); | ||
})(str, summary.it); | ||
assert.deepEqual(str, expected); | ||
assert.isNumber(summary.duration); | ||
assert.isNumber(summary.it.duration); | ||
@@ -593,2 +594,2 @@ | ||
}); | ||
}).as(module); |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
65412
19
1315
297
0
1