Skip to content

Commit 12eac07

Browse files
committed
changed the testing to use mocha and actually run completely automated
1 parent 2c266b9 commit 12eac07

File tree

5 files changed

+112
-83
lines changed

5 files changed

+112
-83
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

index.js

+3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ var create_callsite = function(location) {
5858
};
5959

6060
Error.prepareStackTrace = function(error, structured_stack_trace) {
61+
console.log('Error.prepareStackTrace');
62+
console.log(arguments);
6163
error.__cached_trace__ = structured_stack_trace.filter(function(f) {
64+
console.log(f);
6265
return f.getFileName() !== filename;
6366
});
6467

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@
1010
"engines": {
1111
"node": ">= 0.6.0"
1212
},
13+
"devDependencies": {
14+
"mocha": "latest"
15+
},
16+
"scripts": {
17+
"test": "node_modules/mocha/bin/mocha -R spec"
18+
},
1319
"main": "index"
1420
}

test.js

-83
This file was deleted.

test/test-longjohn.js

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
var longjohn = require('../index')
2+
, assert = require("assert");
3+
4+
describe('longjohn', function() {
5+
it('should work with normal throw', function() {
6+
assert.throws(function() {
7+
throw new Error('foo');
8+
});
9+
});
10+
11+
it('should work with errors from other modules', function(done) {
12+
var fs = require('fs');
13+
14+
fs.readFile('not_there.txt', 'utf8', function(err, text) {
15+
if (err && err instanceof Error && err.stack === "Error: ENOENT, open 'not_there.txt'") {
16+
return done();
17+
}
18+
assert.fail();
19+
});
20+
});
21+
22+
it('should track frames across setTimeout', function(done) {
23+
setTimeout(function() {
24+
console.log(new Error('foobar').stack);
25+
}, 1);
26+
});
27+
28+
it('should allow stack size limiting', function(done) {
29+
longjohn.async_trace_limit = 2;
30+
31+
var counter = 0;
32+
33+
var foo = function() {
34+
if (++counter > 3) {
35+
assert.throws(function() {
36+
try {
37+
throw new Error('foo');
38+
} catch (e) {
39+
throw e;
40+
}
41+
}, function(err) {
42+
return err.stack.split(longjohn.empty_frame).length === 3;
43+
});
44+
return done();
45+
}
46+
setTimeout(foo, 1);
47+
}
48+
49+
foo();
50+
});
51+
52+
it('should work with on/emit', function() {
53+
var count = 0;
54+
55+
var foo = function() {
56+
++count;
57+
};
58+
59+
var emitter = new (require('events').EventEmitter)();
60+
61+
emitter.on('foo', foo);
62+
emitter.on('foo', foo);
63+
emitter.on('foo', foo);
64+
65+
emitter.emit('foo');
66+
67+
assert.equal(count, 3);
68+
});
69+
70+
it('should work with removeListener', function() {
71+
var count = 0;
72+
73+
var foo = function() {
74+
++count;
75+
};
76+
77+
var emitter = new (require('events').EventEmitter)();
78+
79+
emitter.on('foo', foo);
80+
emitter.on('foo', foo);
81+
82+
emitter.removeListener('foo', foo);
83+
84+
emitter.emit('foo');
85+
86+
assert.equal(count, 1);
87+
});
88+
89+
it('should work with setTimeout', function(done) {
90+
setTimeout(function() {
91+
assert.deepEqual(Array.prototype.slice.call(arguments), [1, 2, 3]);
92+
done();
93+
}, 1000, 1, 2, 3);
94+
});
95+
96+
it('should work with setInterval', function(done) {
97+
setInterval(function() {
98+
assert.deepEqual(Array.prototype.slice.call(arguments), [1, 2, 3]);
99+
done();
100+
}, 1000, 1, 2, 3);
101+
});
102+
});

0 commit comments

Comments
 (0)