(file: string)
| 56 | } |
| 57 | |
| 58 | async function expectDiff(file: string) { |
| 59 | const testFilePath = path.join(__dirname, "test-examples", file + ".diff"); |
| 60 | const testFileContents = fs.readFileSync(testFilePath, "utf-8"); |
| 61 | const [oldText, newText, expectedDiff] = testFileContents |
| 62 | .split("\n---\n") |
| 63 | .map((s) => s.replace(/^\n+/, "").trimEnd()); |
| 64 | const oldLines = oldText.split("\n"); |
| 65 | const newLines = newText.split("\n"); |
| 66 | const { streamDiffs, myersDiffs } = await collectDiffs(oldLines, newLines); |
| 67 | const displayedDiff = displayDiff(streamDiffs); |
| 68 | |
| 69 | if (!expectedDiff || expectedDiff.trim() === "") { |
| 70 | console.log( |
| 71 | "Expected diff was empty. Writing computed diff to the test file", |
| 72 | ); |
| 73 | fs.writeFileSync( |
| 74 | testFilePath, |
| 75 | `${oldText}\n\n---\n\n${newText}\n\n---\n\n${displayedDiff}`, |
| 76 | ); |
| 77 | |
| 78 | throw new Error("Expected diff is empty"); |
| 79 | } |
| 80 | |
| 81 | expect(displayedDiff).toEqual(expectedDiff); |
| 82 | } |
| 83 | |
| 84 | // We use a longer `)` string here to not get |
| 85 | // caught by the fuzzy matcher |
no test coverage detected