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

Cypress does not resolve CT Framework Definition in monorepo with hoisted node_modules #25993

Closed
lmiller1990 opened this issue Mar 2, 2023 · 3 comments · Fixed by #26066
Closed
Assignees
Labels
CT Issue related to component testing

Comments

@lmiller1990
Copy link
Contributor

Current behavior

Cypress does not resolve CT Framework Definition correctly in monorepos with hoisted modules.

Desired behavior

Should correctly resolve.

Test code to reproduce

Use a monorepo, eg https://github.com/lmiller1990/ct-monorepo-bug

  • yarn install
  • notice @lmiller1990/cypress-ct-solid-js is in the root node_modules
  • cd packages/foo
  • yarn cypress open
  • Select CT
  • Notice Solid.js is NOT shown in the list

Problem is we can't just require.resolve - we first need to find all node_modules matching the cypress-ct- glob. We currently do this by globbing the projectRoot - that's where the Cypress project is currently, so in this case it'll be packages/foo/node_modules/cypress-ct-*. Code here:

const fullPathGlobs = [
path.join(projectRoot, CT_FRAMEWORK_GLOBAL_GLOB),
path.join(projectRoot, CT_FRAMEWORK_NAMESPACED_GLOB),
].map((x) => x.replaceAll('\\', '/'))
const packageJsonPaths = await globby(fullPathGlobs)
debug('Found packages matching %s glob: %o', fullPathGlobs, packageJsonPaths)

We need to recursively check up to the workspace root, I think - how you identify this, I'm not sure (eg if we are in an Nx repo, how to know the top level? Yarn monorepo? Other type of repo)?

Cypress Version

12.7.0

Node version

v16.17

Operating System

All

Debug Logs

n/a

Other

n/a

@lmiller1990 lmiller1990 added CT Issue related to component testing routed-to-ct labels Mar 2, 2023
@lmiller1990
Copy link
Contributor Author

Some ideas on how we might do this:

  • use findUp to get a list of all of the node_modules directories inside a project (could stop the search once the module has detected the git root or the location Cypress was launched from - we can say this is the top level for a project/monorepo). Then we could loop through the resulting node_modules and apply our cypress-ct-* glob against the discovered node_module directories.

@lmiller1990
Copy link
Contributor Author

Perhaps we can use this: https://github.com/stefanpenner/resolve-package-path it seems to solve this quite well.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Mar 14, 2023

Released in 12.8.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v12.8.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Mar 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CT Issue related to component testing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants