Skip to content

chore(internal): Use memfs for project.ts test#555

Merged
Tobbe merged 3 commits intomainfrom
tobbe-internal-chore-memfs-project
Nov 22, 2025
Merged

chore(internal): Use memfs for project.ts test#555
Tobbe merged 3 commits intomainfrom
tobbe-internal-chore-memfs-project

Conversation

@Tobbe
Copy link
Copy Markdown
Member

@Tobbe Tobbe commented Nov 22, 2025

Use memfs to mock the filesystem for faster tests, and to not rely on the global test fixtures

@netlify
Copy link
Copy Markdown

netlify Bot commented Nov 22, 2025

Deploy Preview for cedarjs canceled.

Name Link
🔨 Latest commit 47a8fcf
🔍 Latest deploy log https://app.netlify.com/projects/cedarjs/deploys/6922111b2d570e0008da5d73

@github-actions github-actions Bot added this to the chore milestone Nov 22, 2025
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Nov 22, 2025

Greptile Overview

Greptile Summary

Refactored test from using real filesystem fixtures to memfs virtual filesystem, but implementation has critical bugs that will cause tests to fail.

Key Issues

  • Missing process.env.RWJS_CWD setup: Both test cases don't set the RWJS_CWD environment variable, causing getConfigPath() to search the real filesystem instead of the mocked memfs virtual filesystem
  • Incomplete virtual filesystem: Missing required files (web/src/Routes.*, web/vite.config.*) that getPaths() expects via resolveFile() calls

Why This Matters

The test flow is: getTsConfigs()getPaths()getConfigPath()findUp('redwood.toml', process.env.RWJS_CWD ?? process.cwd()). Without setting RWJS_CWD = '/', the code searches the real filesystem from the actual cwd, completely bypassing the memfs mock.

Reference implementation: packages/cli-helpers/src/lib/__tests__/project.addTomlSetting.test.ts:15-21 shows the correct pattern of setting RWJS_CWD before using memfs.

Confidence Score: 0/5

  • This PR contains critical bugs that will cause test failures - tests cannot work without setting process.env.RWJS_CWD
  • Score 0 reflects that the tests will definitively fail in their current state. The missing process.env.RWJS_CWD = '/' setup means the code will search the real filesystem instead of the mocked memfs, causing getConfigPath() to fail when it cannot find redwood.toml. This is a fundamental implementation issue, not a minor oversight.
  • packages/internal/src/__tests__/project.test.ts - both test cases need process.env.RWJS_CWD = '/' added and additional virtual filesystem files to work correctly

Important Files Changed

File Analysis

Filename Score Overview
packages/internal/src/tests/project.test.ts 1/5 refactored test to use memfs but missing critical setup - tests will fail without process.env.RWJS_CWD = '/' and required virtual files

Sequence Diagram

sequenceDiagram
    participant Test as Test Suite
    participant Vitest as Vitest
    participant Memfs as memfs (vol)
    participant FS as fs/node:fs
    participant GetTsConfigs as getTsConfigs()
    participant GetPaths as getPaths()
    participant GetConfigPath as getConfigPath()
    participant FindUp as findUp()

    Test->>Vitest: vi.mock('fs', memfs)
    Test->>Vitest: vi.mock('node:fs', memfs)
    Test->>Memfs: vol.fromNestedJSON({...}, '/')
    Note over Memfs: Creates virtual filesystem at root
    
    Test->>GetTsConfigs: Call getTsConfigs()
    GetTsConfigs->>GetPaths: Call getPaths()
    GetPaths->>GetConfigPath: Call getConfigPath()
    
    Note over GetConfigPath: Uses process.env.RWJS_CWD ?? process.cwd()
    Note over GetConfigPath,FindUp: ⚠️ BUG: RWJS_CWD not set,<br/>uses real filesystem cwd
    
    GetConfigPath->>FindUp: findUp('redwood.toml', process.cwd())
    FindUp->>FS: fs.existsSync(realCwd + '/redwood.toml')
    Note over FS: Checks REAL filesystem,<br/>not memfs virtual filesystem
    
    FS-->>FindUp: false (not found in real fs)
    FindUp-->>GetConfigPath: null
    GetConfigPath-->>GetPaths: throws Error
    GetPaths-->>GetTsConfigs: Error propagates
    GetTsConfigs-->>Test: ❌ Test fails
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

Comment thread packages/internal/src/__tests__/project.test.ts
Comment thread packages/internal/src/__tests__/project.test.ts
Comment thread packages/internal/src/__tests__/project.test.ts
@Tobbe Tobbe merged commit d861c96 into main Nov 22, 2025
39 checks passed
@Tobbe Tobbe deleted the tobbe-internal-chore-memfs-project branch November 22, 2025 20:03
@Tobbe Tobbe modified the milestones: chore, v1.1.0 Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant