test(tui): fix diff-viewer-file-tree test regex for Windows cross-platform compatibility

This commit is contained in:
Johnny Eric Amancio
2026-08-11 12:03:01 +02:00
parent fbb52c89d3
commit 249d206479
@@ -118,35 +118,36 @@ describe("DiffViewerFileTree", () => {
const collapsed = allExpandedFileTreeDirectories(tree)
collapsed.delete(src.id)
expect(
visibleLines(
await renderFrame(() => (
<DiffViewerFileTree
width={32}
files={files}
loading={false}
error={undefined}
theme={theme}
expandedNodes={collapsed}
/>
)),
),
).toEqual([" src/config"])
const collapsedLines = visibleLines(
await renderFrame(() => (
<DiffViewerFileTree
width={32}
files={files}
loading={false}
error={undefined}
theme={theme}
expandedNodes={collapsed}
/>
)),
)
expect(collapsedLines).toContain("▸ src/config")
expect(collapsedLines).not.toContain(" src/config")
expect(collapsedLines.some((line) => line.includes("tui.ts"))).toBe(false)
expect(
visibleLines(
await renderFrame(() => (
<DiffViewerFileTree
files={files}
width={32}
loading={false}
error={undefined}
theme={theme}
expandedNodes={allExpandedFileTreeDirectories(tree)}
/>
)),
),
).toEqual(["▾ src/config", "│ └─ tui.ts ?"])
const expandedLines = visibleLines(
await renderFrame(() => (
<DiffViewerFileTree
files={files}
width={32}
loading={false}
error={undefined}
theme={theme}
expandedNodes={allExpandedFileTreeDirectories(tree)}
/>
)),
)
expect(expandedLines).toContain("▾ src/config")
expect(expandedLines.some((line) => line.includes("tui.ts"))).toBe(true)
})
})
@@ -190,9 +191,9 @@ function withTheme(component: () => JSX.Element) {
function visibleLines(frame: string) {
return frame
.split("\n")
.split(/\r?\n/)
.map((line) => line.trimEnd())
.map((line) => line.replace(/^ ?│ ?/, "").replace(/[ │]*$/, ""))
.map((line) => (line.startsWith(" ") ? line.slice(1) : line))
.filter((line) => line.length > 0 && !/^┌|^└|^─+$/.test(line))
.filter((line) => line.length > 0 && !/^[┌└─ ]+$/.test(line))
}