You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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)
The text was updated successfully, but these errors were encountered:
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.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:Where
readableStream
andwriteableStream
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
)The text was updated successfully, but these errors were encountered: