SalesforceLabs / SalesforceLabs/LSStarterConfig
Unit tests fail on a clean checkout: c/* LWC imports do not resolve, plus incorrect mock in lscMobileInline_SimpleWidget test
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 3
- Forks
- 3
- Avg merge
- 1m
- Merged PRs (30d)
- 4
Description
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
PackageComponentstopackageDirectoriesinsfdx-project.json(which also makes the SF CLI aware of the components), or add a JestmoduleNameMappermapping thec/namespace toPackageComponents/lwc/<name>/<name>. - Root cause 2: mock
lightning/mobileCapabilitiesexposinggetBarcodeScanner.
Happy to follow up with a PR that gets the suite to 7/7.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run npm test after a clean npm install and inspect sfdx-project.json plus the affected suites: sampleEditAccountQuickAction, sampleViewAccountQuickAction, subscribeToEvents, lscMobileInline_ParentInfo, and lscMobileInline_SimpleWidget. Verify the c/* resolver uses PackageComponents and that the SimpleWidget test mocks lightning/mobileCapabilities with getBarcodeScanner. Done means all 7 test suites pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 70/100