Skip to content

test(source): fix cross-platform path assertion mismatch on Windows #174

Description

@Adityakk9031

Problem

When running the test suite (bun run test) on Windows, packages/leadtype/src/source/source.test.ts fails in the OpenAPI overlay test (createDocsSource > overlays generated OpenAPI pages while keeping authored pages live):

AssertionError: expected 'C:/Users/user/AppData/Local/Temp/lead...' to be 'C:\Users\user\AppData\Local\Temp\lead...' // Object.is equality

- Expected: "C:\Users\user\AppData\Local\Temp\leadtype-source-LinCaf\guide.mdx"
+ Received: "C:/Users/user/AppData/Local/Temp/leadtype-source-LinCaf/guide.mdx"

❯ src/source/source.test.ts:454:37
    452|         throw new Error("Expected authored and generated metadata.");
    453|       }
    454|       expect(authoredMeta.filePath).toBe(authoredPath);
    455|       expect(generatedMeta.filePath).toContain("leadtype-openapi-");
    456|       expect(generatedMeta.filePath.startsWith(contentDir)).toBe(false);

Root Cause

  • createDocsSource() returns metadata whose filePath is normalized to POSIX-style paths (using / separators).
  • In source.test.ts, authoredPath and contentDir are constructed using path.join(), which produces platform-native paths containing \ separators on Windows.
  • The test performs strict string equality (.toBe(authoredPath)) and prefix checks (.startsWith(contentDir)), which fail solely because the path separators differ (/ vs \), even though both paths refer to the same filesystem location.

Solution

Normalize authoredPath and contentDir to POSIX-style paths before performing equality and prefix assertions. For example:

const normalizedAuthoredPath = authoredPath.replaceAll("\\", "/");
const normalizedContentDir = contentDir.replaceAll("\\", "/");

expect(authoredMeta.filePath).toBe(normalizedAuthoredPath);
expect(generatedMeta.filePath.startsWith(normalizedContentDir)).toBe(false);

Alternatively, normalize both sides using path.resolve() or another consistent path normalization strategy prior to comparison. This ensures the test behaves consistently across both Windows and POSIX platforms.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions