• This repository has been archived on 12/Feb/2022
  • Stars
    star
    122
  • Rank 292,031 (Top 6 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lightning Testing Service (LTS) CircleCI

Lightning Testing Service Overview

NOTICE: This tool is no longer supported and no additional work is planned for this tool. We recommend if you want to use this tool, that you treat it as an example and create your own fork of it to use in your build process

The Lightning Testing Service, or LTS, is a set of tools and services that let you create test suites for your Aura components using standard JavaScript test frameworks, such as Jasmine and Mocha.

Note: As of Spring '19, the Lightning Component framework has two programming models, Lightning Web Components, and Aura Components, the original model. Use LTS to test Aura components.

Automated tests are the best way to achieve predictable, repeatable assessments of the quality of your custom code. Writing automated tests for your custom components gives you confidence that they work as designed, and allows you to evaluate the impact of changes, such as refactoring, or of new versions of Salesforce or third-party JavaScript libraries.

The LTS supports testing with standard JavaScript test frameworks. We provide easy-to-use wrappers for using Jasmine and Mocha. If you prefer to use an alternative test framework, you can wrap it yourself. (See Next Steps for some details.)

Getting Started with Lightning Testing Service

LTS and Salesforce CLI are two great tastes that taste great together. Installing the LTS is a one line command in the Salesforce CLI. Once installed, you can work with your test suite in a variety of ways from the command line. This approach also facilitates systematic automated testing.

Note: If you just want to โ€œkick the tires,โ€ that's cool, too. You can manually install the LTS unmanaged package. The package provides the test service app and an example test suite. It also includes example components that the test suite runs against. You run the test suite by accessing the URL for the LTS app in your org.

Write your tests using a JavaScript testing framework of your choosing. We provide easy-to-use wrappers for Jasmine and Mocha.

A simple Jasmine test spec looks like the following:

/**
 * This is a 'hello world' Jasmine test spec
 */
describe("A simple passing test", function () {
  it("checks that true is always true", function () {
    expect(true).toBe(true);
  });
});

A similar Mocha test looks, well, similar:

/**
 * This is a 'hello world' Mocha test
 */
var assert = require("assert");
describe("Test the nature of truth", function () {
  describe("A simple passing test", function () {
    it("checks that true is always true", function () {
      assert.equal(true, true);
    });
  });
});

You can write your own wrapper if you prefer a different testing framework. It's not hard, but plan on half a day to a day of work.

The LTS also provides utilities specific to the Lightning Component framework, which let you test behavior specific to Aura components. Details are explained in comments in the example tests.

Your test suite is deployed in the form of an archive (zip) static resource. Once the LTS is installed and configured, you make changes to your test suite, create the archive, and upload it to your org. Once uploaded you can run the test suite via the command line or via URL.

Important: Don't run tests in your production org. The LTS doesn't provide an isolated test context or transaction wrapper. DML operations you perform in your tests won't be rolled back at the end of the test. We recommend that you run your LTS test suites only in scratch orgs, using data provided by the test suite itself.

Installing the Lightning Testing Service

There are two ways you can install the LTS. The simplest is to use the Salesforce CLI. If you're not using the Salesforce CLI, you can manually install the unmanaged package.

Install the Lightning Testing Service with the Salesforce CLI

The Salesforce CLI includes a one line command for automatically installing the LTS unmanaged package. The Salesforce CLI also allows you to use the sfdx command line tool to perform automated testing as part of your development process, including automated process, such as continuous integration.

NOTICE: When installing the CLI Plugin, an external request is made to https://api.github.com/repos/forcedotcom/LightningTestingService/releases/ in order to download supporting files for the plugin. If this URL is blocked by your firewall, the installation of the plugin will fail.

  1. If you haven't already, install the Salesforce CLI by following the instructions for your operating system:

    Install the Salesforce CLI in the Salesforce CLI Setup Guide

  2. Verify that the Salesforce CLI plug-in is installed and updated by running the following command in your shell or terminal application:

    sfdx update

    Additional verification details are available in Verify Your Installation and Install the Plug-In in the Salesforce CLI Setup Guide.

  3. Install the LTS CLI Plugin with the following command:

    sfdx plugins:install plugin-lightning-testing-service
  4. Install the LTS package with the following command:

    sfdx aura-test:install

    This installs the latest version of the LTS package into your default SFDX org. See the help for the install command for additional options.

After you install LTS, you can run your tests from the command line using the sfdx tool. For example:

sfdx force:auth:web:login -s     # connect to your scratch org
sfdx force:source:push           # push local source to the scratch org
sfdx aura-test:run -a jasmineTests.app   # run the test suite

When you run the aura-test:run -a jasmineTests.app command in a connected workspace you should see something like the following:

Console output from a successful test suite execution using sfdx

This tells you that the command line tools are working, and connected to your development org.

Install the Lightning Testing Service Unmanaged Package Manually

If you're not using the Salesforce CLI, you're missing out on a lot, but you can still use LTS. Installing the LTS package is just like installing any other unmanaged package.

  1. Log in to your org. We recommend that you create a new DE org for evaluating the LTS.
  2. Go to the project Releases page, and click the package installation URL for the latest release.
  3. Authenticate again with the credentials for your DE org.
  4. Follow the normal package installation prompts. We recommend installing the package for admins only.

Touring the Lightning Testing Service

However you install it, the LTS package includes the following items:

  • Example test suites
    • Jasmine JavaScript files in archive static resources
    • Mocha JavaScript files in archive static resources
  • Example components to be tested
    • Components, an Apex class, and a custom label
  • LTS infrastructure
    • Jasmine framework and wrapper
    • Mocha framework and wrapper
    • LTS test utilities
    • Test runner component
    • Wrapper test app

Once installed, you can run the example test suite by going to the following URL in your org: https://<myServer>/c/jasmineTests.app (Jasmine) https://<myServer>/c/mochaTests.app (Mocha)

You should see a screen that looks something like the following.

Successful execution of the jasmineTests.app tests

This page tells you that the package is correctly installed and LTS is working in your org.

Next Steps

When you have the LTS package installed and working in your org, youโ€™re ready to begin exploring the test code, and even writing your own tests. Here are some next steps for you to take.

Explore the Example Test Suites

To dive into the test suites and start learning how to write tests for your Aura components, explore the tests and the components being tested side-by-side. Youโ€™ll want to open the test suite file in one window, and in another window (perhaps in your IDE) open the simple components being tested.

Both the components and the test suites included in the unmanaged package are also available in a repository on GitHub:

https://github.com/forcedotcom/LightningTestingService

Components for Testing

All of the testable components are named beginning with โ€œegโ€ (from the abbreviation โ€œe.g.โ€, meaning for example). The components provided in the package can be accessed as you would any Aura component.

  • In the Developer Console
  • In the Force.com IDE, in the /aura/ directory
  • By converting your orgโ€™s metadata into a format that you can work with locally, using Salesforce CLI

You can also explore the components directly from the repo. Theyโ€™re available in the lightning-component-tests/main/default/aura directory.

There are more than a dozen different components, designed to be used in illustrative tests. Each of the components has a description of its behavior in its .auradoc documentation file.

Test Suites

The example tests are included in the form of static resources. You can also review them directly in the repo, in the lightning-component-tests/test/default/staticresources directory.

There are four test suites included in the LTS package, three for Jasmine and one for Mocha:

  • jasmineHelloWorldTests.resource โ€” A very simple Jasmine example including one passing and one failing test.
  • jasmineExampleTests.resource โ€” The main Jasmine example test suite.
  • jasmineLightningDataServiceTests.resource โ€” Some Jasmine examples specific to testing Lightning Data Service-based components.
  • mochaExampleTests.resource โ€” The Mocha example test suite, which provides examples parallel to the main Jasmine test suite.

The remainder of the static resources are infrastructure used by the LTS. Theyโ€™re briefly described in Use Another JavaScript Test Framework.

The jasmineExampleTests.resource and mochaExampleTests.resource files are each a single JavaScript file containing a complete test suite. Itโ€™s a single file for convenience in delivery and exploration. Your own test suites can include many such files. The test suites are copiously commented. The code and comments serve as the official documentation for how to write tests.

Write Your Own Tests

A separate document, Testing Lightning Components with the Lightning Testing Service, describes the flow, or lifecycle, of using the LTS to automate your testing. Once youโ€™ve explored the example tests, use this document to dive into writing a test suite for your own custom components.

Use Another JavaScript Test Framework

The Lightning Testing Service provides a way to use standard JavaScript test frameworks with your Aura components. Weโ€™ve provided the example test suites implemented in Jasmine and Mocha. These are well-regarded test frameworks, and if you havenโ€™t chosen one already, we recommend you start with one of them.

If youโ€™d prefer to use another test framework, either because youโ€™ve already selected one, or because you find something more to your taste, you can use it with the LTS instead.

All of the packaged pieces of the LTS are included in the project repository, in the lightning-component-tests/test/default directory. The pieces youโ€™ll need to modify or replace are the following items, drawn from the Jasmine wrapper.

  • aura/jasmineTests โ€” The front end of the LTS, this simple app includes the test runner component, and a list of test suites to feed it.
  • aura/lts_jasmineRunner โ€” The test runner component for Jasmine. It includes references to the required Jasmine library, which it loads along with the test spec resources, and then fires the test runner.
  • lts_jasmine.resource โ€” The Jasmine library, unmodified.
  • lts_jasmineboot.resource โ€” A JavaScript IIFE that launches Jasmine in the LTS context.
  • lts_testutil.resource โ€” A collection of utilities for use within your test specs, and by the test framework wrappers. They provide Lightning component-specific functions that make it easier to test your custom components from a test context.

The Mocha version of the framework wrapper provides similar files. You might find the similarities and differences instructive in creating your own adapter for other frameworks.

If youโ€™re already experienced with setting up another test framework, adapting the Jasmine examples should take you a day or so, but not longer. Weโ€™d be thrilled to hear more about your adventures with other JavaScript test frameworks!

More Repositories

1

postman-salesforce-apis

Salesforce API Postman Collection
1,071
star
2

salesforcedx-vscode

Salesforce Extensions for VS Code
TypeScript
949
star
3

aura

This project is archived, please see the readme for additional resources.
JavaScript
676
star
4

scrollerjs

A JavaScript library that helps you build performant UI components for the web.
JavaScript
637
star
5

phoenix

Java
560
star
6

SalesforceMobileSDK-iOS

iOS SDK for Salesforce
Objective-C
520
star
7

cli

Salesforce CLI
477
star
8

dataloader

Salesforce Data Loader
Java
440
star
9

SFDX-Data-Move-Utility

SFDMU is a cutting-edge Salesforce data migration tool for seamless org population from other orgs or CSV files. It handles all CRUD operations on multiple related objects in one go.
TypeScript
405
star
10

SalesforceMobileSDK-Android

Android SDK for Salesforce
Java
313
star
11

wsc

Java
266
star
12

mobile-ui-elements

Custom elements to build beautiful mobile applications on salesforce.
JavaScript
247
star
13

idecore

The core plug-ins for the Force.com IDE
Java
238
star
14

sfdx-scanner

HTML
215
star
15

EMP-Connector

A simplified cometd connector for Enterprise Messaging Platform
Java
185
star
16

CustomMetadataLoader

Tool to help users bulk create and update custom metadata records in salesforce.com from a CSV file.
Apex
161
star
17

b2b-commerce-on-lightning-quickstart

Shell
157
star
18

sfdx-core

TypeScript
151
star
19

force-dot-com-esapi

Enterprise Security API for the Apex language on the Force.com platform.
Apex
129
star
20

Analytics-Cloud-Dataset-Utils

Friendly utility to load your on-prem data, whether large or small, to Einstein Analytics Datasets, with useful features such as autoloading, dataflow control and dataset inspection.
JavaScript
129
star
21

SalesforceCanvasFrameworkSDK

Java
122
star
22

sfdx-simple

Apex
116
star
23

quiz-host-app

Multiplayer quiz app built on Salesforce technology (host app)
Apex
108
star
24

SalesforcePy

An absurdly simple package for making Salesforce Rest API calls.
Python
106
star
25

dependencies-cli

SFDX plugin for metadata dependencies tooling API
CSS
101
star
26

sfdx-travisci

Apex
98
star
27

Data-Migration-Tool

Java
98
star
28

ConnectApiHelper

Helper class that makes it easier to post Chatter @-mentions, rich text, and inline images with Apex code.
Apex
93
star
29

RecordViewer

Record Viewer - UI API + Node.js Sample App
JavaScript
86
star
30

salesforcedx-templates

Salesforce Templates Node Library
TypeScript
79
star
31

SFDX-Data-Move-Utility-Desktop-App

This repository contains the special Desktop GUI Application, that will help you to prepare and execute data migration packages using the SFDMU Plugin.
TypeScript
77
star
32

sfdx-plugin-generate

TypeScript
73
star
33

salesforcedx-docker

The official Dockerfile for Salesforce DX
JavaScript
72
star
34

ApexUnit

ApexUnit is a powerful continuous integration tool for the Force.com platform
Java
71
star
35

SalesforceMobileSDK-Shared

JavaScript
68
star
36

cinnamon

Cinnamon is a Force.com app that enables you to build and run Selenium tests to validate custom UI pages with Visualforce/Javascript in your Salesforce org.
Apex
67
star
37

commerce-on-lightning-components

Commerce on Lightning out-of-the-box component source code for reference and educational purposes
JavaScript
67
star
38

SalesforceMobileSDK-Samples

Samples for working with the Salesforce Mobile SDK
C
65
star
39

commerce-on-lightning

An SFDX Plugin to setup a B2C or B2B Store
TypeScript
64
star
40

WSDL2Apex

Apex
62
star
41

salesforce-alm

A read-only snapshot of the salesforce-alm plugin known as the "toolbelt".
TypeScript
61
star
42

devops-center-feedback

61
star
43

SlidingCarousel

A tool used to create the onboarding experience for Salesforce1's hybrid application on iOS.
Objective-C
59
star
44

LightningFlowComponents

โšก A collection of sample Lightning Components that can be used to enhance Salesforce Lightning Flow.
JavaScript
58
star
45

source-deploy-retrieve

JavaScript toolkit for working with Salesforce metadata.
TypeScript
55
star
46

PerlKoans

Perl
51
star
47

go-soql

Golang tag library to generate SOQL queries
Go
51
star
48

java-sdk

NO LONGER MAINTAINED: Database.com SDK for Java
Java
47
star
49

SalesforceMobileSDK-Templates

Kotlin
46
star
50

SalesforceMobileSDK-ReactNative

Objective-C
46
star
51

user-access-visualization

Apex
46
star
52

AuraEnabledScanner

JavaScript
45
star
53

SalesforceMobileSDK-CordovaPlugin

Cordova plugin for the Salesforce Mobile SDK
Java
45
star
54

sfdx-analytics

Einstein Analytics sample application templates
JavaScript
44
star
55

sfdx-jenkins-org

Jenkins example with org development
Apex
44
star
56

cli-packages

TypeScript
43
star
57

lwc-dev-server-feedback

LWC Local Development
43
star
58

LWC-Mobile-Samples

Mobile sample applications and code for LWC development
JavaScript
42
star
59

isvte-sfdx-plugin

TypeScript
42
star
60

SalesforceCanvasJavascriptSDK

A JavaScript SDK used to integrate applications with the Force.com Canvas framework
JavaScript
42
star
61

OrgMonitor

JavaScript
41
star
62

Salesforce1-Dev-Guide-Setup-Package

40
star
63

sfdx-bitbucket-package

Bitbucket Pipelines examples with Package development
Apex
39
star
64

project-force

Reference implementation app for Feature Management.
Apex
37
star
65

schemas

Salesforce DX Schemas
JavaScript
36
star
66

Einstein-GPT-for-Developers

Einstein GPT For Developers
36
star
67

salesforcedx-actions

(Unofficial) GitHub Actions for SalesforceDX using the Salesforce CLI
Shell
34
star
68

aura-note

JavaScript
34
star
69

lightning-language-server

LWC and Aura Language Servers - shipped as part of the Salesforce VSCode Extensions
JavaScript
33
star
70

distributions

Low-level primitives for collapsed Gibbs sampling in python and C++
C++
33
star
71

apex-tmLanguage

Salesforce Apex Language syntax grammar used for colorization
TypeScript
32
star
72

Salesforce-CDP-jdbc

JDBC driver to connect to Salesforce CDP.
Java
32
star
73

sfdx-dev-packages

TypeScript
30
star
74

sfdx-gitlab-org

GitLab Pipelines example with org development
Apex
30
star
75

code-builder-feedback

This repository is used to collect feedback for the Code Builder beta.
29
star
76

eslint-plugin-aura

Salesforce Lightning (Aura) specific linting rules for ESLint
JavaScript
27
star
77

git2gus

A Github application to keep issues in sync with Agile Accelerator
JavaScript
27
star
78

salesforcedx-vscode-slds

TypeScript
26
star
79

sfdx-bitbucket-org

Bitbucket Pipelines examples with org development
Apex
26
star
80

lwc-builder

VSCode Extension to kickstart Lightning Web Component development.
TypeScript
26
star
81

sfdx-circleci

Apex
24
star
82

ServiceSDK-iOS

Salesforce Embedded Service SDK for iOS
23
star
83

dx-empty

Template repository representing the empty file system structure for a new Salesforce DX project.
JavaScript
23
star
84

SalesforceMobileSDK-Package

JavaScript
22
star
85

soql-tooling

SOQL Language Tooling features including the Language Server and Query Builder UI.
TypeScript
22
star
86

RecordViewerNative

Record Viewer Native - UI API + React Native Sample App
JavaScript
21
star
87

salesforce-deskcom-api

A lightweight, flexible library for desk.com APIv2, it supports basic auth and OAuth as authentication methods and is written to be auto discoverable.
Ruby
21
star
88

sfdx-gitlab-package

Apex
20
star
89

lwc-builder-ui

JavaScript
20
star
90

almond

Native Force.com Learning Management Application
Apex
20
star
91

SiteCrawler

This is a Java library which can be used to crawl the content of some of web properties (www.salesforce.com, blogs.salesforce.com for example). It supports dynamic scaling (depending on available machine power (CPU, RAM) and network capacity) out of the box. It also has a Plugin structure, which allows others to write code (plugins) that act on the crawled pages.
Java
20
star
92

devops-center-roadmap

19
star
93

lwc-dev-mobile

TypeScript
19
star
94

sfdx-jenkins-package

Apex
19
star
95

source-tracking

JavaScript library for tracking local and remote Salesforce metadata changes.
TypeScript
19
star
96

df17-ant-to-sfdx

Metadata repository demonstrating move from Ant Migration Tools to the Salesforce CLI
Apex
19
star
97

salesforce-datacom-api-java-client

Easy-to-use and efficient Java client library for accessing Data.com APIs using JSON[XML] and OAuth 2.0
Java
19
star
98

commerce-extensibility

Apex
18
star
99

codey-midnight

Dark theme for VS Code configured for accessibility and Salesforce development
18
star
100

salesforcedx-apex

Salesforce Apex Node Library
TypeScript
18
star