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
Port custom assertions to mostly strict assertions #89
Conversation
f935823
to
b3ee11a
Compare
Thx for the time invested. From the feedback I got in my first attmept in #51 to do something similar I learned that the owners prefer to keep those tests as they are. I also opened #72 to discuss how to handle testing in the future. But since I'm only a contributor, I hope the owners will also add their perspective to the mix. |
.editorconfig
Outdated
# http://EditorConfig.org | ||
root = true | ||
|
||
[*.js] | ||
charset = utf-8 | ||
indent_style = tab | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true |
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.
Personally, I believe this is a good idea, but should be added in a separate PR where just this topic can be discussed. See #29
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.
Oops, yes of course
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.
Yes please revert 894522a, thanks.
@karfau I don't think having the the tests be dependent on the setting of a variable is a very good idea... I would assume tests cover every situation by default (or at at least as much as the execution environment can do). But also for the vast majority of the tests, I don't think that makes any sense. If you're testing the length of an array, or the contents of a string, there's no reason to do that non-strict. Which assertions specifically need the old behavior? |
@awwright did you read the conversation in #51 (and potentially follow up #59 ) that lead to the creation of those assertions? I'm not really willing to repeat the arguments stated there (, also since they are not mine). I agree that there are many tests that are not very useful, redundant or hard to maintain. But I would rather invest into a properly structured test suite using modern tooling, that makes the vow's test suite obsolete (by "covering all it covers" and more), instead of "tweaking" the vows test suite and risking that we cover less afterwards. But as I said, it's just my personal preference. |
Hi I am reviewing the changes right now. I would actually favor converting the existing custom assertions to strict assertions, assuming that it does not affect testing speed too aversely. The testing speed is pretty important for the Stryker mutation testing that is already in place. I would also not mind if we would port the existing tests from vows to something more universally accepted such as Jest. (I would actually not favor Mocha, but that is personal preference). I would definitely agree with @karfau that the existing tests are pretty bad, and we may need to replace them all over time, as discussed in #72. When the custom assert function was introduced in PR #59, my understanding was that this was only a temporary solution to restore the existing test coverage. I did also take the liberty to update the title. In short, I do think this is a step in the right direction, even if it is not where we really want to be in the end. |
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.
In general I think these changes are really awesome. I did leave quite a few comments.
My one major criticism is mixing formatting changes into lines that would otherwise not need to be updated.
I am fine with using "use strict" in the test files, lib should be updated in a separate PR.
test/dom/attr.vows.js
Outdated
//not standart | ||
// root.firstChild.setAttributeNode(root.attributes[0]); | ||
// assert(root.attributes.length, 0); | ||
// assert.strictEqual(root.attributes.length, 0); |
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.
What should we do with these lines? Any ideas?
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.
Comment them, eventually? Idk what exactly, but if they do get uncommented, this will definitely want to use strictEqual.
.editorconfig
Outdated
# http://EditorConfig.org | ||
root = true | ||
|
||
[*.js] | ||
charset = utf-8 | ||
indent_style = tab | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true |
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.
Yes please revert 894522a, thanks.
test/dom/clone.vows.js
Outdated
'clone': function () { | ||
var doc1 = new DOMParser().parseFromString("<doc1 attr1='1' attr2='a2'>text1<child>text2</child></doc1>",'text/xml') | ||
'clone': function () { | ||
var doc1 = new DOMParser().parseFromString("<doc1 attr1='1' attr2='a2'>text1<child>text2</child></doc1>",'text/xml'); |
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 there is no reason to do formatting change to lines like this at the same time as we convert the assertions. This kind of formatting change makes it harder to see the actual impact of this conversion.
var doc1 = new DOMParser().parseFromString("<doc1 attr1='1' attr2='a2'>text1<child>text2</child></doc1>",'text/xml'); | |
var doc1 = new DOMParser().parseFromString("<doc1 attr1='1' attr2='a2'>text1<child>text2</child></doc1>",'text/xml') |
test/dom/clone.vows.js
Outdated
var n =doc1.cloneNode(true); | ||
assert(n, doc1s); |
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 would rather we revert these changes.
var n =doc1.cloneNode(true); | |
assert(n, doc1s); | |
var n =doc1.cloneNode(true) | |
assert(n, doc1s) |
test/error/xml-error.vows.js
Outdated
assert(errors.length, 2,"invalid xml attribute(miss qute)") | ||
assert(dom+'', '<img attr="1" xmlns="http://www.w3.org/1999/xhtml"/>') | ||
assert.strictEqual(errors.length, 2,"invalid xml attribute(miss qute)") | ||
assert.strictEqual(dom+'', '<img attr="1" xmlns="http://www.w3.org/1999/xhtml"/>') |
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 wonder if we should consider this kind of change as well:
assert.strictEqual(dom+'', '<img attr="1" xmlns="http://www.w3.org/1999/xhtml"/>') | |
assert.strictEqual(dom.toString(), '<img attr="1" xmlns="http://www.w3.org/1999/xhtml"/>') |
test/parse/locator.vows.js
Outdated
@@ -27,7 +29,7 @@ var xml= [ | |||
var parser = new DOMParser({locator:{}}); | |||
var doc = parser.parseFromString(xml, 'text/xml'); | |||
var trans = doc.getElementsByTagName('transition')[0]; | |||
assert.equal(trans.lineNumber , 10)//,''+trans+trans.lineNumber+'/'+trans.parentNode.previousSibling.previousSibling.lineNumber) | |||
assert.strictEqual(trans.lineNumber, 10);//,''+trans+trans.lineNumber+'/'+trans.parentNode.previousSibling.previousSibling.lineNumber) |
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 the commented code indicate another TODO item here?
test/parse/locator.vows.js
Outdated
@@ -71,6 +73,6 @@ var xml= [ | |||
var doc = parser.parseFromString('<root>\n\t<err</root>', 'text/html'); | |||
var root = doc.documentElement; | |||
var textNode = root.firstChild; | |||
assert.isTrue(/\n@#\[line\:2,col\:2\]/.test(error.join(' ')),'line,col must record:'+JSON.stringify(error)); | |||
assert(/\n@#\[line\:2,col\:2\]/.test(error.join(' ')),'line,col must record:'+JSON.stringify(error)); |
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.
A bit hard to read & understand, how about this idea:
assert(/\n@#\[line\:2,col\:2\]/.test(error.join(' ')),'line,col must record:'+JSON.stringify(error)); | |
assert(/\n@#\[line\:2,col\:2\]/.test(error.join(' ')), 'line,col must record: ' + JSON.stringify(error)); |
or maybe even this:
assert(/\n@#\[line\:2,col\:2\]/.test(error.join(' ')),'line,col must record:'+JSON.stringify(error)); | |
assert(/\n@#\[line\:2,col\:2\]/.test(error.join(' ')), `line,col must record: ${JSON.stringify(error)}`); |
or one step further, like what I think Prettier would do:
assert(/\n@#\[line\:2,col\:2\]/.test(error.join(' ')),'line,col must record:'+JSON.stringify(error)); | |
assert( | |
/\n@#\[line\:2,col\:2\]/.test(error.join(' ')), | |
`line,col must record: ${JSON.stringify(error)}` | |
); |
test/parse/namespace.vows.js
Outdated
assert.strictEqual(root.namespaceURI, 'http://test.com'); | ||
assert.strictEqual(root.lookupNamespaceURI(''), 'http://test.com'); | ||
assert.strictEqual(root.firstChild.namespaceURI, 'http://test.com'); | ||
assert.strictEqual(root.firstChild.lookupNamespaceURI(''), 'http://test.com'); |
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.
fix alignment of this line?
}, | ||
}).export(module); |
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 these should be reverted for now:
}, | |
}).export(module); | |
} | |
}).export(module) |
@brodybits Wrt the rest of the review... It seems to me maybe we should do a PR to normalize the whitespace first, then I can apply these fixes after that. Thoughts? |
Yes. I think it would be easier to get the lint in place first. Thanks. |
b3ee11a
to
3081e08
Compare
I rebased over the updates from #121. |
I have updated the title, and I pushed a bunch of updates to give us a green build and make some improvements. I can think of a couple followup items:
|
8c80c8c
to
be92b95
Compare
be92b95
to
ce6f144
Compare
@awwright Are you still investing time to porting the assertions to strict ones? Or did I misunderstand you @brodybits ? |
I could go either way. I would not mind a multi-step approach like this:
|
I was proposing that, after the code is formatted, to first port the assertion calls (as in this PR). That would make changing over the test runner a minimal amount of effort. Then working on fixing tests and adding coverage. ...it seems the test runner has mostly been converted, though. I favor using |
Another thing is that I had spent several hours getting this PR to run with a green build, and find it very unfortunate to see my work thrown away here. (I do have my work saved in my own fork though.) At this point I am thinking to go ahead with PR #123 with the Prettier reformatting and then convert the custom assertions directly into Jest-style |
@brodybits I'm sorry, when was that? Was this PR introducing build errors? |
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.
@brodybits Well, OK, but I'm trying to figure out what changes you're talking about, do you mean a PR? I'm curious which errors you're referring to. |
I had pushed the changes to your Unfortunately I don't have much time to explain the errors that I had fixed, due to some other priorities. In any case, your contributions did help us get the code cleaner. You should be able to see that you have co-authorship credit on some recent changes that we made. |
I mean, I'm not sure what else to say... GitHub shows my rebases and commits that I pushed, and I see you mentioning this from other PRs, but it doesn't show any commits pushed to my branch. |
I'd like to start chipping away at converting the test suite, I've converted a Vows suite to Mocha before. This one looks pretty straightforward, actually.
I think the first logical step here is to start with the assertions themselves, and use the Node.js core library and only the builtin functions.
In particular,
assert.isTrue
is a monkey-patch by Vows. I found most all the tests can useassert.strictEqual
. There's a few that test if an object is cast to a string, these useassert.equal
. There's two more that I think don't meet the DOM standard if you use===
, these useassert.equal
and are marked with a FIXME.