stack-trace-parser
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "stack-trace-parser", | ||
"description": "parse stack trace", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "src/parser.js", | ||
@@ -6,0 +6,0 @@ "dependencies": {}, |
@@ -40,7 +40,10 @@ var parser = require('../src/parser'); | ||
describe('simple stack trace', function() { | ||
var error = {}, | ||
parsed; | ||
describe('stack trace', function() { | ||
var error; | ||
beforeEach(function() { | ||
error = {}; | ||
}); | ||
it('parses the file names from a basic stack trace', function() { | ||
error.stack = | ||
@@ -50,10 +53,27 @@ 'Error: Foo\n' + | ||
' at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)\n'; | ||
parsed = parser.parse(error); | ||
expect(parsed[0].fileName).toBe('/Users/hoitz/develop/test.coffee'); | ||
expect(parsed[1].fileName).toBe('timers.js'); | ||
}); | ||
it('parses the file names from a basic stack trace', function() { | ||
expect(parsed[0].fileName).toBe('/Users/hoitz/develop/test.coffee'); | ||
expect(parsed[1].fileName).toBe('timers.js'); | ||
it('parses type exception type', function() { | ||
error.stack = | ||
'ReferenceError: d is not defined\n' + | ||
' at Object.<anonymous> (/Users/cvig/dev/node-stack-trace-parser/example-undefined.js:5:7)\n' + | ||
' at Module._compile (module.js:456:26)\n' + | ||
' at Object.Module._extensions..js (module.js:474:10)\n' + | ||
' at Module.load (module.js:356:32)\n' + | ||
' at Function.Module._load (module.js:312:12)\n' + | ||
' at Function.Module.runMain (module.js:497:10)\n' + | ||
' at startup (node.js:119:16)\n' + | ||
' at node.js:902:3\n'; | ||
parsed = parser.parse(error); | ||
expect(parsed.type).toBe('ReferenceError'); | ||
expect(parsed.message).toBe('d is not defined'); | ||
}); | ||
}); | ||
}); |
@@ -38,5 +38,19 @@ var _ = require('lodash'); | ||
var getTypeAndMessage = function(line) { | ||
var typeAndMessageArray = line.split(': '); | ||
return { | ||
type: typeAndMessageArray[0], | ||
message: typeAndMessageArray[1] | ||
}; | ||
}; | ||
module.exports = { | ||
parse: function(error) { | ||
return error.stack.split('\n').slice(1).map(this.parseLine); | ||
var lines = error.stack.split('\n'); | ||
var typeAndMessage = getTypeAndMessage(lines[0]); | ||
var parsedLines = lines.slice(1).map(this.parseLine); | ||
return _.extend(typeAndMessage, parsedLines); | ||
}, | ||
@@ -43,0 +57,0 @@ |
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
8292
9
133