-
-
Notifications
You must be signed in to change notification settings - Fork 381
Description
Describe the bug.
While running and reviewing unit tests in apps/generator, I noticed that tests for utils.exists() rely on the real filesystem instead of mocked behavior.
Specifically, in test/utils.test.js:
const exists = await utils.exists(${process.cwd()}/package.json);
expect(exists).toBeTruthy();
This test depends on:
the presence of package.json at runtime
the current working directory
filesystem behavior of the host OS
This violates unit test isolation and makes the test environment-dependent.
Why this is a problem
Not a true unit test
Unit tests should validate logic in isolation. Accessing the real filesystem turns this into an implicit integration test.
Non-deterministic across environments
Behavior may differ depending on:
OS (Windows vs Unix path handling)
execution context (monorepo root vs workspace)
CI vs local runs
Inconsistent with existing test patterns
Other utils in the same file (isFileSystemPath, getTemplateDetails) are tested using mocks and stubs, but exists() is not, which introduces inconsistency in test strategy.
Fragile during refactors
Changes to project structure or working directory can cause unrelated test failures.
Expected behavior
utils.exists() unit tests should mock filesystem access (e.g. fs.promises.access or equivalent).
Tests should explicitly cover:
file exists → resolves true
file does not exist → resolves false
No dependency on actual files or project layout.
Screenshots
How to Reproduce
Clone the repository
git clone https://github.com/asyncapi/generator.git
Open this file:
generator\apps\generator\test\utils.test.js
Locate this line (this is the root cause):
await utils.exists(${process.cwd()}/package.json);
🖥️ Device Information [optional]
- Operating System (OS): Windows 11
- Browser: Brave
- Browser Version:
👀 Have you checked for similar open issues?
- I checked and didn't find similar issue
🏢 Have you read the Contributing Guidelines?
- I have read the Contributing Guidelines
Are you willing to work on this issue ?
Yes I am willing to submit a PR!