-
-
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
Return new assertion with flags copied over instead of this. Fix #791 #799
Return new assertion with flags copied over instead of this. Fix #791 #799
Conversation
@@ -4,7 +4,9 @@ | |||
* MIT Licensed | |||
*/ | |||
|
|||
var chai = require('../../chai'); |
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.
Does this create a circular dependency? Have we done this before? I feel like this might create issues
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.
Currently addMethod
and addProperty
have this too and there's been no issue reported about it. However, I'd like to have more time to check this before giving a confident response.
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.
I'm a bit confused how it's working.
test/bootstrap/index.js
requiresindex.js
index.js
requireslib/chai.js
lib/chai.js
requireslib/chai/utils/index.js
lib/chai/utils/index.js
requireslib/chai/utils/addProperty.js
lib/chai/utils/addProperty.js
requireslib/chai.js
Thus circular dependency. -scratches head-
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.
I think it works because chai.js only sets module.exports
and this file only calls stuff from chai.js inside of the methods, so it all kind of works out eventually.
68a4b4f
to
21df19c
Compare
21df19c
to
4101fdf
Compare
Hello there, While I was working on #799, I discovered that you cannot call `JSON.stringify` on an assertion because o proxify. ```javascript const { expect } = require('chai'); const equal = expect(1).to.equal(1); JSON.stringify(equal); // This will throw Error: Invalid Chai property: toJSON ``
1d05b40
to
fe8f2ee
Compare
I believe that I was creating more confusion than explaining something (at least to myself). IMHO, we should return a new Assertion with flags copied over not only to prevent bugs with |
fe8f2ee
to
c1d5a54
Compare
36dae89
to
1ae0a41
Compare
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.
@vieiralucas Awesome work sir, thank you for doing this! I tested this branch with my work-in-progress on proxifying methods, and it solves the problem I was running into. Yay!
I noticed you added delete
statements to a bunch of existing tests that were adding new properties. I agree that we should make sure every test cleans up after itself. My only suggestion is that we restructure some of these tests so that they clean up after themselves even if they fail. Therefore, we'll need to wrap those tests in describe
blocks and move the cleanup code into after
blocks, as I noticed some of the newer tests already do.
@@ -230,6 +230,8 @@ describe('utilities', function () { | |||
}); | |||
|
|||
expect(expect('foo').result()).to.equal('result'); | |||
|
|||
delete chai.Assertion.prototype.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.
It's a great idea to add this so the test cleans up after itself, but we need it to run the cleanup operation regardless of success or failure. Therefore, I think we should wrap this test in a describe
with an after
function to contain the cleanup activities.
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.
Of course, you're absolutely right. Thanks for noticing.
I'll make the changes.
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.
Done
@@ -273,6 +275,9 @@ describe('utilities', function () { | |||
|
|||
var anotherAssertion = expect([1, 2, 3]).to.have.a.lengthOf(3).and.to.be.ok; | |||
expect(anotherAssertion.length.constructor).to.equal(assertionConstructor); | |||
|
|||
delete chai.Assertion.prototype.returnNewAssertion; | |||
delete chai.Assertion.prototype.checkFlags; |
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.
Same thing here; cleanup steps should be in an after
function.
@@ -403,6 +444,8 @@ describe('utilities', function () { | |||
|
|||
var assert = expect('chai').to.be.tea; | |||
expect(assert.__flags.tea).to.equal('chai'); | |||
|
|||
delete chai.Assertion.prototype.tea; |
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.
Same thing here; cleanup steps should be in an after
function.
@@ -446,6 +489,9 @@ describe('utilities', function () { | |||
|
|||
expect(expect([1, 2, 3]).be).to.be.an.instanceOf(assertionConstructor); | |||
expect(expect([1, 2, 3]).thing).to.be.an.instanceOf(assertionConstructor); | |||
|
|||
delete chai.Assertion.prototype.thing; | |||
delete chai.Assertion.prototype.checkFlags; |
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.
Same thing here; cleanup steps should be in an after
function.
@@ -456,11 +502,16 @@ describe('utilities', function () { | |||
}); | |||
|
|||
expect(expect('foo').result).to.equal('result'); | |||
|
|||
delete chai.Assertion.prototype.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.
Same thing here; cleanup steps should be in an after
function.
@@ -477,6 +528,8 @@ describe('utilities', function () { | |||
expect(matcha.__flags.tea).to.equal('matcha'); | |||
var assert = expect('something').to.be.tea; | |||
expect(assert.__flags.tea).to.equal('chai'); | |||
|
|||
delete chai.Assertion.prototype.tea; |
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.
Same thing here; cleanup steps should be in an after
function.
@@ -489,6 +542,8 @@ describe('utilities', function () { | |||
}); | |||
|
|||
expect(expect('foo').result).to.equal('result'); | |||
|
|||
delete chai.Assertion.prototype.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.
Same thing here; cleanup steps should be in an after
function.
@@ -762,46 +866,156 @@ describe('utilities', function () { | |||
expect(obj).x.to.be.ok; | |||
expect(obj).to.have.property('__x', 'X!'); | |||
}) | |||
|
|||
delete chai.Assertion.prototype.x; |
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.
Same thing here; cleanup steps should be in an after
function.
expect(expect('bar').foo('bar')).to.be.an.instanceOf(assertionConstructor); | ||
|
||
delete chai.Assertion.prototype.foo; | ||
delete chai.Assertion.prototype.checkFlags; |
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.
Same thing here; cleanup steps should be in an after
function.
… block even if they fail
@vieiralucas Thanks for the extra effort refactoring the tests to clean up after themselves. Personally, I think the whole test suite could use a refactoring to be better organized and labeled, and only have one assertion per test, but that's a future battle :D Anyway, this LGTM! @keithamus @lucasfcosta? Edit: I think the LGTM feature is a little wonky since github added the "Review" system. I haven't done much reading on the Review system. Can it be configured to require multiple approved reviews instead of just one? If so, it could probably replace LGTM altogether. |
@meeber I totally agree with your considerations about the LGTM feature, it would be perfect if we could require more than one review for PR, however, if this is not possible, can we disable this and continue using only LGTM? Also, this LGTM! |
@meeber @lucasfcosta I enabled the github review to see how well it worked. I've disabled it for now, and we can keep using LGTM. When it's configurable for N number of reviewers then we'll look at re-enabling I think 😄 |
Based on my limited interactions with it, I think the builtin review tool has a lot of potential. I particularly like being able to group a bunch of comments together before submitting them during a review. |
Yes, I think ultimately it's better than LGTM (for our use case) but also much less configurable - namely the number of required reviewers, which becomes a deal breaker (unless we want to lower the number of required viewers to 1 😆). |
Personally I did not find a way to tell if the changes requested were already made. Maybe I'm just a hater 😸 |
@vieiralucas @meeber @keithamus Apparently this makes the build fail, I have no idea how this is possible since the Travis check passed. Any ideas about how this happened? Shouldn't the Travis check be the same as the builds? |
Ahh sadly they're not - because the saucelabs tests only run on master (because if they were to run on pull requests, we'd risk exposing our saucelabs tokens to malicious PR code). |
Not very familiarized with saucelabs, but I found this IE 10.0.0 (Windows 7 0.0.0) utilities overwriteChainableMethod should return a new assertion with flags copied over FAILED |
You should try to run the tests in IE10 locally, see why it is failing. |
Currently downloading IE10 VM. |
Well... WHY IS THAT SO HARD MICROSOFT PLS |
Hello!
This PR addresses #791.
overwriteProperty
overwriteMethod
addChainableMethod
overwriteChainableMethod