Modules with the same name are not resolved correctly
JoshArgent-FF opened this issue · 0 comments
Description
getModule
does not search the packageDirectories
in sfdx-project.json
in the order I would expect. If we have a project that has two components with the same name, the resolver will return the path to the first component based on the ascending order in packageDirectories
. However, when we push the source to an org, the last component defined in packageDirectories
will overwrite the first one. I would expect the sfdx-lwc-jest
resolver to behave in the same way.
Steps to Reproduce
Setup an sfdx-project.json
with at least two packageDirectories
{
"packageDirectories": [
{
"path": "force-app",
"default": true
},
{
"path": "force-app-wip",
"default": false
}
]
}
Create two components with the same name in each package directory. When the project is pushed, the component in force-app-wip
will overwrite the other because it is defined after force-app
in packageDirectories
.
Write a jest test that imports the component using the default namespace.
import MyComponent from 'c/myComponent';
Expected Results
The imported component will be the one defined in force-app-wip
.
Actual Results
The imported component is the version defined in force-app
.
Version
- @salesforce/sfdx-lwc-jest: 0.14.0
- Node: 14.2.0
Possible Solution
If we scan the packageDirectories
in reverse order, the correct component will be resolved first.
function getModulePaths() {
if (PATHS.length > 0) return PATHS;
const packageDirectories = getSfdxProjectJson().packageDirectories.reverse();
const projectPaths = packageDirectories.map((entry) => `${entry.path}/**/lwc`);
PATHS = fg.sync(projectPaths, { onlyDirectories: true });
return PATHS;
}