asyncapi / asyncapi/website

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

Open
#5,096 6 comments 0 reactions 0 assignees View on GitHub
area/javascript good first issue triaged
Dominant language
TypeScript
Stars
716
Forks
1.2k
Avg merge
1d 12h
Merged PRs (30d)
35

Description

### 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

- [x] I have looked for similar issues to avoid duplicates.
- [x] I have read the[ Contributing Guidelines](https://github.com/asyncapi/.github/blob/master/CONTRIBUTING.md)

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

- [x] Yes, I am interested in contributing to the fix.
- [ ] No, I am just reporting the issue.

cc @asyncapi/maintainers

Contributor guide

Open the contributing guide

Research direction

Start by reading scripts/compose.ts and then create tests/scripts/compose.test.ts using the existing Jest setup. Mock inquirer, fs, and moment, and run npm test. Done means the tests cover the interactive flow, kebab-case slug generation, front matter and file-path output, and file-write error logging.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli, testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.