lightning Commands

Use the lightning commands to create Aura components and Lightning web components and to test Aura components. As of API version 45.0, you can build Lightning components using two programming models: Lightning Web Components, and the original model, Aura Components. Lightning web components and Aura components can coexist and interoperate on a page.

force:lightning:lint

Runs a static analysis, or “lint,” tool on your Aura component code. The default rules include recommended best practices and Lightning Locker requirements. For details, including how to customize the rules for your org, see the Lightning Aura Components Developer Guide.

Command Syntax

sfdx force:lightning:lint
[--json]
[--loglevel LOGLEVEL]
[-i IGNORE]
[--files FILES]
[--config CONFIG]
[--verbose]
[--exit]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-i | --ignore IGNORE
Optional

A “glob” pattern used to filter folders (and their contents) out of the analysis. For example: --ignore **/foo/**.

Type: string
--files FILES
Optional

A “glob” pattern used to add specific files to the analysis. For example, to only analyse your controller files, use --files **/*Controller.js. When specified, this value overrides the --ignore flag. The default is all .js files.

Type: string
--config CONFIG
Optional

Path to a custom ESLint configuration file. Only code style rules are used, while the rest are ignored. For example: --config path/to/.eslintrc.

Type: string
--verbose
Optional

Report both warnings and errors. The default is to report only errors.

Type: boolean
--exit
Optional

Exit with error code 1 if there are lint issues. The default exits without an error code.

Type: boolean

Help for force:lightning:lint

force:lightning:lwc:test:create

create a Lightning web component test with boilerplate code inside a __tests__ directory

Command Syntax

sfdx force:lightning:lwc:test:create
[--json]
[--loglevel LOGLEVEL]
-f FILEPATH

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-f | --filepath FILEPATH
Required

path to Lightning web component .js file to create a test for

Type: string

Help for force:lightning:lwc:test:create

force:lightning:lwc:test:run

invoke Lightning web component Jest unit tests

Command Syntax

sfdx force:lightning:lwc:test:run
[--json]
[--loglevel LOGLEVEL]
[-d]
[--watch]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-d | --debug
Optional

Runs tests in a Node process that an external debugger can connect to. The run pauses until the debugger is connected. For more information, see: https://jestjs.io/docs/en/troubleshooting

Type: boolean
--watch
Optional

Runs tests when a watched file changes. Watched files include the component under test and any files it references.

Type: boolean

Help for force:lightning:lwc:test:run

force:lightning:lwc:test:setup

install Jest unit testing tools for Lightning web components

Command Syntax

sfdx force:lightning:lwc:test:setup
[--json]
[--loglevel LOGLEVEL]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn

Help for force:lightning:lwc:test:setup

force:lightning:app:create

Creates a Lightning app bundle in the specified directory or the current working directory. The bundle consists of multiple files in a folder with the designated name.

Command Syntax

sfdx force:lightning:app:create
[--json]
[--loglevel LOGLEVEL]
-n APPNAME
[-t TEMPLATE]
[-d OUTPUTDIR]
[--apiversion APIVERSION]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-n | --appname APPNAME
Required

The Lightning app name. The name can be up to 40 characters and must start with a letter.

Type: string
-t | --template TEMPLATE
Optional

The template to use to create the file. Supplied parameter values or default values are filled into a copy of the template.

Type: string
Permissible values are: DefaultLightningApp
Default value: DefaultLightningApp
-d | --outputdir OUTPUTDIR
Optional

The directory to store the newly created files. The location can be an absolute path or relative to the current working directory. The default is the current directory.

Type: string
Default value: .
--apiversion APIVERSION
Optional

Override the API version used for API requests made by this command.

Type: string

Help for force:lightning:app:create

If not supplied, the apiversion, template, and outputdir use default values.

The outputdir can be an absolute path or relative to the current working directory.

If you don’t specify an outputdir, we create a subfolder in your current working directory with the name of your bundle. For example, if the current working directory is force-app and your Lightning bundle is called myBundle, we create force-app/myBundle/ to store the files in the bundle.

Examples:

1$ sfdx force:lightning:app:create -n myapp
1$ sfdx force:lightning:app:create -n myapp -d aura

force:lightning:component:create

Creates a bundle for an Aura component or a Lightning web component in the specified directory or the current working directory. The bundle consists of multiple files in a folder with the designated name.

Command Syntax

sfdx force:lightning:component:create
[--json]
[--loglevel LOGLEVEL]
-n COMPONENTNAME
[-t TEMPLATE]
[-d OUTPUTDIR]
[--apiversion APIVERSION]
[--type TYPE]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-n | --componentname COMPONENTNAME
Required

