Skip to main content
Pilot feature: Source control setup for LWC test runs

Instructions on the correct format and setup that your git repository needs to run LWC tests as part of a CI job run in Gearset.

Stephen Chambers avatar
Written by Stephen Chambers
Updated over 2 years ago

Note: LWC test support for CI jobs is currently in early beta. It requires git as the source for a CI job to run. Results can be reported in a Slack notification for CI job results (only test failures are currently reported), or viewed in Gearset. You can configure your CI job to either fail on LWC test failures or still attempt to deploy metadata.

Source control repository setup instructions

The current implementation of LWC tests assumes that you've set up your repo in the same way as the https://github.com/trailheadapps/lwc-recipes example project. See also https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.unit_testing_using_jest_create_tests

  1. Install the sfdx-lwc-jest package with npm install @salesforce/sfdx-lwc-jest.

  2. Tests must be in a __tests__ folder. The suggested way to set this up is to create a __tests__ folder in each component's folder (that is being tested). For example, if you had a teamComponent that looked like this in the file structure:

then you add your test file like so:

3. Add **/__tests__/** to .forceignore so that the tests aren't deployed to Salesforce.

4. Add the following script to the scripts section in package.json:

"test:unit": "sfdx-lwc-jest"

5. Test this works locally by checking out the repo, running npm ci and then npm run test:unit

In Gearset, to receive notifications the CI job must have Slack notifications enabled. Please follow this guide to configure the Slack notifications. If the run errors or fails, a notification will be sent (a passed run won't notify).

Did this answer your question?