Skip to content

[TEST]: Add unit tests for scripts/compose.ts #5096

Description

@codxbrexx

What changes are you proposing?

Add automated unit tests for the blog post composition script (scripts/compose.ts) to cover its interactive CLI flow and file generation behavior.

Why do we need this improvement?

The compose script is frequently used by contributors to create new blog posts, but it currently has no automated coverage.

Problems now:

  • No tests for the CLI flow.
  • Manual validation required for any change.
  • Risk of regressions in slug generation, front matter output, and file writing.

How will this change help?

  • Safer refactoring of the script.
  • Faster contributor feedback via npm test.
  • Ensures consistent output (front matter + slug + file path).

How could it be implemented/designed?

Implementation plan:
Add tests/scripts/compose.test.ts using Jest (already configured with asyncapi/website).

Mock dependencies:

  • inquirer for CLI answers.
  • fs for file writes.
  • moment for deterministic dates.

Test scenarios:

  • Happy path: verify file path + front matter.
  • Slug generation: ensure titles convert to kebab-case.
  • Error handling: verify logging on file write failure.

Breaking changes

No.

Check Before Submitting

Would you like to help fix this issue? (Not required, but appreciated!)

  • Yes, I am interested in contributing to the fix.
  • No, I am just reporting the issue.

cc @asyncapi/maintainers

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions