Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mochajs/mocha
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.5.2
Choose a base ref
...
head repository: mochajs/mocha
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.5.3
Choose a head ref
  • 6 commits
  • 5 files changed
  • 4 contributors

Commits on May 25, 2016

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    08cb423 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6d24063 View commit details
  3. Copy the full SHA
    9e93efc View commit details
  4. Copy the full SHA
    7496c14 View commit details
  5. Rebuild mocha.js

    dasilvacontin committed May 25, 2016
    Copy the full SHA
    52dcc3f View commit details
  6. Release v2.5.3

    dasilvacontin committed May 25, 2016
    Copy the full SHA
    e939d8e View commit details
Showing with 181 additions and 140 deletions.
  1. +4 −1 .travis.yml
  2. +10 −0 CHANGELOG.md
  3. +83 −69 lib/reporters/html.js
  4. +83 −69 mocha.js
  5. +1 −1 package.json
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -8,10 +8,13 @@ dist: trusty

language: node_js

env:
global: PHANTOMJS_CDNURL='https://cnpmjs.org/downloads'

matrix:
include:
- node_js: '6'
env: TARGET="clean lint test-node test-browser"
env: TARGET='clean lint test-node test-browser'
- node_js: '5'
env: TARGET=test-node
- node_js: '4'
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 2.5.3 / 2016-05-25

- [#2112] - Fix HTML reporter regression causing duplicate error output ([@danielstjules] via 6d24063)
- [#2119] - Make HTML reporter failure/passed links preventDefault to avoid SPA's hash navigation ([@jimenglish81] via 9e93efc)

[@danielstjules]: https://github.com/danielstjules
[@jimenglish81]: https://github.com/jimenglish81
[#2112]: https://github.com/mochajs/mocha/pull/2112
[#2119]: https://github.com/mochajs/mocha/pull/2119

# 2.5.2 / 2016-05-24

- [#2178] - Avoid double and triple xUnit XML escaping ([@graingert] via 49b5ff1)
152 changes: 83 additions & 69 deletions lib/reporters/html.js
Original file line number Diff line number Diff line change
@@ -80,7 +80,8 @@ function HTML(runner) {
}

// pass toggle
on(passesLink, 'click', function() {
on(passesLink, 'click', function(evt) {
evt.preventDefault();
unhide();
var name = (/pass/).test(report.className) ? '' : ' pass';
report.className = report.className.replace(/fail|pass/g, '') + name;
@@ -90,7 +91,8 @@ function HTML(runner) {
});

// failure toggle
on(failuresLink, 'click', function() {
on(failuresLink, 'click', function(evt) {
evt.preventDefault();
unhide();
var name = (/fail/).test(report.className) ? '' : ' fail';
report.className = report.className.replace(/fail|pass/g, '') + name;
@@ -128,88 +130,82 @@ function HTML(runner) {
stack.shift();
});

runner.on('fail', function(test) {
// For type = 'test' its possible that the test failed due to multiple
// done() calls. So report the issue here.
if (test.type === 'hook'
|| test.type === 'test') {
runner.emit('test end', test);
}
runner.on('pass', function(test) {
var url = self.testURL(test);
var markup = '<li class="test pass %e"><h2>%e<span class="duration">%ems</span> '
+ '<a href="%s" class="replay">‣</a></h2></li>';
var el = fragment(markup, test.speed, test.title, test.duration, url);
self.addCodeToggle(el, test.body);
appendToStack(el);
updateStats();
});

runner.on('test end', function(test) {
// TODO: add to stats
var percent = stats.tests / this.total * 100 | 0;
if (progress) {
progress.update(percent).draw(ctx);
runner.on('fail', function(test) {
var el = fragment('<li class="test fail"><h2>%e <a href="%e" class="replay">‣</a></h2></li>',
test.title, self.testURL(test));
var stackString; // Note: Includes leading newline
var message = test.err.toString();

// <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
// check for the result of the stringifying.
if (message === '[object Error]') {
message = test.err.message;
}

// update stats
var ms = new Date() - stats.start;
text(passes, stats.passes);
text(failures, stats.failures);
text(duration, (ms / 1000).toFixed(2));

// test
var el;
if (test.state === 'passed') {
var url = self.testURL(test);
el = fragment('<li class="test pass %e"><h2>%e<span class="duration">%ems</span> <a href="%s" class="replay">‣</a></h2></li>', test.speed, test.title, test.duration, url);
} else if (test.isPending()) {
el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
} else {
el = fragment('<li class="test fail"><h2>%e <a href="%e" class="replay">‣</a></h2></li>', test.title, self.testURL(test));
var stackString; // Note: Includes leading newline
var message = test.err.toString();

// <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
// check for the result of the stringifying.
if (message === '[object Error]') {
message = test.err.message;
}

if (test.err.stack) {
var indexOfMessage = test.err.stack.indexOf(test.err.message);
if (indexOfMessage === -1) {
stackString = test.err.stack;
} else {
stackString = test.err.stack.substr(test.err.message.length + indexOfMessage);
}
} else if (test.err.sourceURL && test.err.line !== undefined) {
// Safari doesn't give you a stack. Let's at least provide a source line.
stackString = '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
}

stackString = stackString || '';

if (test.err.htmlMessage && stackString) {
el.appendChild(fragment('<div class="html-error">%s\n<pre class="error">%e</pre></div>', test.err.htmlMessage, stackString));
} else if (test.err.htmlMessage) {
el.appendChild(fragment('<div class="html-error">%s</div>', test.err.htmlMessage));
if (test.err.stack) {
var indexOfMessage = test.err.stack.indexOf(test.err.message);
if (indexOfMessage === -1) {
stackString = test.err.stack;
} else {
el.appendChild(fragment('<pre class="error">%e%e</pre>', message, stackString));
stackString = test.err.stack.substr(test.err.message.length + indexOfMessage);
}
} else if (test.err.sourceURL && test.err.line !== undefined) {
// Safari doesn't give you a stack. Let's at least provide a source line.
stackString = '\n(' + test.err.sourceURL + ':' + test.err.line + ')';
}

// toggle code
// TODO: defer
if (!test.isPending()) {
var h2 = el.getElementsByTagName('h2')[0];
stackString = stackString || '';

on(h2, 'click', function() {
pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
});

var pre = fragment('<pre><code>%e</code></pre>', utils.clean(test.body));
el.appendChild(pre);
pre.style.display = 'none';
if (test.err.htmlMessage && stackString) {
el.appendChild(fragment('<div class="html-error">%s\n<pre class="error">%e</pre></div>',
test.err.htmlMessage, stackString));
} else if (test.err.htmlMessage) {
el.appendChild(fragment('<div class="html-error">%s</div>', test.err.htmlMessage));
} else {
el.appendChild(fragment('<pre class="error">%e%e</pre>', message, stackString));
}

self.addCodeToggle(el, test.body);
appendToStack(el);
updateStats();
});

runner.on('pending', function(test) {
var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
appendToStack(el);
updateStats();
});

function appendToStack(el) {
// Don't call .appendChild if #mocha-report was already .shift()'ed off the stack.
if (stack[0]) {
stack[0].appendChild(el);
}
});
}

function updateStats() {
// TODO: add to stats
var percent = stats.tests / this.total * 100 | 0;
if (progress) {
progress.update(percent).draw(ctx);
}

// update stats
var ms = new Date() - stats.start;
text(passes, stats.passes);
text(failures, stats.failures);
text(duration, (ms / 1000).toFixed(2));
}
}

/**
@@ -247,6 +243,24 @@ HTML.prototype.testURL = function(test) {
return makeUrl(test.fullTitle());
};

/**
* Adds code toggle functionality for the provided test's list element.
*
* @param {HTMLLIElement} el
* @param {string} contents
*/
HTML.prototype.addCodeToggle = function(el, contents) {
var h2 = el.getElementsByTagName('h2')[0];

on(h2, 'click', function() {
pre.style.display = pre.style.display === 'none' ? 'block' : 'none';
});

var pre = fragment('<pre><code>%e</code></pre>', utils.clean(contents));
el.appendChild(pre);
pre.style.display = 'none';
};

/**
* Display error `msg`.
*
Loading