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
npm install @salesforce/sfdx-lwc-jest.
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
teamComponentthat looked like this in the file structure:
then you add your test file like so:
.forceignore so that the tests aren't deployed to Salesforce.
4. Add the following script to the
scripts section in
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).