SalesforceLabs / SalesforceLabs/LSStarterConfig

Unit tests fail on a clean checkout: c/* LWC imports do not resolve, plus incorrect mock in lscMobileInline_SimpleWidget test

Open
#38 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Clone the repo.
  2. Run npm install.
  3. 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.