Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Update utils.js #118

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ function parseStack(err, cb) {
lineno: line.getLineNumber(),
'function': getFunction(line),
}, isInternal = line.isNative() ||
(frame.filename[0] !== '/' &&
frame.filename[0] !== '.');
(frame.filename[0] !== path.sep &&
frame.filename[0] !== '.' &&
frame.filename.indexOf(':\\') !== 1);

// in_app is all that's not an internal Node function or a module within node_modules
frame.in_app = !isInternal && !~frame.filename.indexOf('node_modules/');
Expand Down
17 changes: 17 additions & 0 deletions test/raven.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@ describe('raven.utils', function() {
parseStack([], callback);
parseStack([{lol: 1}], callback);
});

it('should extract context from last stack line', function(done){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this test testing the new code that was just added? I don't see anything about looking for :\ in the frame or a \ at all. Just a bit confused on what this is attempting to test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, actually the test does much more than that. Here it is what my point was when writing it:

  1. A real js exception is caused on purpose inside the try block
  2. It gets passed to parseStack along with a custom callback knowing that the callback gets invoked with an array of all the processed frames once the whole stack is parsed.
  3. As the frames array gets reversed inside parseStack I know that the last frame corresponds to the file where the exception was generated and that the exception isn't inside native code.
  4. I verify that the frame has properties: pre_context, context_line and post_context which is valid for non-internal stack lines only.
    The test was failing without the change as inside parseStack the following was always resolving to true:
isInternal = line.isNative() || (frame.filename[0] !== '/' && frame.filename[0] !== '.');

and the frame was never having pre_context, context_line and post_context

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But to touch the branch that you added, that mandates that this test is run on Windows, correct? If the test is run on anything non-windows, your code branches never get touched. So I agree the test is useful, we just need to mock it to force a windows style frame.filename so that we can assert it does the right thing. Especially since all testing is run in Linux or OSX.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I will think about forcing a windows-style frame.filename and will commit again once ready. But that'll be tomorrow as here in Europe it is beer time now.

var parseStack = raven.utils.parseStack;
var callback = function(frames) {
var frame = frames.pop();
frame.pre_context.should.be.an.instanceOf(Array);
frame.context_line.should.be.type('string');
frame.context_line.should.endWith('undeclared_function();');
frame.post_context.should.be.an.instanceOf(Array);
done();
};
try {
undeclared_function();
} catch(e) {
parseStack(e, callback);
}
});
});

describe('#getCulprit()', function(){
Expand Down