Jest is a powerful testing framework used in JavaScript projects. Besides vanilla JS, it’s often used for React, NodeJS, Angular or Vue.js projects, among others. I am going to help you configure running your Jest test suite on GitHub Actions. We are going to use CI parallelization with Knapsack Pro, for maximum effectiveness. Let’s begin.
Splitting the test suites on multiple machines is a smart way to achieve short build times and increase your team’s productivity. A naïve division of work between multiple machines might result in fewer gains than anticipated though, due to possible bottlenecks (please refer to this article to learn more about the reasons behind it). This is where a dynamic test distribution with Knapsack Pro ( @knapsack-pro/jest) comes into play. It ensures you utilize your parallel CI nodes (a.k.a. parallel jobs) in the optimal way.
GitHub Actions is configured through a yaml config file residing in your repository. It should be placed in the: .github/workflows
directory, e.g. .github/workflows/main.yml
. When properly configured, your GH Actions builds will be visible in the Actions tab in your GitHub repository page.
The Build Matrix is a powerful feature in GitHub Actions, which allows you to easily configure a combination of settings for running multiple jobs. Since we are concerned with simple parallelism for the purpose of this demonstration, our build matrix config is pretty straightforward:
strategy:
fail-fast: false
matrix:
ci_node_total: [4]
ci_node_index: [0, 1, 2, 3]
For the ci_node_total
key, we always provide a single-element list. The value should be equal to the number of parallel nodes you are going to use.
#continuous_integration #jest