karma-runner / karma-runner/karma
Compatibility with pnpm
- Dominant language
- JavaScript
- Stars
- 12k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
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](https://github.com/karma-runner/karma/blob/50f963551fbccf669c8d42499d0406ded2ec6176/lib/plugin.js#L34)).
- 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
karma@6.4.6
node_modules
karma
lib
plugin.js
karma-chrome-launcher@3.1.1
node_modules
karma-chrome-launcher
karma -> .pnpm/karma@6.4.1/node_modules/karma
karma-chrome-launcher -> .pnpm/karma-chrome-launcher@3.1.1/node_modules/karma-chrome-launcher
```
➡️ By going two directories up, the plugin directory is then `[project]/.pnpm/karma@6.4.1/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.
Contributor guide
Research direction
Start by reading lib/plugin.js and reproduce plugin loading with the pnpm node_modules layout described in the issue. Verify how the plugin directory is determined and make sure the finished change detects plugins with pnpm without breaking the existing npm-style layout.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100