asyncapi / asyncapi/generator

Improve Test Coverage and Robustness in `apps/generator`

Open
#2,002 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.1k
Forks
397
Avg merge
1d 7h
Merged PRs (30d)
25

Description

## Description

While analyzing the **asyncapi-generator** codebase, I identified several areas where the test suite can be improved to increase reliability and catch potential regressions early.

Currently:

* Some core modules like `conditionalGeneration.js` lack dedicated unit tests.
* Certain integration test scenarios (such as log verification for `noOverwriteGlobs`) are marked with TODOs.

Strengthening these areas will improve confidence in future changes and refactors.

---

## Proposed Improvements

### 1. Dedicated Unit Tests for `conditionalGeneration.js`

The `lib/conditionalGeneration.js` module handles complex logic for conditional file/folder generation using template parameters and JMESPath expressions.

**Goal:** Create
`apps/generator/test/conditionalGeneration.test.js`
to cover:

**Scenarios**

* Parameter-based conditions.
* Subject (JMESPath) based conditions.
* Handling of the deprecated `conditionalFiles` configuration.

**Edge Cases**

* Missing parameters in `templateParams`.
* JMESPath expressions returning no results or `null`.
* Custom `validate` functions in `conditionalGeneration`.
* Server-specific context in JMESPath evaluation.

---

### 2. Verify Log Messages in Integration Tests

An existing TODO in `test/integration.test.js` suggests verifying log messages when files are skipped due to `noOverwriteGlobs`.

**Goal:** Implement log spying using:

```js
jest.spyOn(log, 'debug')
```

**To ensure:**

* `logMessage.relativeSourceFileNotGenerated` (or the corresponding overwrite-skip message) is correctly called.
* Users get visual feedback in debug mode when files are intentionally skipped.

---

### 3. Expand `noOverwriteGlobs` Scenarios

Current integration tests for `noOverwriteGlobs` cover only basic cases.

**Goal:** Add more complex scenarios to
`apps/generator/test/integration.test.js`, including:

* Nested directory structures.
* Multiple glob patterns.
* Overlapping globs.

---

## Impact

These improvements will:

* Increase overall test coverage of the generator core.
* Ensure the transition from `conditionalFiles` → `conditionalGeneration` is stable.
* Improve developer experience by confirming debug logs behave as expected.

---

## Next Steps

* [ ] Create `apps/generator/test/conditionalGeneration.test.js`.
* [ ] Update `apps/generator/test/integration.test.js` with:

* Log verification.
* Complex glob scenarios.
* [ ] Ensure all existing tests pass.

---

Contributor guide

Open the contributing guide

Research direction

Start by reading apps/generator/lib/conditionalGeneration.js and the existing tests in apps/generator/test/integration.test.js, then run the generator test suite. Add the named unit and integration scenarios, including debug-log verification and complex noOverwriteGlobs cases; done means the expanded tests pass without regressions.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.