Skip to content

Improve Test Coverage and Robustness in apps/generator #2002

@Satya900

Description

@Satya900

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:

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 conditionalFilesconditionalGeneration 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.


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions