Socket
Socket
Sign inDemoInstall

mocha

Package Overview
Dependencies
Maintainers
1
Versions
199
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mocha - npm Package Compare versions

Comparing version 0.14.0 to 0.14.1

lib/browser/diff.js

9

History.md
0.14.1 / 2012-03-06
==================
* Added lib-cov to _.npmignore_
* Added reporter to `mocha.run([reporter])` as argument
* Added some margin-top to the HTML reporter
* Removed jQuery dependency
* Fixed `--watch`: purge require cache. Closes #266
0.14.0 / 2012-03-01

@@ -3,0 +12,0 @@ ==================

2

lib/mocha.js

@@ -12,3 +12,3 @@

exports.version = '0.14.0';
exports.version = '0.14.1';

@@ -15,0 +15,0 @@ exports.utils = require('./utils');

@@ -38,11 +38,13 @@

// TODO: clean up
var self = this
, stats = this.stats
, total = runner.total
, root = $('#mocha')
, root = document.getElementById('mocha')
, stat = fragment(statsTemplate)
, items = stat.getElementsByTagName('li')
, passes = items[1].getElementsByTagName('em')[0]
, failures = items[2].getElementsByTagName('em')[0]
, duration = items[3].getElementsByTagName('em')[0]
, canvas = stat.getElementsByTagName('canvas')[0]
, stack = [root]
, stat = $(statsTemplate).appendTo(root)
, canvas = stat.find('canvas').get(0)
, progress

@@ -56,4 +58,6 @@ , ctx

if (!root.length) return error('#mocha div missing, add it to your document');
if (!root) return error('#mocha div missing, add it to your document');
root.appendChild(stat);
if (progress) progress.size(40);

@@ -65,8 +69,8 @@

// suite
var el = $('<div class="suite"><h1>' + suite.title + '</h1></div>');
var el = fragment('<div class="suite"><h1>%s</h1></div>', suite.title);
// container
stack[0].append(el);
stack.unshift($('<div>'));
el.append(stack[0]);
stack[0].appendChild(el);
stack.unshift(document.createElement('div'));
el.appendChild(stack[0]);
});

@@ -86,20 +90,17 @@

var percent = stats.tests / total * 100 | 0;
if (progress) progress.update(percent).draw(ctx);
if (progress) {
progress.update(percent).draw(ctx);
}
// update stats
var ms = new Date - stats.start;
stat.find('.passes em').text(stats.passes);
stat.find('.failures em').text(stats.failures);
stat.find('.duration em').text((ms / 1000).toFixed(2));
text(passes, stats.passes);
text(failures, stats.failures);
text(duration, (ms / 1000).toFixed(2));
// test
if ('passed' == test.state) {
var el = $('<div class="test pass"><h2>' + escape(test.title) + '</h2></div>')
var el = fragment('<div class="test pass"><h2>%e</h2></div>', test.title);
} else if (test.pending) {
var el = $('<div class="test pass pending"><h2>' + escape(test.title) + '</h2></div>')
var el = fragment('<div class="test pass pending"><h2>%e</h2></div>', test.title);
} else {
var el = $('<div class="test fail"><h2>' + escape(test.title) + '</h2></div>');
var el = fragment('<div class="test fail"><h2>%e</h2></div>', test.title);
var str = test.err.stack || test.err;

@@ -111,10 +112,12 @@

$('<pre class="error">' + escape(str) + '</pre>').appendTo(el);
el.appendChild(fragment('<pre class="error">%e</pre>', str));
}
// toggle code
el.find('h2').toggle(function(){
pre && pre.slideDown('fast');
}, function(){
pre && pre.slideUp('fast');
var h2 = el.getElementsByTagName('h2')[0];
on(h2, 'click', function(){
pre.style.display = 'none' == pre.style.display
? 'block'
: 'none';
});

@@ -125,7 +128,8 @@

if (!test.pending) {
var code = escape(clean(test.fn.toString()));
var pre = $('<pre><code>' + code + '</code></pre>');
pre.appendTo(el).hide();
var pre = fragment('<pre><code>%e</code></pre>', clean(test.fn.toString()));
el.appendChild(pre);
pre.style.display = 'none';
}
stack[0].append(el);
stack[0].appendChild(el);
});

@@ -139,6 +143,49 @@ }

