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

Compatibility with pnpm #3837

Open
mjeanroy opened this issue Mar 11, 2023 · 0 comments
Open

Compatibility with pnpm #3837

mjeanroy opened this issue Mar 11, 2023 · 0 comments

Comments

@mjeanroy
Copy link

Hi everyone,

I'm a big fan of pnpm, and I wanted to use it with a project using karma as test runner and I noticed that karma was not compatible with pnpm.

I debugged my config and I found that:

  • When karma is loading plugins:
    • It try to guess the plugin directory. It works by using the lib/plugin.js directory and go two directories up to retrieve the node_modules directory (here).
    • It works with npm (and probably with yarn too) because karma is usually installed inside the project node_modules directory.
  • Unfortunately, with pnpm, it does not work like this:
    • Karma is not directly installed in the project node_modules, it is installed in a .pnpm directory inside the project node_modules directory. The directory tree will look like this:
[project]
  node_modules
    .pnpm
      [email protected]
        node_modules
          karma
            lib
              plugin.js
      [email protected]
        node_modules
          karma-chrome-launcher
    karma -> .pnpm/[email protected]/node_modules/karma
    karma-chrome-launcher -> .pnpm/[email protected]/node_modules/karma-chrome-launcher

➡️ By going two directories up, the plugin directory is then [project]/.pnpm/[email protected]/node_modules, so obviously no plugins will be detected.

A (probably very naive) fix would to use process.cwd() instead of __dirname of karma/lib/plugin.js, this way you would get the project root directory. But, as said, it's probably very naive, and I'm sure I probably miss a lot of use cases.

In any case, I'd be happy to submit PR to fix this issue if you think it's worth it.

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