-
-
Notifications
You must be signed in to change notification settings - Fork 698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix stacktraces for overwritten properties and methods #661
Changes from all commits
be8189c
cf378e4
cceadf6
1d8c3d9
c4f522f
58532d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
*/ | ||
|
||
var chai = require('../../chai'); | ||
var config = require('../config'); | ||
var flag = require('./flag'); | ||
var transferFlags = require('./transferFlags'); | ||
|
||
|
@@ -40,8 +39,9 @@ module.exports = function (ctx, name, getter) { | |
|
||
Object.defineProperty(ctx, name, | ||
{ get: function addProperty() { | ||
var keep_ssfi = flag(this, 'keep_ssfi'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also explain why we need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imagine expect(true).to.be.false with false overwritten:
but actually that last part shouldn't happen because you don't want the _super in the stack trace. setting keep_ssfi during the _super prevents that from happening. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we test if Tests are okay now, but maybe we could have this too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, great idea 👍 💯 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lucasfcosta but sure I understand what you meant? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Turbo87, sorry but I didn't understand what you just said :( Tests for this should be similar to what we already have, we just need to overwrite the property and them check the stack trace to make sure it does not include that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. damn autocorrect... that was "not sure I understand what you meant" 😉 |
||
var old_ssfi = flag(this, 'ssfi'); | ||
if (old_ssfi && config.includeStack === false) | ||
if (!keep_ssfi && old_ssfi) | ||
flag(this, 'ssfi', addProperty); | ||
|
||
var result = getter.call(this); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
* MIT Licensed | ||
*/ | ||
|
||
var flag = require('./flag'); | ||
|
||
/** | ||
* ### overwriteMethod (ctx, name, fn) | ||
* | ||
|
@@ -46,7 +48,15 @@ module.exports = function (ctx, name, method) { | |
_super = _method; | ||
|
||
ctx[name] = function () { | ||
var keep_ssfi = flag(this, 'keep_ssfi'); | ||
var old_ssfi = flag(this, 'ssfi'); | ||
if (!keep_ssfi && old_ssfi) | ||
flag(this, 'ssfi', ctx[name]); | ||
|
||
flag(this, 'keep_ssfi', true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @Turbo87, I just want to confirm I understood the whole thing here: Whenever you overwrite a method you set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correct |
||
var result = method(_super).apply(this, arguments); | ||
flag(this, 'keep_ssfi', false); | ||
|
||
return result === undefined ? this : result; | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please explain why you've removed the
config.includeStack
part here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That flag is already checked in the assert() method and checking it here has no real benefit aside from making the logic more complicated