Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added test coverage for native frames in error stacks

  • Loading branch information...
commit 6ef7bdf5b8b6bb4bc42dd2fb71c87d6f9e18ce92 1 parent 0095380
Merlyn Albery-Speyer authored
Showing with 22 additions and 7 deletions.
  1. +22 −7 test/test.js
View
29 test/test.js
@@ -8,7 +8,7 @@ var unnamed = fixture.unnamed,
var trace = require('../trace').trace;
-var expected = 'random_'+~~(Math.random()*100)
+var expected = 'random_'+~~(Math.random()*100);
var local_unnamed = function(text) {
throw new Error(text);
@@ -19,7 +19,6 @@ try {
} catch(err) {
var traced = trace(err);
- assert.equal(traced.frames.length, err.stack.split('\n').length - 1);
assert.ok(!!~['<anonymous>', 'local_unnamed'].indexOf(traced.frames[0].named_location));
assert_stacks_equal(err, traced);
@@ -29,8 +28,6 @@ try {
unnamed(expected);
} catch(err) {
var traced = trace(err);
- assert.equal(traced.frames.length, err.stack.split('\n').length - 1);
-
assert_stacks_equal(err, traced);
}
@@ -38,21 +35,39 @@ try {
named(expected);
} catch(err) {
var traced = trace(err);
- assert.equal(traced.frames.length, err.stack.split('\n').length - 1);
-
assert_stacks_equal(err, traced);
}
+(function () {
+ var err = {
+ stack: "TypeError: Cannot read property 'toString' of undefined\n"+
+ " at /Users/merlyn/fun/pdxnode/node_modules/tracejs/trace.js:85:17\n"+
+ " at Array.map (native)\n"+
+ " at Trace.toString (/Users/merlyn/fun/pdxnode/node_modules/tracejs/trace.js:84:69)\n"+
+ " at Domain.<anonymous> (/Users/merlyn/fun/pdxnode/bot.js:8:27)\n"+
+ " at Domain.EventEmitter.emit (events.js:96:17)\n"+
+ " at process.uncaughtHandler (domain.js:61:20)\n"+
+ " at process.EventEmitter.emit (events.js:126:20)"
+ };
+
+ var traced = trace(err);
+ assert_stacks_equal(err, traced);
+})();
+
console.error('Tests passed');
return;
function assert_stacks_equal(err, traced) {
+ assert.equal(traced.frames.length, err.stack.split('\n').length - 1);
assert.equal(traced.first_line, err.stack.split('\n')[0]);
assert.strictEqual(traced.original_error, err);
var lines = err.stack.split('\n').slice(1);
for(var i = 0, len = lines.length; i < len; ++i) {
- assert.notStrictEqual(lines[i].indexOf(traced.frames[i].line + ':' + traced.frames[i].character), -1);
+ assert.ok(traced.frames[i], "Expected frame to be defined for line: '"+lines[i]+"'");
+ if (!/\(native\)$/.test(lines[i])) {
+ assert.notStrictEqual(lines[i].indexOf(traced.frames[i].line + ':' + traced.frames[i].character), -1);
+ }
assert.notStrictEqual(lines[i].indexOf(traced.frames[i].filename), -1);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.