Comparing version 0.13.0 to 0.14.0
0.14.0 / 2012-03-01 | ||
================== | ||
* Added string diff support for terminal reporters | ||
0.13.0 / 2012-02-23 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -17,3 +17,3 @@ /* automatically generated by JSCoverage - do not edit */ | ||
_$jscoverage['mocha.js'][12]++; | ||
exports.version = "0.12.1"; | ||
exports.version = "0.13.0"; | ||
_$jscoverage['mocha.js'][14]++; | ||
@@ -37,2 +37,2 @@ exports.utils = require("./utils"); | ||
exports.Test = require("./test"); | ||
_$jscoverage['mocha.js'].source = ["","/*!"," * mocha"," * Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>"," * MIT Licensed"," */","","/**"," * Library version."," */","","exports.version = '0.12.1';","","exports.utils = require('./utils');","exports.interfaces = require('./interfaces');","exports.reporters = require('./reporters');","exports.Runnable = require('./runnable');","exports.Context = require('./context');","exports.Runner = require('./runner');","exports.Suite = require('./suite');","exports.Hook = require('./hook');","exports.Test = require('./test');"]; | ||
_$jscoverage['mocha.js'].source = ["","/*!"," * mocha"," * Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>"," * MIT Licensed"," */","","/**"," * Library version."," */","","exports.version = '0.13.0';","","exports.utils = require('./utils');","exports.interfaces = require('./interfaces');","exports.reporters = require('./reporters');","exports.Runnable = require('./runnable');","exports.Context = require('./context');","exports.Runner = require('./runner');","exports.Suite = require('./suite');","exports.Hook = require('./hook');","exports.Test = require('./test');"]; |
@@ -12,3 +12,3 @@ | ||
exports.version = '0.13.0'; | ||
exports.version = '0.14.0'; | ||
@@ -15,0 +15,0 @@ exports.utils = require('./utils'); |
@@ -6,3 +6,4 @@ | ||
var tty = require('tty'); | ||
var tty = require('tty') | ||
, diff = require('diff'); | ||
@@ -48,2 +49,5 @@ /** | ||
, 'light': 90 | ||
, 'diff gutter': 90 | ||
, 'diff added': 42 | ||
, 'diff removed': 41 | ||
}; | ||
@@ -136,4 +140,38 @@ | ||
, index = stack.indexOf(message) + message.length | ||
, msg = stack.slice(0, index); | ||
, msg = stack.slice(0, index) | ||
, actual = err.actual | ||
, expected = err.expected; | ||
// actual / expected diff | ||
if ('string' == typeof actual && 'string' == typeof expected) { | ||
var len = Math.max(actual.length, expected.length); | ||
if (len < 20) msg = errorDiff(err, 'Chars'); | ||
else msg = errorDiff(err, 'Words'); | ||
// linenos | ||
var lines = msg.split('\n'); | ||
if (lines.length > 4) { | ||
var width = String(lines.length).length; | ||
msg = lines.map(function(str, i){ | ||
return pad(++i, width) + ' |' + ' ' + str; | ||
}).join('\n'); | ||
} | ||
// legend | ||
msg = '\n' | ||
+ color('diff removed', 'actual') | ||
+ ' ' | ||
+ color('diff added', 'expected') | ||
+ '\n\n' | ||
+ msg | ||
+ '\n'; | ||
// indent | ||
msg = msg.replace(/^/gm, ' '); | ||
fmt = color('error title', ' %s) %s:\n%s') | ||
+ color('error stack', '\n%s\n'); | ||
} | ||
// indent stack trace without msg | ||
@@ -240,1 +278,46 @@ stack = stack.slice(index + 1) | ||
}; | ||
/** | ||
* Pad the given `str` to `len`. | ||
* | ||
* @param {String} str | ||
* @param {String} len | ||
* @return {String} | ||
* @api private | ||
*/ | ||
function pad(str, len) { | ||
str = String(str); | ||
return Array(len - str.length + 1).join(' ') + str; | ||
} | ||
/** | ||
* Return a character diff for `err`. | ||
* | ||
* @param {Error} err | ||
* @return {String} | ||
* @api private | ||
*/ | ||
function errorDiff(err, type) { | ||
return diff['diff' + type](err.actual, err.expected).map(function(str){ | ||
if (str.added) return colorLines('diff added', str.value); | ||
if (str.removed) return colorLines('diff removed', str.value); | ||
return str.value; | ||
}).join(''); | ||
} | ||
/** | ||
* Color lines for `str`, using the color `name`. | ||
* | ||
* @param {String} name | ||
* @param {String} str | ||
* @return {String} | ||
* @api private | ||
*/ | ||
function colorLines(name, str) { | ||
return str.split('\n').map(function(str){ | ||
return color(name, str); | ||
}).join('\n'); | ||
} |
{ | ||
"name": "mocha" | ||
, "version": "0.13.0" | ||
, "version": "0.14.0" | ||
, "description": "simple, flexible, fun test framework" | ||
@@ -18,2 +18,3 @@ , "keywords": ["test", "bdd", "tdd", "tap"] | ||
, "jade": "0.20.3" | ||
, "diff": "1.0.2" | ||
, "debug": "*" | ||
@@ -20,0 +21,0 @@ } |
[![Build Status](https://secure.travis-ci.org/visionmedia/mocha.png)](http://travis-ci.org/visionmedia/mocha) | ||
[![Mocha test framework](http://f.cl.ly/items/3H1W3W3i3W163X0U3127/Screenshot.png)](http://visionmedia.github.com/mocha) | ||
[![Mocha test framework](http://f.cl.ly/items/3l1k0n2A1U3M1I1L210p/Screen%20Shot%202012-02-24%20at%202.21.43%20PM.png)](http://visionmedia.github.com/mocha) | ||
@@ -5,0 +5,0 @@ Mocha is a simple, flexible, fun JavaScript test framework for node.js and the browser. For more information view the [documentation](http://visionmedia.github.com/mocha). |
@@ -90,3 +90,3 @@ | ||
.replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>') | ||
.replace(/('.*')/gm, '<span class="string">$1</span>') | ||
.replace(/('.*?')/gm, '<span class="string">$1</span>') | ||
.replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>') | ||
@@ -93,0 +93,0 @@ .replace(/(\d+)/gm, '<span class="number">$1</span>') |
describe('Context', function(){ | ||
var prev; | ||
before(function(){ | ||
this.age = 2; | ||
}) | ||
after(function(){ | ||
this.age.should.equal(2); | ||
this.name.should.equal('Tobi'); | ||
this.inspect().should.equal('{\n "age": 2,\n "name": "Tobi"\n}'); | ||
}) | ||
beforeEach(function(){ | ||
this.name = 'Tobi'; | ||
this.age.should.equal(2); | ||
this.calls = ['before']; | ||
}) | ||
afterEach(function(){ | ||
this.name.should.equal('Tobi'); | ||
prev = this; | ||
}) | ||
it('should be maintained between hooks', function(){ | ||
this.name.should.equal('Tobi'); | ||
this.age.should.equal(2); | ||
}) | ||
it('should provide the same object', function(){ | ||
this.should.equal(prev); | ||
}) | ||
describe('when async', function(){ | ||
var prev; | ||
beforeEach(function(done){ | ||
this.name = 'Tobi'; | ||
this.age.should.equal(2); | ||
done(); | ||
describe('nested', function(){ | ||
beforeEach(function(){ | ||
this.calls.push('before two'); | ||
}) | ||
afterEach(function(done){ | ||
this.name.should.equal('Tobi'); | ||
prev = this; | ||
done(); | ||
it('should work', function(){ | ||
this.calls.should.eql(['before', 'before two']); | ||
this.calls.push('test'); | ||
}) | ||
it('should be maintained between hooks', function(done){ | ||
this.name.should.equal('Tobi'); | ||
done(); | ||
after(function(){ | ||
this.calls.should.eql(['before', 'before two', 'test']); | ||
this.calls.push('after two'); | ||
}) | ||
}) | ||
it('should provide the same object', function(done){ | ||
this.should.equal(prev); | ||
done(); | ||
}) | ||
after(function(){ | ||
this.calls.should.eql(['before', 'before two', 'test', 'after two']); | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
142
14246
610452
5
20
+ Addeddiff@1.0.2
+ Addeddiff@1.0.2(transitive)