The Lightning component name. The name can be up to 40 characters and must start with a letter.

Type: string
-t | --template TEMPLATE
Optional

The template to use to create the file. Supplied parameter values or default values are filled into a copy of the template.

Type: string
Default value: DefaultLightningCmp
-d | --outputdir OUTPUTDIR
Optional

The directory to store the newly created files. The location can be an absolute path or relative to the current working directory. The default is the current directory.

Type: string
Default value: .
--apiversion APIVERSION
Optional

Override the API version used for API requests made by this command.

Type: string
--type TYPE
Optional

The type of the new Lightning component.

Type: string
Permissible values are: aura, lwc
Default value: aura

Help for force:lightning:component:create

If not supplied, the apiversion, template, and outputdir use default values.

The outputdir can be an absolute path or relative to the current working directory.

If you don’t specify an outputdir, we create a subfolder in your current working directory with the name of your bundle. For example, if the current working directory is force-app and your Lightning bundle is called myBundle, we create force-app/myBundle/ to store the files in the bundle.

To create a Lightning web component, pass --type lwc to the command. If you don’t include a --type value, Salesforce CLI creates an Aura component by default.

Examples:

1$ sfdx force:lightning:component:create -n mycomponent
1$ sfdx force:lightning:component:create -n mycomponent --type lwc
1$ sfdx force:lightning:component:create -n mycomponent -d aura
1$ sfdx force:lightning:component:create -n mycomponent --type lwc -d lwc

force:lightning:event:create

Creates a Lightning event bundle in the specified directory or the current working directory. The bundle consists of multiple files in a folder with the designated name.

Command Syntax

sfdx force:lightning:event:create
[--json]
[--loglevel LOGLEVEL]
-n EVENTNAME
[-t TEMPLATE]
[-d OUTPUTDIR]
[--apiversion APIVERSION]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-n | --eventname EVENTNAME
Required

The Lightning event name. The name can be up to 40 characters and must start with a letter.

Type: string
-t | --template TEMPLATE
Optional

The template to use to create the file. Supplied parameter values or default values are filled into a copy of the template.

Type: string
Permissible values are: DefaultLightningEvt
Default value: DefaultLightningEvt
-d | --outputdir OUTPUTDIR
Optional

The directory to store the newly created files. The location can be an absolute path or relative to the current working directory. The default is the current directory.

Type: string
Default value: .
--apiversion APIVERSION
Optional

Override the API version used for API requests made by this command.

Type: string

Help for force:lightning:event:create

If not supplied, the apiversion, template, and outputdir use default values.

The outputdir can be an absolute path or relative to the current working directory.

If you don’t specify an outputdir, we create a subfolder in your current working directory with the name of your bundle. For example, if the current working directory is force-app and your Lightning bundle is called myBundle, we create force-app/myBundle/ to store the files in the bundle.

Examples:

1$ sfdx force:lightning:event:create -n myevent
1$ sfdx force:lightning:event:create -n myevent -d aura

force:lightning:interface:create

Creates a Lightning interface bundle in the specified directory or the current working directory. The bundle consists of multiple files in a folder with the designated name.

Command Syntax

sfdx force:lightning:interface:create
[--json]
[--loglevel LOGLEVEL]
-n INTERFACENAME
[-t TEMPLATE]
[-d OUTPUTDIR]
[--apiversion APIVERSION]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-n | --interfacename INTERFACENAME
Required

The Lightning interface name. The name can be up to 40 characters and must start with a letter.

Type: string
-t | --template TEMPLATE
Optional

The template to use to create the file. Supplied parameter values or default values are filled into a copy of the template.

Type: string
Permissible values are: DefaultLightningIntf
Default value: DefaultLightningIntf
-d | --outputdir OUTPUTDIR
Optional

The directory to store the newly created files. The location can be an absolute path or relative to the current working directory. The default is the current directory.

Type: string
Default value: .
--apiversion APIVERSION
Optional

Override the API version used for API requests made by this command.

Type: string

Help for force:lightning:interface:create

If not supplied, the apiversion, template, and outputdir use default values.

The outputdir can be an absolute path or relative to the current working directory.

If you don’t specify an outputdir, we create a subfolder in your current working directory with the name of your bundle. For example, if the current working directory is force-app and your Lightning bundle is called myBundle, we create force-app/myBundle/ to store the files in the bundle.

Examples:

1$ sfdx force:lightning:interface:create -n myinterface
1$ sfdx force:lightning:interface:create -n myinterface -d aura

force:lightning:test:create

Creates a Lightning test in the specified directory or the current working directory. The .resource file and associated metadata file are created.

Command Syntax

sfdx force:lightning:test:create
[--json]
[--loglevel LOGLEVEL]
-n TESTNAME
[-t TEMPLATE]
[-d OUTPUTDIR]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-n | --testname TESTNAME
Required

The name of the new Lightning test. The name can be up to 40 characters and must start with a letter.

Type: string
-t | --template TEMPLATE
Optional

The template to use to create the file. Supplied parameter values or default values are filled into a copy of the template.

Type: string
Permissible values are: DefaultLightningTest
Default value: DefaultLightningTest
-d | --outputdir OUTPUTDIR
Optional

The directory to store the newly created files. The location can be an absolute path or relative to the current working directory. The default is the current directory.

Type: string
Default value: .

Help for force:lightning:test:create

If not supplied, the apiversion, template, and outputdir use default values.

The outputdir can be an absolute path or relative to the current working directory.

Examples:

1$ sfdx force:lightning:test:create -n MyLightningTest
1$ sfdx force:lightning:test:create -n MyLightningTest -d lightningTests

force:lightning:test:install

Installs a Lightning Testing Service (LTS) unmanaged package into your org.

Command Syntax

sfdx force:lightning:test:install
[--json]
[--loglevel LOGLEVEL]
[-u TARGETUSERNAME]
[--apiversion APIVERSION]
[-w WAIT]
[-r RELEASEVERSION]
[-t PACKAGETYPE]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-u | --targetusername TARGETUSERNAME
Optional

A username or alias for the target org. Overrides the default target org.

Type: string
--apiversion APIVERSION
Optional

Override the API version used for API requests made by this command.

Type: string
-w | --wait WAIT
Optional

Maximum number of minutes to wait for installation status.

Type: minutes
Default value: 2 minutes
-r | --releaseversion RELEASEVERSION
Optional

The release version of LTS unmanaged package you want to install.

Type: string
Default value: latest
-t | --packagetype PACKAGETYPE
Optional

Type of LTS unmanaged package to install. 'jasmine' and 'mocha' contains the essentials for development, 'full' contains both, and adds sample components and tests in the package. 'full' is best for 'kicking the tires' of LTS.

Type: enum
Permissible values are: jasmine, mocha, full
Default value: full

Help for force:lightning:test:install

Examples:

1$ sfdx force:lightning:test:install
1$ sfdx force:lightning:test:install -w 0 -r v1.0
1$ sfdx force:lightning:test:install -t jasmine

force:lightning:test:run

Runs Aura component tests. The Lightning Testing Service (LTS) unmanaged package must be installed in your org. For details, see the LTS documentation.

Command Syntax

sfdx force:lightning:test:run
[--json]
[--loglevel LOGLEVEL]
[-r RESULTFORMAT]
[-u TARGETUSERNAME]
[--apiversion APIVERSION]
[-a APPNAME]
[-d OUTPUTDIR]
[-f CONFIGFILE]
[-o]
[-t TIMEOUT]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sfdx/sfdx.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-r | --resultformat RESULTFORMAT
Optional

Format to use when displaying results. If you also specify the --json flag, --json overrides this parameter.

Type: enum
Permissible values are: human, tap, junit, json
Default value: human
-u | --targetusername TARGETUSERNAME
Optional

A username or alias for the target org. Overrides the default target org.

Type: string
--apiversion APIVERSION
Optional

Override the API version used for API requests made by this command.

Type: string
-a | --appname APPNAME
Optional

Name of your Lightning test application. The name is case insensitive, and ".app" is optional, so "Test" and "test.app" are equivalent.

Default value: Test.app

Type: string
-d | --outputdir OUTPUTDIR
Optional

Directory path to store test run artifacts: log files, test results, and so on.

Type: directory
-f | --configfile CONFIGFILE
Optional

Path to a test configuration file to configure WebDriver and other settings. For details, see the LTS documentation.

Type: filepath
-o | --leavebrowseropen
Optional

Leaves browser open after the test finishes so that you can view the test suite results.

Type: boolean
-t | --timeout TIMEOUT
Optional

Time, in milliseconds, to wait for the results element to be present in the DOM, before failing and moving on to the next test.

Type: number
Default value: 60000

Help for force:lightning:test:run

Examples:

1$ sfdx force:lightning:test:run
1$ sfdx force:lightning:test:run -a tests -r human
1$ sfdx force:lightning:test:run -f config/myConfigFile.json -d testResultFolder