🧹 Add expect-based tests for interactive scripts #389
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In this PR
expect
-based testing suites for interactive hardhat tasks.expect
is a utility that makes testing interactive commands easy by listening to the output and reacting to it by sending input. It is a way of testing the tasks in isolated runtime (in their own shell) while still being able to "mock" user inputs.expect
utility should be preinstalled on mac - if not, it can be installed using e.g. homebrew. On unix systems, it also comes with anautoexpect
utility that will "record" the expected interaction and turn it into a test script.The test scripts themselves are written in an interpreted language
Expectk
. It has some quite advanced control flow features but for us theexpect
andsend
instructions are the two go-to ones. There's a nice little tutorial for expect here