astryx
astryx copied to clipboard
[Bug] Test suite fails on Windows due to path separator and URL.pathname issues
Description
Several tests in the Astryx test suite fail when run on Windows due to Windows-specific path handling differences.
Affected Tests
packages/core/src/FormLayout/FormLayout.test.tsx— Snapshot serializer causesMaximum call stack size exceededdue to missing recursion guardpackages/core/src/theme/derivedVarRegistry.test.ts— NTFS case-insensitive filesystem causestheme/directory to matchTheme.doc.mjs, producing false--border-widthundocumented var failurespackages/cli/src/commands/component-resolution.test.mjs— File path assertions use/regex but Windows paths use\packages/cli/src/commands/doctor.test.mjs—new URL(import.meta.url).pathnamereturns/C:/...on Windows (leading slash before drive letter), causingmkdtempto fail withENOENT
Root Causes
URL.prototype.pathnameon Windows prepends a/before the drive letter (e.g./C:/Users/...). UsefileURLToPath(import.meta.url)fromnode:urlinstead.- NTFS is case-insensitive, so
existsSync('theme/Theme.doc.mjs')returnstrueeven though the directory isthemenotTheme. UsereaddirSync+Array.includesfor case-sensitive checks. path.join()uses\on Windows. File path regex assertions need[/\\]instead of/.- The Vitest snapshot serializer's
test()function must check a re-entrance guard to avoid infinite recursion whenprinter()callstest()again on child nodes.
Environment
- OS: Windows 11
- Node: v22
- Package manager: pnpm
Proposed Fix
I have a fix ready — will submit a PR referencing this issue.
Reproduction
- Clone the repo on Windows:
git clone https://github.com/facebook/astryx - Install dependencies:
pnpm install - Run the test suite:
npx pnpm vitest run packages/cli packages/core/src/FormLayout packages/core/src/theme/derivedVarRegistry.test.ts - Observe failures on Windows
XDS Version
@astryxdesign/[email protected]
I've submitted a fix for this in PR #3234 The PR addresses all four root causes described above:
- Snapshot serializer recursion guard (
setup.ts) - Case-sensitive doc file check (
derivedVarRegistry.test.ts) fileURLToPathinstead ofURL.pathname(doctor.test.mjs)- Forward-slash normalization in CLI path handling
All previously-failing tests now pass on Windows. Happy to make any changes based on review feedback!