[SalesForce] sfdx force:lightning:lwc:test:run not working

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

Best Answer

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.

Related Topic