Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updating and adding a bunch more tests.

Added some static stack traces with expected conversions.
  • Loading branch information...
commit bb678781c1feb957ad9b9b01ff0c15df5a26e964 1 parent 4c79681
@mattrobenolt mattrobenolt authored
View
3  package.json
@@ -21,6 +21,7 @@
"express": "*",
"mocha": "*",
"should": "*",
- "nock": "*"
+ "nock": "*",
+ "glob": "*"
}
}
View
9 test/fixtures/stacks/native_error.json
@@ -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
+}]
View
3  test/fixtures/stacks/native_error.txt
@@ -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)
View
35 test/fixtures/stacks/no_function_context.json
@@ -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
+}]
View
10 test/fixtures/stacks/no_function_context.txt
@@ -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)
View
41 test/fixtures/stacks/normal_contexts.json
@@ -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
+}]
View
11 test/fixtures/stacks/normal_contexts.txt
@@ -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
49 test/raven.client.js
@@ -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
102 test/raven.parsers.js
@@ -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();
+ });
+ }
+ });
+ });
+});
View
165 test/raven.utils.js
@@ -1,5 +1,7 @@
var raven = require('../')
- , fs = require('fs');
+ , fs = require('fs')
+ , glob = require('glob')
+ , path = require('path');
describe('raven.utils', function() {
describe('#constructChecksum()', function(){
@@ -44,83 +46,104 @@ describe('raven.utils', function() {
};
dsn.should.eql(expected);
});
+ });
- describe('#parseStack()', function(){
- var stack;
- beforeEach(function(done){
- fs.readFile(__dirname + '/fixtures/stack.txt', 'utf8', function(err, data){
- stack = data;
- done();
- });
- });
+ describe('#parseAuthHeader()', function(){
+ it('should parse all parameters', function(){
+ var signature = 'abc',
+ timestamp = 12345,
+ api_key = 'xyz',
+ project_id = 1;
+ var expected = 'Sentry sentry_version=2.0, sentry_signature=abc, sentry_timestamp=12345, sentry_client=raven-node/'+raven.version+', sentry_key=xyz, project_id=1';
+ raven.utils.getAuthHeader(signature, timestamp, api_key, project_id).should.equal(expected);
+ });
+ });
+
+ describe('#parseStack()', function(){
+ var stack;
+ beforeEach(function(){
+ stack = fs.readFileSync(__dirname + '/fixtures/stack.txt', 'utf8');
+ });
- it('should not throw an error', function(done){
- raven.utils.parseStack(stack, done);
+ it('should not throw an error', function(done){
+ raven.utils.parseStack(stack, done);
+ });
+
+ it('should parse the correct number of frames', function(done){
+ raven.utils.parseStack(stack, function(err, frames){
+ frames.length.should.equal(10);
+ done();
});
+ });
- it('should parse the correct number of frames', function(done){
- raven.utils.parseStack(stack, function(err, frames){
- frames.length.should.equal(10);
- done();
- });
+ it('should parse all frames correctly', function(done){
+ var expected = [{
+ 'function': 'trace',
+ filename: './test/fixtures/stack.js',
+ lineno: 11,
+ pre_context: ['', 'function bar(a,b,c) {', ' var test=\'yay!\';', ' trace();', '}', '', 'function trace() {'],
+ context_line: ' console.log(__stack[1].fun.arguments);',
+ post_context: ['}', '', 'foo();', '']
+ }, {
+ 'function': 'bar',
+ filename: './test/fixtures/stack.js',
+ lineno: 7,
+ pre_context: ['function foo() {', ' bar(\'hey\');', '}', '', 'function bar(a,b,c) {', ' var test=\'yay!\';'],
+ context_line: ' trace();',
+ post_context: ['}', '', 'function trace() {', ' console.log(__stack[1].fun.arguments);', '}', '', 'foo();']
+ }, {
+ 'function': 'foo',
+ filename: './test/fixtures/stack.js',
+ lineno: 2,
+ pre_context: ['function foo() {'],
+ context_line: ' bar(\'hey\');',
+ post_context: ['}', '', 'function bar(a,b,c) {', ' var test=\'yay!\';', ' trace();', '}', '']
+ }, {
+ 'function': 'Object.<anonymous>',
+ filename: './test/fixtures/stack.js',
+ lineno: 14,
+ pre_context: [' trace();', '}', '', 'function trace() {', ' console.log(__stack[1].fun.arguments);', '}', ''],
+ context_line: 'foo();',
+ post_context: ['']
+ }, {
+ '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
+ }];
+ raven.utils.parseStack(stack, function(err, frames){
+ frames.should.eql(expected);
+ done();
});
+ });
- it('should parse all frames correctly', function(done){
- var expected = [{
- 'function': 'trace',
- filename: './test/fixtures/stack.js',
- lineno: 11,
- pre_context: ['', 'function bar(a,b,c) {', ' var test=\'yay!\';', ' trace();', '}', '', 'function trace() {'],
- context_line: ' console.log(__stack[1].fun.arguments);',
- post_context: ['}', '', 'foo();', '']
- }, {
- 'function': 'bar',
- filename: './test/fixtures/stack.js',
- lineno: 7,
- pre_context: ['function foo() {', ' bar(\'hey\');', '}', '', 'function bar(a,b,c) {', ' var test=\'yay!\';'],
- context_line: ' trace();',
- post_context: ['}', '', 'function trace() {', ' console.log(__stack[1].fun.arguments);', '}', '', 'foo();']
- }, {
- 'function': 'foo',
- filename: './test/fixtures/stack.js',
- lineno: 2,
- pre_context: ['function foo() {'],
- context_line: ' bar(\'hey\');',
- post_context: ['}', '', 'function bar(a,b,c) {', ' var test=\'yay!\';', ' trace();', '}', '']
- }, {
- 'function': 'Object.<anonymous>',
- filename: './test/fixtures/stack.js',
- lineno: 14,
- pre_context: [' trace();', '}', '', 'function trace() {', ' console.log(__stack[1].fun.arguments);', '}', ''],
- context_line: 'foo();',
- post_context: ['']
- }, {
- '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
- }];
+ var stacks = glob.sync(__dirname + '/fixtures/stacks/*.txt');
+ var results = glob.sync(__dirname + '/fixtures/stacks/*.json');
+ stacks.forEach(function(stackname, index) {
+ var stack = fs.readFileSync(stackname, 'utf8');
+ var result = require(results[index]);
+ it('should parse stack with '+path.basename(stackname, '.txt').replace(/_/g, ' '), function(done) {
raven.utils.parseStack(stack, function(err, frames){
- frames.should.eql(expected);
+ frames.should.eql(result);
done();
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.