E2E testing of the CLI

Description

We want to create E2E test that cover the whole lifecycle of the Frontity CLI. Those tests should be able to:

  • launch the CLI on diferent platforms (Win, MacOS) (optional?)
  • launch the CLI with any arguments
  • pass interactive arguments to the CLI
  • assert that particular files have been created
  • check that a frontity server has been launched and returns pages (with cypress?)

Existing frameworks

This has been implemented in:

For more details, you can check out the packages/frontity/e2e-cli/README.md.


Features supported

Yes. This is possible by running the tests on github actions which support Win, Linux and MacOS containers.

Yes. Indeed you can launch the CLI with any arguments, the testing “framework”, if you can call it that, provides a helper to run an arbitrary command inside an isolated container.

Sort of. For the moment this is not supported out of the box, but since the tests are built on top of execa, it could be accomplished with something like:

const execa = require("execa");
const { Readable } = require("stream");

const subprocess = execa("frontity create --theme @frontity/mars-theme");

// The name of the project that is gonna be passed interactively 
const readable = Readable.from(["my-awesome-project"]);

// Pass it to std input
readable.pipe(subprocess.stdin);

// Actually run the `create` command 
const { stdout } = await subprocess;

console.log(stdout);

Yes. The framework helpers can run arbitrary unix commands inside the container like ls, cat or tree and capture their output.

Sort of. At the moment there is no built-in way to do this, but helpers can be created in a similar way as those for passing the interactive CLI arguments.

I’m changing this to “Released”. Thanks a lot @mmczaplinski :slightly_smiling_face::clap:

1 Like