Skip to content
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: Make location info parser tests work #440

Merged
merged 5 commits into from
Mar 7, 2022
Merged

Conversation

fb55
Copy link
Collaborator

@fb55 fb55 commented Mar 7, 2022

I realised during the original refactor that generateLocationInfoParserTests didn't call some of the functions is was supposed to call. Digging into this now, it turned out that it was calling escapeString on the input before processing anything. That meant we would receive a single long string with all of the document's content, and only assert a single time that the received string matched the input.

Now, we properly walk the tree (depth first, from the deepest node), and test nodes along the way.

#436 was found during this effort.

Other changes necessary to make this work:

  • serializeOuter was updated to serialise any kind of node.
  • Removed null from document type functions (value was never used)
  • BREAKING: Before, we would always add an empty SYSTEM identifier to the data prop of document types of the htmlparser2 adapter. This was removed; ie. <!DOCTYPE html ""> is now <!DOCTYPE html>.

fb55 added 5 commits March 7, 2022 11:23
BREAKING: The serialization of document types stored in the htmlparser2 adapter now no longer has an empty trailing string. Ie. `<!DOCTYPE html "">` is now `<!DOCTYPE html>`.
For some reason, we were escaping the data before. That meant we would only assert once that the received string matched the input.

Now, we properly walk the tree (depth first, from the deepest node), and test nodes along the way.

Requires #436
Otherwise this would be a breaking change

assertNodeLocation(location, serializedNode, html, lines);

// TODO: None of the cases below are ever matched.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the TODO that started this PR.

@@ -113,42 +112,44 @@ export function generateLocationInfoParserTests(
//Then for each node in the tree we run the serializer and compare results with the substring
//obtained via the location info from the expected serialization results.
it(`Location info (Parser) - ${test.name}`, async () => {
const serializerOpts = { treeAdapter };
const html = escapeString(test.data);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the escapeString call that invalidated the test.

@fb55 fb55 changed the title feat: Make location info parser tests work refactor: Make location info parser tests work Mar 7, 2022
@fb55 fb55 merged commit a2c7240 into master Mar 7, 2022
@fb55 fb55 deleted the loc-info-parser-test branch March 7, 2022 14:27
jmbpwtw pushed a commit to jmbpwtw/parse5 that referenced this pull request Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants