Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modules with the same name are not resolved correctly #252

Open
JoshArgent-FF opened this issue Nov 12, 2021 · 0 comments
Open

Modules with the same name are not resolved correctly #252

JoshArgent-FF opened this issue Nov 12, 2021 · 0 comments

Comments

@JoshArgent-FF
Copy link

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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant