4

I have written a bunch of tests for LWC. I'm trying to run it using sfdx force:lightning:lwc:test:run but I run into:

ERROR running force:lightning:lwc:test:run: No lwc-jest executable found. Verify it is properly installed. Run "sfdx force:lightning:lwc:test:setup --help" for installation details.

I tried to install lwc-jest using @salesforce/lwc-jest looks like it's been deprecated and has been renamed to @salesforce/sfdx-lwc-jest.

Does this mean sfdx force:lightning:lwc:test:run is referencing an older module (@salesforce/lwc-jest)?

Is there a way to fix this/what am I missing here?

Note: I'm able to run tests using npm run test:unit.

Edit:

I tried installing jest using sfdx force:lightning:lwc:test:setup and ran into the below issue:

ERROR running force:lightning:lwc:test:setup: npm command not found. Verify npm is properly installed and try again.

I have installed jest using:

npm install
npm install @salesforce/sfdx-lwc-jest --save-dev

NPM version - 6.4.1

NPM Path - C:\Users\UserName\AppData\Roaming\npm\node_modules

Node Version - v10.15.1

OS - Windows

8
  • Please mention the operating system and node version you have as it works fine on MACOSX. Commented Jun 8, 2020 at 13:38
  • I agree with @MohithShrivastava, to me, it seems that npm is not on the default path of your OS. That is why sfdx force:lightning:lwc:test:setup has failed. Commented Jun 8, 2020 at 14:27
  • @MohithShrivastava NPM version 6.4.1 and OS windows. I updated my question as well.
    – d_k
    Commented Jun 8, 2020 at 14:40
  • What about node version and also what’s your default npm path? Commented Jun 8, 2020 at 14:41
  • Hi @MohithShrivastava I have added that to the question now.
    – d_k
    Commented Jun 8, 2020 at 15:35

3 Answers 3

1

You were pretty much spot on with your investigation and finding that lwc-jest has been deprecated in favor of sfdx-lwc-jest. The SFDX plugin was in fact referencing the deprecated binary.

This has just been fixed in the plugin by this PR and should be released into the main SFDX CLI via a patch release in a week or two.

1
  • Thank you! @trevorBliss
    – d_k
    Commented Jul 10, 2020 at 7:50
6

npm i @salesforce/sfdx-lwc-jest

This should do the trick

1
  • 1
    This worked for me. Ran into the same error as the original question even with latest versions of node and npm
    – Avinash
    Commented Jul 5, 2020 at 16:34
0

Either try to install using sfdx force:lightning:lwc:test:setup or if you are trying to use npm directly, you can install sfdx-lwc-jest instead of lwc-jest, see the page you referred:

This package, @salesforce/lwc-jest, has been renamed to @salesforce/sfdx-lwc-jest. Please update your projects to reference @salesforce/sfdx-lwc-jest. @salesforce/lwc-jest will continue to be updated through the Winter '20 release, then development and releases will only happen against @salesforce/sfdx-lwc-jest.

3
  • I have updated my question. @jeferson chaves
    – d_k
    Commented Jun 8, 2020 at 12:36
  • Hey, @d_k: have you removed the previous module lwc-jest? Commented Jun 8, 2020 at 12:41
  • Yes, I have removed the lwc-jest module.
    – d_k
    Commented Jun 8, 2020 at 12:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .