Bug Report
Describe the bug
On a fresh clone, npm test (sfdx-lwc-jest) fails 5 of 7 test suites. There are two independent root causes.
To Reproduce
- Clone the repo.
- Run
npm install.
- Run
npm test.
Expected: all suites pass. Actual: 5 suites fail to run.
Root cause 1: c/ imports do not resolve (4 suites)*
The LWC components live under PackageComponents/lwc/, but sfdx-project.json declares only force-app as a packageDirectory. The sfdx-lwc-jest resolver derives module paths from packageDirectories (using the <path>/**/lwc glob), so an import from the c/ namespace cannot be resolved for components under PackageComponents. Affected suites: sampleEditAccountQuickAction, sampleViewAccountQuickAction, subscribeToEvents, lscMobileInline_ParentInfo (each fails with Cannot find module 'c/...'). Suites that import the component via a relative path (e.g. lscMobileInline_CarouselLwc) pass.
Root cause 2: wrong mock in lscMobileInline_SimpleWidget test (1 suite)
The component imports getBarcodeScanner from lightning/mobileCapabilities, but the test mocks lightning/barcodeScanner. With no stub for lightning/mobileCapabilities, the import fails with Cannot find module 'lightning/mobileCapabilities'.
Suggested fix
- Root cause 1: add
PackageComponents to packageDirectories in sfdx-project.json (which also makes the SF CLI aware of the components), or add a Jest moduleNameMapper mapping the c/ namespace to PackageComponents/lwc/<name>/<name>.
- Root cause 2: mock
lightning/mobileCapabilities exposing getBarcodeScanner.
Happy to follow up with a PR that gets the suite to 7/7.
Bug Report
Describe the bug
On a fresh clone,
npm test(sfdx-lwc-jest) fails 5 of 7 test suites. There are two independent root causes.To Reproduce
npm install.npm test.Expected: all suites pass. Actual: 5 suites fail to run.
Root cause 1: c/ imports do not resolve (4 suites)*
The LWC components live under
PackageComponents/lwc/, butsfdx-project.jsondeclares onlyforce-appas apackageDirectory. The sfdx-lwc-jest resolver derives module paths frompackageDirectories(using the<path>/**/lwcglob), so animportfrom thec/namespace cannot be resolved for components underPackageComponents. Affected suites:sampleEditAccountQuickAction,sampleViewAccountQuickAction,subscribeToEvents,lscMobileInline_ParentInfo(each fails withCannot find module 'c/...'). Suites that import the component via a relative path (e.g.lscMobileInline_CarouselLwc) pass.Root cause 2: wrong mock in lscMobileInline_SimpleWidget test (1 suite)
The component imports
getBarcodeScannerfromlightning/mobileCapabilities, but the test mockslightning/barcodeScanner. With no stub forlightning/mobileCapabilities, the import fails withCannot find module 'lightning/mobileCapabilities'.Suggested fix
PackageComponentstopackageDirectoriesinsfdx-project.json(which also makes the SF CLI aware of the components), or add a JestmoduleNameMappermapping thec/namespace toPackageComponents/lwc/<name>/<name>.lightning/mobileCapabilitiesexposinggetBarcodeScanner.Happy to follow up with a PR that gets the suite to 7/7.