-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(runner/stack-trace): solve issue #545 + test
- Loading branch information
Showing
9 changed files
with
347 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -629,3 +629,68 @@ exports.getError = function(err) { | |
return err || exports.undefinedError(); | ||
}; | ||
|
||
|
||
/** | ||
* @summary | ||
* This Filter based on `mocha-clean` module.(see: `github.com/rstacruz/mocha-clean`) | ||
* @description | ||
* When invoking this function you get a filter function that get the Error.stack as an input, | ||
* and return a prettify output. | ||
* (i.e: strip Mocha, node_modules, bower and componentJS from stack trace). | ||
* @returns {Function} | ||
*/ | ||
|
||
exports.stackTraceFilter = function() { | ||
var slash = '/' | ||
, is = typeof document === 'undefined' | ||
? { node: true } | ||
: { browser: true } | ||
, cwd = is.node | ||
? process.cwd() + slash | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
benjamn
|
||
: location.href.replace(/\/[^\/]*$/, '/'); | ||
|
||
function isNodeModule (line) { | ||
return (~line.indexOf('node_modules')); | ||
} | ||
|
||
function isMochaInternal (line) { | ||
return (~line.indexOf('node_modules' + slash + 'mocha')) || | ||
(~line.indexOf('components' + slash + 'mochajs')) || | ||
(~line.indexOf('components' + slash + 'mocha')); | ||
} | ||
|
||
// node_modules, bower, componentJS | ||
function isBrowserModule(line) { | ||
return (~line.indexOf('node_modules')) || | ||
(~line.indexOf('components')); | ||
} | ||
|
||
function isNodeInternal (line) { | ||
return (~line.indexOf('(timers.js:')) || | ||
(~line.indexOf('(events.js:')) || | ||
(~line.indexOf('(node.js:')) || | ||
(~line.indexOf('(module.js:')) || | ||
(~line.indexOf('GeneratorFunctionPrototype.next (native)')) || | ||
false | ||
} | ||
|
||
return function(stack) { | ||
stack = stack.split('\n'); | ||
|
||
stack = stack.reduce(function (list, line) { | ||
if (is.node && (isNodeModule(line) || | ||
isMochaInternal(line) || | ||
isNodeInternal(line))) | ||
return list; | ||
|
||
if (is.browser && (isBrowserModule(line))) | ||
return list; | ||
|
||
// Clean up cwd(absolute) | ||
list.push(line.replace(cwd, '')); | ||
return list; | ||
}, []); | ||
|
||
return stack.join('\n'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<html> | ||
<head> | ||
<title>Mocha</title> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="../../mocha.css" /> | ||
<script src="../../mocha.js"></script> | ||
<script>mocha.setup('bdd')</script> | ||
<script> | ||
function assert(expr, err) { | ||
if (!expr) throw err; | ||
} | ||
</script> | ||
<script src="stack-trace.js"></script> | ||
<script> | ||
onload = function() { | ||
mocha.run(); | ||
}; | ||
</script> | ||
</head> | ||
<body> | ||
<div id="mocha"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
describe('Stack trace', function() { | ||
it('should prettify the stack-trace', function() { | ||
var err = new Error(); | ||
// We do this fake stack-trace because we under development, | ||
// and our root isn't `node_modules`, `bower` or `components` | ||
err.stack = ['Error: failed' | ||
, 'at assert (stack-trace.html:11:30)' | ||
, 'at Context.<anonymous> (stack-trace.js:5:5)' | ||
, 'at callFn (http://localhost:63342/node_modules/mocha.js:4546:21)' | ||
, 'at Test.require.register.Runnable.run (http://localhost:63342/node_modules/mocha.js:4539:7)' | ||
, 'at Runner.require.register.Runner.runTest (http://localhost:63342/node_modules/mocha.js:4958:10)' | ||
, 'at http://localhost:63342/bower_components/mocha.js:5041:12' | ||
, 'at next (http://localhost:63342/bower_components/mocha.js:4883:14)' | ||
, 'at http://localhost:63342/bower_components/mocha.js:4893:7' | ||
, 'at next (http://localhost:63342/bower_components/mocha.js:4828:23)' | ||
, 'at http://localhost:63342/bower_components/mocha.js:4860:5'].join('\n'); | ||
assert(false, err); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
I'm seeing this function called at a time when this
process
refers to the variablemocha/mocha.js
Line 6426 in f08b789
process
object, so there is no.cwd
method… any idea what to do about that?