astryx icon indicating copy to clipboard operation
astryx copied to clipboard

[Bug] Test suite fails on Windows due to path separator and URL.pathname issues

Open GeekLuffy opened this issue 5 months ago • 1 comments

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 causes Maximum call stack size exceeded due to missing recursion guard
  • packages/core/src/theme/derivedVarRegistry.test.ts — NTFS case-insensitive filesystem causes theme/ directory to match Theme.doc.mjs, producing false --border-width undocumented var failures
  • packages/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).pathname returns /C:/... on Windows (leading slash before drive letter), causing mkdtemp to fail with ENOENT

Root Causes

  1. URL.prototype.pathname on Windows prepends a / before the drive letter (e.g. /C:/Users/...). Use fileURLToPath(import.meta.url) from node:url instead.
  2. NTFS is case-insensitive, so existsSync('theme/Theme.doc.mjs') returns true even though the directory is theme not Theme. Use readdirSync + Array.includes for case-sensitive checks.
  3. path.join() uses \ on Windows. File path regex assertions need [/\\] instead of /.
  4. The Vitest snapshot serializer's test() function must check a re-entrance guard to avoid infinite recursion when printer() calls test() 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

  1. Clone the repo on Windows: git clone https://github.com/facebook/astryx
  2. Install dependencies: pnpm install
  3. Run the test suite: npx pnpm vitest run packages/cli packages/core/src/FormLayout packages/core/src/theme/derivedVarRegistry.test.ts
  4. Observe failures on Windows

XDS Version

@astryxdesign/[email protected]

GeekLuffy avatar Jun 29 '26 10:06 GeekLuffy

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)
  • fileURLToPath instead of URL.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!

GeekLuffy avatar Jun 29 '26 10:06 GeekLuffy