Skip to content

Commit bcfefdf

Browse files
Improved the compareContents() helper function to compare small chunks at a time rather than the whole file. This makes it easier to spot differences
1 parent f494199 commit bcfefdf

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

test/utils/compare-contents.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,28 @@ module.exports = compareContents;
1010
*/
1111
async function compareContents (actualContents, fileName) {
1212
let expectedContents = await readFile(`test/fixtures/modified/${fileName}`, "utf8");
13-
expect(actualContents).to.equal(expectedContents);
13+
14+
// Split both files into separate lines
15+
let actualLines = actualContents.split("\n").filter(Boolean);
16+
let expectedLines = expectedContents.split("\n").filter(Boolean);
17+
18+
let lineCount = Math.max(actualLines.length, expectedLines.length);
19+
let chunkSize = 50;
20+
21+
// Compare each line
22+
for (let i = 0; i < lineCount; i++) {
23+
let actual = actualLines[i];
24+
let expected = expectedLines[i];
25+
26+
// Compare the lines in small chunks, since inlined SVGs can be huuuuuge,
27+
// which makes it hard to see the differences when there are mismatches
28+
let offset = 0;
29+
while (actual.length > offset || expected.length > offset) {
30+
let actaulChunk = actual.slice(offset, offset + chunkSize);
31+
let expectedChunk = expected.slice(offset, offset + chunkSize);
32+
33+
expect(actaulChunk).to.equal(expectedChunk, `Line #${i + 1} does not match line #${i + 1} of ${fileName}`);
34+
offset += chunkSize;
35+
}
36+
}
1437
}

0 commit comments

Comments
 (0)