Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Tests #125

Open
ThisIsMissEm opened this issue Jul 28, 2020 · 1 comment
Open

Better Tests #125

ThisIsMissEm opened this issue Jul 28, 2020 · 1 comment

Comments

@ThisIsMissEm
Copy link

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)

@ThisIsMissEm
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant