Permalink
Browse files

Updating and adding a bunch more tests.

Added some static stack traces with expected conversions.
  • Loading branch information...
mattrobenolt committed Mar 18, 2012
1 parent 4c79681 commit bb678781c1feb957ad9b9b01ff0c15df5a26e964
View
@@ -21,6 +21,7 @@
"express": "*",
"mocha": "*",
"should": "*",
- "nock": "*"
+ "nock": "*",
+ "glob": "*"
}
}
@@ -0,0 +1,9 @@
+[{
+ "function": "String.CALL_NON_FUNCTION",
+ "filename": "native",
+ "lineno": 0
+}, {
+ "function": "Context.<anonymous>",
+ "filename": "/Does/Not/Exist/test/raven.client.js",
+ "lineno": 73
+}]
@@ -0,0 +1,3 @@
+TypeError: string is not a function
+ at String.CALL_NON_FUNCTION (native)
+ at Context.<anonymous> (/Does/Not/Exist/test/raven.client.js:73:13)
@@ -0,0 +1,35 @@
+[{
+ "function": "Context.<anonymous>",
+ "filename": "/Does/Not/Exist/test/raven.client.js",
+ "lineno": 43
+}, {
+ "function": "Test.run",
+ "filename": "/Does/Not/Exist/node_modules/mocha/lib/runnable.js",
+ "lineno": 143
+}, {
+ "function": "Runner.runTest",
+ "filename": "/Does/Not/Exist/node_modules/mocha/lib/runner.js",
+ "lineno": 272
+}, {
+ "filename": "/Does/Not/Exist/node_modules/mocha/lib/runner.js",
+ "lineno": 316
+}, {
+ "function": "next",
+ "filename": "/Does/Not/Exist/node_modules/mocha/lib/runner.js",
+ "lineno": 199
+}, {
+ "filename": "/Does/Not/Exist/node_modules/mocha/lib/runner.js",
+ "lineno": 208
+}, {
+ "function": "next",
+ "filename": "/Does/Not/Exist/node_modules/mocha/lib/runner.js",
+ "lineno": 157
+}, {
+ "function": "Array.0",
+ "filename": "/Does/Not/Exist/node_modules/mocha/lib/runner.js",
+ "lineno": 176
+}, {
+ "function": "EventEmitter._tickCallback",
+ "filename": "node.js",
+ "lineno": 192
+}]
@@ -0,0 +1,10 @@
+Error
+ at Context.<anonymous> (/Does/Not/Exist/test/raven.client.js:43:36)
+ at Test.run (/Does/Not/Exist/node_modules/mocha/lib/runnable.js:143:15)
+ at Runner.runTest (/Does/Not/Exist/node_modules/mocha/lib/runner.js:272:10)
+ at /Does/Not/Exist/node_modules/mocha/lib/runner.js:316:12
+ at next (/Does/Not/Exist/node_modules/mocha/lib/runner.js:199:14)
+ at /Does/Not/Exist/node_modules/mocha/lib/runner.js:208:7
+ at next (/Does/Not/Exist/node_modules/mocha/lib/runner.js:157:23)
+ at Array.0 (/Does/Not/Exist/node_modules/mocha/lib/runner.js:176:5)
+ at EventEmitter._tickCallback (node.js:192:40)
@@ -0,0 +1,41 @@
+[{
+ "function": "trace",
+ "filename": "/Does/Not/Exist/test/fixtures/stack.js",
+ "lineno": 11
+}, {
+ "function": "bar",
+ "filename": "/Does/Not/Exist/test/fixtures/stack.js",
+ "lineno": 7
+}, {
+ "function": "foo",
+ "filename": "/Does/Not/Exist/test/fixtures/stack.js",
+ "lineno": 2
+}, {
+ "function": "Object.<anonymous>",
+ "filename": "/Does/Not/Exist/test/fixtures/stack.js",
+ "lineno": 14
+}, {
+ "function": "Module._compile",
+ "filename": "module.js",
+ "lineno": 441
+}, {
+ "function": "Object..js",
+ "filename": "module.js",
+ "lineno": 459
+}, {
+ "function": "Module.load",
+ "filename": "module.js",
+ "lineno": 348
+}, {
+ "function": "Function._load",
+ "filename": "module.js",
+ "lineno": 308
+}, {
+ "function": "Array.0",
+ "filename": "module.js",
+ "lineno": 479
+}, {
+ "function": "EventEmitter._tickCallback",
+ "filename": "node.js",
+ "lineno": 192
+}]
@@ -0,0 +1,11 @@
+ReferenceError: __stack is not defined
+ at trace (/Does/Not/Exist/test/fixtures/stack.js:11:15)
+ at bar (/Does/Not/Exist/test/fixtures/stack.js:7:3)
+ at foo (/Does/Not/Exist/test/fixtures/stack.js:2:3)
+ at Object.<anonymous> (/Does/Not/Exist/test/fixtures/stack.js:14:1)
+ at Module._compile (module.js:441:26)
+ at Object..js (module.js:459:10)
+ at Module.load (module.js:348:31)
+ at Function._load (module.js:308:12)
+ at Array.0 (module.js:479:10)
+ at EventEmitter._tickCallback (node.js:192:40)
View
@@ -4,6 +4,12 @@ var raven = require('../')
var dsn = 'https://public:private@app.getsentry.com/269';
+function wait(scope, done) {
+ setTimeout(function() {
+ scope.done(); done();
+ }, 10);
+}
+
describe('raven.version', function(){
it('should be valid', function(){
raven.version.should.match(/^\d+\.\d+\.\d+(-\w+)?$/);
@@ -34,7 +40,48 @@ describe('raven.Client', function(){
.reply(200, 'OK');
client.createFromText('Hey!');
- setTimeout(function(){scope.done(); done();}, 10); // Really should not take more than 10ms to work.
+ wait(scope, done);
+ });
+ });
+
+ describe('#createFromError()', function(){
+ it('should send an Error to Sentry server', function(done){
+ var scope = nock('https://app.getsentry.com')
+ .filteringRequestBody(/.*/, '*')
+ .post('/api/store/', '*')
+ .reply(200, 'OK');
+
+ client.createFromError(new Error('wtf?'));
+ wait(scope, done);
+ });
+ });
+
+ describe('#patchGlobal()', function(){
+ it('should add itself to the uncaughtException event list', function(){
+ var before = process._events.uncaughtException;
+ client.patchGlobal();
+ process._events.uncaughtException.length.should.equal(before.length+1);
+ process._events.uncaughtException = before; // patch it back to what it was
+ });
+
+ /* Why can't I do this?!?!
+ it('should send an uncaughtException to Sentry server', function(done){
+ var scope = nock('https://app.getsentry.com')
+ .filteringRequestBody(/.*\/, '*')
+ .post('/api/store/', '*')
+ .reply(200, 'OK');
+ var before = process._events.uncaughtException;
+ process.removeAllListeners('uncaughtException');
+ console.log(process._events);
+ client.patchGlobal();
+ console.log(process._events);
+ ''(); // should be caught and sent to Sentry
+ before.forEach(function(cb) {
+ // restore old callbacks
+ process.on('uncaughtException', cb);
+ });
+ done();
});
+ */
});
});
View
@@ -0,0 +1,102 @@
+var raven = require('../');
+raven.parsers = require('../lib/parsers');
+
+describe('raven.parsers', function(){
+ describe('#parseText()', function(){
+ it('should parse some text without kwargs', function(){
+ var parsed = raven.parsers.parseText('Howdy');
+ parsed['message'].should.equal('Howdy');
+ parsed.should.have.property('sentry.interfaces.Message');
+ parsed['sentry.interfaces.Message'].message.should.equal('Howdy');
+ });
+
+ it('should parse some text with kwargs', function(){
+ var parsed = raven.parsers.parseText('Howdy', {'foo': 'bar'});
+ parsed['message'].should.equal('Howdy');
+ parsed.should.have.property('sentry.interfaces.Message');
+ parsed['sentry.interfaces.Message'].message.should.equal('Howdy');
+ parsed['foo'].should.equal('bar');
+ });
+ });
+
+ describe('#parseError()', function(){
+ it('should parse plain Error object', function(done){
+ raven.parsers.parseError(new Error(), {}, function(parsed){
+ parsed['message'].should.equal('Error: <no message>');
+ parsed.should.have.property('sentry.interfaces.Exception');
+ parsed['sentry.interfaces.Exception']['type'].should.equal('Error');
+ parsed['sentry.interfaces.Exception']['value'].should.equal('');
+ parsed.should.have.property('sentry.interfaces.Stacktrace');
+ parsed['sentry.interfaces.Stacktrace'].should.have.property('frames');
+ parsed.should.have.property('culprit');
+ parsed['culprit'].should.match(/^.+?:.+$/);
+ done();
+ });
+ });
+
+ it('should parse Error with message', function(done){
+ raven.parsers.parseError(new Error('Crap'), {}, function(parsed){
+ parsed['message'].should.equal('Error: Crap');
+ parsed.should.have.property('sentry.interfaces.Exception');
+ parsed['sentry.interfaces.Exception']['type'].should.equal('Error');
+ parsed['sentry.interfaces.Exception']['value'].should.equal('Crap');
+ parsed.should.have.property('sentry.interfaces.Stacktrace');
+ parsed['sentry.interfaces.Stacktrace'].should.have.property('frames');
+ parsed.should.have.property('culprit');
+ parsed['culprit'].should.match(/^.+?:.+$/);
+ done();
+ });
+ });
+
+ it('should parse TypeError with message', function(done){
+ raven.parsers.parseError(new TypeError('Crap'), {}, function(parsed){
+ parsed['message'].should.equal('TypeError: Crap');
+ parsed.should.have.property('sentry.interfaces.Exception');
+ parsed['sentry.interfaces.Exception']['type'].should.equal('TypeError');
+ parsed['sentry.interfaces.Exception']['value'].should.equal('Crap');
+ parsed.should.have.property('sentry.interfaces.Stacktrace');
+ parsed['sentry.interfaces.Stacktrace'].should.have.property('frames');
+ parsed.should.have.property('culprit');
+ parsed['culprit'].should.match(/^.+?:.+$/);
+ done();
+ });
+ });
+
+ it('should parse thrown Error', function(done){
+ try {
+ throw new Error('Derp');
+ } catch(e) {
+ raven.parsers.parseError(e, {}, function(parsed){
+ parsed['message'].should.equal('Error: Derp');
+ parsed.should.have.property('sentry.interfaces.Exception');
+ parsed['sentry.interfaces.Exception']['type'].should.equal('Error');
+ parsed['sentry.interfaces.Exception']['value'].should.equal('Derp');
+ parsed.should.have.property('sentry.interfaces.Stacktrace');
+ parsed['sentry.interfaces.Stacktrace'].should.have.property('frames');
+ parsed.should.have.property('culprit');
+ parsed['culprit'].should.match(/^.+?:.+$/);
+ done();
+ });
+ }
+ });
+
+ it('should parse caught real error', function(done){
+ try {
+ var o = {};
+ o['...']['Derp']();
+ } catch(e) {
+ raven.parsers.parseError(e, {}, function(parsed){
+ parsed['message'].should.equal('TypeError: Cannot call method \'Derp\' of undefined');
+ parsed.should.have.property('sentry.interfaces.Exception');
+ parsed['sentry.interfaces.Exception']['type'].should.equal('TypeError');
+ parsed['sentry.interfaces.Exception']['value'].should.equal('Cannot call method \'Derp\' of undefined');
+ parsed.should.have.property('sentry.interfaces.Stacktrace');
+ parsed['sentry.interfaces.Stacktrace'].should.have.property('frames');
+ parsed.should.have.property('culprit');
+ parsed['culprit'].should.match(/^.+?:.+$/);
+ done();
+ });
+ }
+ });
+ });
+});
Oops, something went wrong.

0 comments on commit bb67878

Please sign in to comment.