Cypress is an amazing tool for end to end testing Rails applications, but large test suites can quickly take upwards of 20 minutes to run. That’s where Knapsack Pro comes in. Knapsack Pro Queue Mode to intelligently split your test suite into jobs that can be run in parallel, reducing run time to only a few minutes. In this article we’ll show how to quickly implement Knapsack Pro Queue Mode to speed up both Cypress & RSpec test suites in a Ruby on Rails app on Github Actions
Set up Knapsack Pro API Keys
First step is to go to your Knapsack dashboard and grab your API keys for both RSpec and Cypress. Once you have those, go to your Github Repo’s settings, for example:
Set up your GitHub Actions config file
Once you’ve added your KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC and KNAPSACK_PRO_TEST_SUITE_TOKEN_CYPRESS secrets, the next step is setting up your GitHub Actions configuration file to use the Knapsack Runner in place of the normal commands to run RSpec and Cypress.
Existing GitHub Actions config
For those that already have a GH actions config file setup (e.g. .github/workflows/ci.yml), here’s all that you should need to change to get Knapsack Pro Queue Mode working for both Cypress and RSpec.
Change your RSpec run command to use Knapsack:
Change your cypress run command to use Knapsack as well:
New Github Actions config file
For those starting from scratch, here’s a full example .github/workflows/ci.yaml for a Rails app with Cypress + RSpec with Knapsack tokens for RSpec and Cypress already added.
Add Knapsack Pro gem and npm package
Add the Knapsack Pro gem to your Gemfile:
Add the Knapsack Pro npm package with yarn add --dev @knapsack-pro/cypress
Run your tests & view your results
Once you’ve completed the above steps, trigger a test run on your repo. You should see multiple jobs for both RSpec and Cypress like so: