-
-
Notifications
You must be signed in to change notification settings - Fork 239
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
refactor: Improve code coverage #517
Conversation
@@ -17,9 +17,6 @@ export function parseChunked<T extends TreeAdapterTypeMap>( | |||
parserStream.parser.tokenizer.preprocessor.bufferWaterline = 8; | |||
|
|||
for (let i = 0; i < chunks.length - 1; i++) { | |||
if (typeof chunks[i] !== 'string') { |
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.
TypeScript validates this, we don't need this check.
@@ -317,6 +317,8 @@ generateTestsForEachTreeAdapter('open-element-stack', (treeAdapter) => { | |||
test('Has numbered header in scope', () => { | |||
const stack = new OpenElementStack(treeAdapter.createDocument(), treeAdapter, stackHandler); | |||
|
|||
assert.ok(stack.hasNumberedHeaderInScope()); |
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.
The empty states won't be used in the parser, but we can test them 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.
🤔 Why does hasNumberedHeaderInScope
exist if parse5 doesn’t use it? Should we deprecate it and remove it in a major then?
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.
If these functions are used, can we instead add unit tests (input/output) of parsing behavior that depends on the result of these functions?
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.
hasNumberedHeaderInScope
is used by the parser. The only thing that the parser cannot reach is the default return value, eg. for an empty stack.
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.
You mean this early return
return true; |
return true; |
Could you change that early return to a break in that case, to fix the coverage?
Not sure about the algorithm: but it seems off that the default for that function i true
? I’d expect, with such a function name, to exit early with true
, and otherwise return false
?
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.
The relevant part of the spec is https://html.spec.whatwg.org/multipage/parsing.html#has-an-element-in-scope
The algorithm explicitly doesn't consider the possibility of an empty stack:
This will never fail, since the loop will always terminate in the previous step if the top of the stack — an html element — is reached.
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.
Then I recommend using a c8 ignore
(or similar), with this as an explanation:
/* Note: the algorithm <link> never fails */
/* c8 ignore next 123 */
|
||
await finished(parser); | ||
|
||
assert.ok(foundText); |
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.
probably a good idea to use an assert.equal
instead, to check that the actual result makes sense and not, say, 'null'
for example?
@@ -317,6 +317,8 @@ generateTestsForEachTreeAdapter('open-element-stack', (treeAdapter) => { | |||
test('Has numbered header in scope', () => { | |||
const stack = new OpenElementStack(treeAdapter.createDocument(), treeAdapter, stackHandler); | |||
|
|||
assert.ok(stack.hasNumberedHeaderInScope()); |
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.
🤔 Why does hasNumberedHeaderInScope
exist if parse5 doesn’t use it? Should we deprecate it and remove it in a major then?
@@ -317,6 +317,8 @@ generateTestsForEachTreeAdapter('open-element-stack', (treeAdapter) => { | |||
test('Has numbered header in scope', () => { | |||
const stack = new OpenElementStack(treeAdapter.createDocument(), treeAdapter, stackHandler); | |||
|
|||
assert.ok(stack.hasNumberedHeaderInScope()); |
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.
If these functions are used, can we instead add unit tests (input/output) of parsing behavior that depends on the result of these functions?
Removes all low-hanging fruit for #515