When writing tome-cli, I wanted to ensure that the tool’s side effects were accurately tested at their outermost bound and so I needed to wrap the full tool’s binary execution in end to end tests.
Normally I would use bats-core for bash/cli testing. But I’ve been using deno more and more for work
and find dax
library (like xz from Google) to be a simple and powerful mechanism for shelling out
from a more robust language.
I simplified my testing interface by wrapping the tome-cli command in a deno function, injected the necessary environmental variables, and pre-parse the outputs to make each test low repetition.
Function setup: https://github.com/zph/tome-cli/blob/main/test/tome-cli.test.ts#L27-L31
Example test: https://github.com/zph/tome-cli/blob/main/test/tome-cli.test.ts#L100-L108
This approach makes for easier E2E testing compared to bats because I have robust data types without the fragility/peculiarities of bash, while having a clearer UI for assertions and their diffs.