Note: LWC test support for CI jobs is currently in early beta. It requires git as the source for a CI job to run and results are currently only included as part of a Slack notification for CI job results. Only test failures are currently reported and a CI job will still attempt to deploy metadata on LWC test failures.
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 get any results, the CI job must have Slack notifications enabled. If the run errors or fails, a notification will be sent (a passed run won't notify)