function error(msg) {
$('<div id="error">' + msg + '</div>').appendTo('body');
document.body.appendChild(fragment('<div id="error">%s</div>', msg));
}
/**
* Return a DOM fragment from `html`.
*/
function fragment(html) {
var args = arguments
, div = document.createElement('div')
, i = 1;
div.innerHTML = html.replace(/%([se])/g, function(_, type){
switch (type) {
case 's': return String(args[i++]);
case 'e': return escape(args[i++]);
}
});
return div.firstChild;
}
/**
* Set `el` text to `str`.
*/
function text(el, str) {
if (el.textContent) {
el.textContent = str;
} else {
el.innerText = str;
}
}
/**
* Listen on `event` with callback `fn`.
*/
function on(el, event, fn) {
if (el.addEventListener) {
el.addEventListener(event, fn, false);
} else {
el.attachEvent('on' + event, fn);
}
}
/**
* Strip the function definition from `str`,

@@ -145,0 +192,0 @@ * and re-indent for pre whitespace.

{
"name": "mocha"
, "version": "0.14.0"
, "version": "0.14.1"
, "description": "simple, flexible, fun test framework"

@@ -5,0 +5,0 @@ , "keywords": ["test", "bdd", "tdd", "tap"]

@@ -49,2 +49,3 @@

.replace(/require\('path'\)/g, "require('browser/path')")
.replace(/require\('diff'\)/g, "require('browser/diff')")
.replace(/require\('tty'\)/g, "require('browser/tty')")

@@ -51,0 +52,0 @@ .replace(/require\('fs'\)/g, "require('browser/fs')")

@@ -73,10 +73,3 @@

, utils = mocha.utils
, Reporter = mocha.reporters.HTML
$(function(){
$('code').each(function(){
$(this).html(highlight($(this).text()));
});
});
/**

@@ -99,2 +92,13 @@ * Highlight the given string of `js`.

/**
* Highlight code contents.
*/
function highlightCode() {
var code = document.getElementsByTagName('code');
for (var i = 0, len = code.length; i < len; ++i) {
code[i].innerHTML = highlight(code[i].innerHTML);
}
}
/**
* Parse the given `qs`.

@@ -129,15 +133,12 @@ */

mocha.run = function(){
mocha.run = function(Reporter){
suite.emit('run');
var runner = new mocha.Runner(suite);
Reporter = Reporter || mocha.reporters.HTML;
var reporter = new Reporter(runner);
var query = parse(window.location.search || "");
if (query.grep) runner.grep(new RegExp(query.grep));
runner.on('end', function(){
$('code').each(function(){
$(this).html(highlight($(this).text()));
});
});
runner.on('end', highlightCode);
return runner.run();
};
})();

@@ -5,3 +5,5 @@

it('should highlight in red', function(done){
setTimeout(done, 100);
setTimeout(function(){
done();
}, 100);
})

@@ -12,3 +14,5 @@ })

it('should highlight in yellow', function(done){
setTimeout(done, 50);
setTimeout(function(){
done();
}, 50);
})

@@ -19,5 +23,7 @@ })

it('should highlight in green', function(done){
setTimeout(done, 10);
setTimeout(function(){
done();
}, 10);
})
})
})

@@ -17,5 +17,7 @@

this.timeout(1000);
setTimeout(done, 300);
setTimeout(function(){
done();
}, 300);
})
})
describe('Array', function(){
describe('#indexOf()', function(){
it('should return -1 when the value is not present', function(){
var arr = [1,2,3];
assert(-1 == arr.indexOf(5));
describe('#push()', function(){
it('should append a value', function(){
var arr = [];
arr.push('foo');
arr.push('bar');
arr.push('baz');
assert('foo' == arr[0]); // to test indentation
assert('bar' == arr[1]);
assert('baz' == arr[2]);
})
it('should be pending')
it('should return the correct index when the value is present', function(){
var arr = [1,2,3];
assert(0 == arr.indexOf(1)); // just to test indentation
assert(1 == arr.indexOf(2));
it('should return the length', function(){
var arr = [];
assert(1 == arr.push('foo'));
assert(2 == arr.push('bar'));
assert(3 == arr.push('baz'));
})

@@ -20,8 +24,7 @@ })

describe('#pop()', function(){
it('should remove and return the last value', function(done){
it('should remove and return the last value', function(){
var arr = [1,2,3];
assert(arr.pop() == 3);
setTimeout(function(){
doesNotExist();
}, 0);
assert(arr.pop() == 2);
assert(arr.pop() == 1);
})

@@ -28,0 +31,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc