Skip to content

Commit

Permalink
ensure windows compat with stack trace filter; closes #2502
Browse files Browse the repository at this point in the history
- also removed component-related cruft
  • Loading branch information
boneskull committed Sep 27, 2016
1 parent 8ef51a5 commit da5576d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
19 changes: 12 additions & 7 deletions lib/utils.js
Expand Up @@ -9,7 +9,8 @@ var basename = require('path').basename;
var debug = require('debug')('mocha:watch');
var exists = require('fs').existsSync || require('path').existsSync;
var glob = require('glob');
var join = require('path').join;
var path = require('path');
var join = path.join;
var readdirSync = require('fs').readdirSync;
var statSync = require('fs').statSync;
var watchFile = require('fs').watchFile;
Expand Down Expand Up @@ -720,16 +721,20 @@ exports.getError = function(err) {
*/
exports.stackTraceFilter = function() {
// TODO: Replace with `process.browser`
var slash = '/';
var is = typeof document === 'undefined' ? { node: true } : { browser: true };
var cwd = is.node
? process.cwd() + slash
: (typeof location === 'undefined' ? window.location : location).href.replace(/\/[^\/]*$/, '/');
var slash = path.sep;
var cwd;
if (is.node) {
cwd = process.cwd() + slash;
} else {
cwd = (typeof location === 'undefined' ? window.location : location).href.replace(/\/[^\/]*$/, '/');
slash = '/';
}

function isMochaInternal(line) {
return (~line.indexOf('node_modules' + slash + 'mocha' + slash))
|| (~line.indexOf('components' + slash + 'mochajs' + slash))
|| (~line.indexOf('components' + slash + 'mocha' + slash))
|| (~line.indexOf('node_modules' + slash + 'mocha.js'))
|| (~line.indexOf('bower_components' + slash + 'mocha.js'))
|| (~line.indexOf(slash + 'mocha.js'));
}

Expand Down
22 changes: 21 additions & 1 deletion test/utils.spec.js
@@ -1,5 +1,6 @@
var mocha = require('..');
var utils = mocha.utils;
var path = require('path');
var JSON = require('json3');

describe('utils', function() {
Expand Down Expand Up @@ -154,6 +155,25 @@ describe('utils', function() {

filter(stack.join('\n')).should.equal(expected.join('\n'));
});

it('should work on Windows', function() {
if (path.sep === '/') {
return this.skip();
}
var stack = [
'Error: failed',
'at Context.<anonymous> (C:\Users\ishida\src\test\test\mytest.js:5:9)',
'at callFn (C:\Users\ishida\src\test\node_modules\mocha\lib\runnable.js:326:21)',
'at Test.Runnable.run (C:\Users\ishida\src\test\node_modules\mocha\lib\runnable.js:319:7)',
'at Runner.runTest (C:\Users\ishida\src\test\node_modules\mocha\lib\runner.js:422:10)',
'at C:\Users\ishida\src\test\node_modules\mocha\lib\runner.js:528:12',
'at next (C:\Users\ishida\src\test\node_modules\mocha\lib\runner.js:342:14)',
'at C:\Users\ishida\src\test\node_modules\mocha\lib\runner.js:352:7',
'at next (C:\Users\ishida\src\test\node_modules\mocha\lib\runner.js:284:14)',
'at Immediate._onImmediate (C:\Users\ishida\src\test\node_modules\mocha\lib\runner.js:320:5)'
];
filter(stack.join('\n')).should.equal(stack.slice(0,1).join('\n'));
});
});

describe('on browser', function() {
Expand All @@ -163,7 +183,7 @@ describe('utils', function() {
global.location = { href: 'localhost:3000/foo/bar/index.html' };
filter = utils.stackTraceFilter();
});
it('does not strip out other bower_components and components', function() {
it('does not strip out other bower_components', function() {
var stack = ['Error: failed'
, 'at assert (index.html:11:26)'
, 'at Context.<anonymous> (test.js:17:18)'
Expand Down

0 comments on commit da5576d

Please sign in to comment.