MCPcopy
hub / github.com/continuedev/continue / expectDiff

Function expectDiff

core/diff/streamDiff.vitest.ts:58–82  ·  view source on GitHub ↗
(file: string)

Source from the content-addressed store, hash-verified

56}
57
58async 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

Callers 1

Calls 4

collectDiffsFunction · 0.70
displayDiffFunction · 0.70
logMethod · 0.65
replaceMethod · 0.45

Tested by

no test coverage detected