commitizen / commitizen/cz-conventional-changelog

Better Tests

Open
#125 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
793
Forks
444
PR merge metrics
No merged PRs in 30d

Description

I've been working on a new feature for cz-conventional-changelog (related to #118 ), and I've noticed that all of the tests essentially fake out inquirer, which means that logic like `when` in inquirer prompts wasn't respected. An alternative testing strategy would be to assume that the inquirer module works as expected and then work with the stdin/stdout streams to do more integration-style testing.

- https://shift.infinite.red/integration-testing-interactive-clis-93af3cc0d56f

If we assume that git-cz correctly injects an inquirer instance into this module when calling `engine(options).prompter(inquirer, commit)`, then we can actually write tests with:

```
testPrompt = inquirer.createPromptModule({
input: readableStream,
output: writeableStream
});

engine(options).prompter(testPrompt, (message) => {
// .. do some assertions on message
})

// do some assertions on the prompter by sending data to readableStream and reading from writeableStream
```

Where `readableStream` and `writeableStream` are as defined in the node.js Streams documentation.

The article linked above actually uses the enquirer module, not inquirer, which has a `prompt.keypress` method to send data in during tests.

For now, I'm considering this as being far too an extensive piece of work to do in my pull request, but would allow us to better test cz-conventional-changelog by having proper regression tests. I have already done a bunch of work to separate the loading of options from the loading of the module, such that the option handling can be tested without mocking out external modules too much (just `@commitlint/load`)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.