fix(mermaid): enforced deterministic colorMode during golden test runs
- Pin colorMode to none in golden test suites to prevent nondeterministic ANSI escape sequences. - Normalize render calls across test files to ensure stable output comparison. - Prevent test flakes caused by environment-specific TTY auto-detection in the renderer.
This commit is contained in:
@@ -8,7 +8,13 @@
|
||||
*/
|
||||
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { renderMermaidAscii } from "../../src/vendor/mermaid-ascii/ascii/index";
|
||||
import { type AsciiRenderOptions, renderMermaidAscii as renderRaw } from "../../src/vendor/mermaid-ascii/ascii/index";
|
||||
|
||||
// Pin colorMode so assertions stay deterministic even if a concurrent or leaked
|
||||
// TTY override makes the renderer auto-detect ANSI color.
|
||||
function renderMermaidAscii(text: string, opts: AsciiRenderOptions = {}): string {
|
||||
return renderRaw(text, { colorMode: "none", ...opts });
|
||||
}
|
||||
|
||||
describe("Class Diagram Arrow Directions", () => {
|
||||
// ============================================================================
|
||||
|
||||
@@ -136,6 +136,7 @@ function runGoldenTests(dir: string, useAscii: boolean): void {
|
||||
useAscii,
|
||||
paddingX: tc.paddingX,
|
||||
paddingY: tc.paddingY,
|
||||
colorMode: "none",
|
||||
});
|
||||
|
||||
const normalizedExpected = normalizeWhitespace(tc.expected);
|
||||
@@ -172,20 +173,20 @@ describe("Config behavior", () => {
|
||||
const mermaidInput = "graph LR\nA --> B";
|
||||
|
||||
it("ASCII and Unicode outputs should differ", () => {
|
||||
const asciiOutput = renderMermaidAscii(mermaidInput, { useAscii: true });
|
||||
const unicodeOutput = renderMermaidAscii(mermaidInput, { useAscii: false });
|
||||
const asciiOutput = renderMermaidAscii(mermaidInput, { useAscii: true, colorMode: "none" });
|
||||
const unicodeOutput = renderMermaidAscii(mermaidInput, { useAscii: false, colorMode: "none" });
|
||||
expect(asciiOutput).not.toBe(unicodeOutput);
|
||||
});
|
||||
|
||||
it("ASCII output should not contain Unicode box-drawing characters", () => {
|
||||
const output = renderMermaidAscii(mermaidInput, { useAscii: true });
|
||||
const output = renderMermaidAscii(mermaidInput, { useAscii: true, colorMode: "none" });
|
||||
expect(output).not.toContain("┌");
|
||||
expect(output).not.toContain("─");
|
||||
expect(output).not.toContain("│");
|
||||
});
|
||||
|
||||
it("Unicode output should contain Unicode box-drawing characters", () => {
|
||||
const output = renderMermaidAscii(mermaidInput, { useAscii: false });
|
||||
const output = renderMermaidAscii(mermaidInput, { useAscii: false, colorMode: "none" });
|
||||
const hasUnicode = output.includes("┌") || output.includes("─") || output.includes("│");
|
||||
expect(hasUnicode).toBe(true);
|
||||
});
|
||||
@@ -209,6 +210,7 @@ describe("Diagonal validation", () => {
|
||||
useAscii: true,
|
||||
boxBorderPadding: paddingX,
|
||||
paddingY: paddingY,
|
||||
colorMode: "none",
|
||||
});
|
||||
|
||||
// Check for diagonal characters
|
||||
@@ -228,6 +230,7 @@ describe("Diagonal validation", () => {
|
||||
useAscii: false,
|
||||
boxBorderPadding: paddingX,
|
||||
paddingY: paddingY,
|
||||
colorMode: "none",
|
||||
});
|
||||
|
||||
// Check for diagonal characters
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { renderMermaidAscii } from "../../src/vendor/mermaid-ascii/ascii/index";
|
||||
import { type AsciiRenderOptions, renderMermaidAscii as renderRaw } from "../../src/vendor/mermaid-ascii/ascii/index";
|
||||
|
||||
// Pin colorMode so assertions stay deterministic even if a concurrent or leaked
|
||||
// TTY override makes the renderer auto-detect ANSI color.
|
||||
function renderMermaidAscii(text: string, opts: AsciiRenderOptions = {}): string {
|
||||
return renderRaw(text, { colorMode: "none", ...opts });
|
||||
}
|
||||
|
||||
describe("ASCII multi-line labels", () => {
|
||||
describe("flowchart nodes", () => {
|
||||
|
||||
Reference in New Issue
Block a user