Skip to content

Commit d88e5b0

Browse files
authored
fix: Update end index for text events (#621)
1 parent be1e9ba commit d88e5b0

7 files changed

Lines changed: 98 additions & 63 deletions

File tree

package-lock.json

Lines changed: 82 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"@typescript-eslint/parser": "^4.29.3",
4343
"eslint": "^7.32.0",
4444
"eslint-config-prettier": "^8.1.0",
45-
"htmlparser2": "^7.0.0",
45+
"htmlparser2": "^7.1.1",
4646
"jest": "^27.1.0",
4747
"prettier": "^2.0.5",
4848
"ts-jest": "^27.0.5",

src/__fixtures__/24-with-start-indices.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "withStartIndices adds correct startIndex properties",
33
"options": { "withStartIndices": true },
4-
"streaming": false,
54
"html": "<!DOCTYPE html> <html> <title>The Title</title> <body class='foo'>Hello world <p></p></body> <!-- the comment --> </html> ",
65
"expected": [
76
{

src/__fixtures__/25-with-end-indices.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "withEndIndices adds correct endIndex properties",
33
"options": { "withEndIndices": true },
4-
"streaming": false,
54
"html": "<!DOCTYPE html> <html> <title>The Title</title> <body class='foo'>Hello world <p></p></body> <!-- the comment --> </html> ",
65
"expected": [
76
{

src/index.spec.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ describe("DomHandler", () => {
1010
.filter((name) => name.endsWith(".json")) // Only allow .json files
1111
.map((name) => resolve(basePath, name))
1212
.map(require)
13-
.forEach(({ name, html, options = {}, streaming = true, expected }) =>
13+
.forEach(({ name, html, options = {}, expected }) =>
1414
test(name, () => {
15-
const result = parse(html, options, streaming);
15+
const result = parse(html, options);
1616

1717
compare(result, expected);
1818
})
@@ -21,8 +21,7 @@ describe("DomHandler", () => {
2121

2222
function parse(
2323
data: string,
24-
options: DomHandlerOptions & ParserOptions,
25-
streaming: boolean
24+
options: DomHandlerOptions & ParserOptions
2625
): Node[] {
2726
const results: Node[][] = [];
2827

@@ -34,21 +33,17 @@ function parse(
3433
const parser = new Parser(handler, options);
3534

3635
// First, try to run the fixture via chunks
37-
if (streaming) {
38-
for (let i = 0; i < data.length; i++) {
39-
parser.write(data.charAt(i));
40-
}
41-
42-
parser.done();
36+
for (let i = 0; i < data.length; i++) {
37+
parser.write(data.charAt(i));
4338
}
4439

40+
parser.done();
41+
4542
// Then parse everything
4643
parser.parseComplete(data);
4744

48-
if (streaming) {
49-
// Ensure streaming doesn't change anything.
50-
expect(results[0]).toEqual(results[1]);
51-
}
45+
// Ensure streaming doesn't change anything.
46+
expect(results[0]).toEqual(results[1]);
5247

5348
return results[0];
5449
}

0 commit comments

Comments
 (0)