karma-runner / karma-runner/karma

[Feature request] Provide option to trigger preprocessors on any watcher event

Open
#2,736 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
12k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

This is a feature request following up on #2491.

### Problem

I'm working on a [`karma-nim-preprocessor`](https://github.com/bluenote10/karma-nim-preprocessor) to allow using Karma with the Nim programming language. The Nim compiler behaves like a bundler, i.e., compiling a `main.nim` could have dependencies on many other `.nim` files, but the output is a single `main.js`. The standard Karma configuration would look like:

```js
files: [
// the main test entry point is watched and served
'tests/main.nim',
// attempt to add watchers on all Nim sources
{
pattern: "**/*.nim",
watched: true,
served: false,
included: false
}
],
// only the main test entry point is supposed to produce JS output
preprocessors: {
'tests/main.nim': ['nim']
},
```

The problem is that the source watchers only trigger a re-run of the tests, but not a re-run of the main entry point preprocessor. This ruins the TDD experience, because Karma has to be stopped & started constantly to force the rebuild of the main entry point.

I had a look into how the rollup and webpack plugins solve this problem. Unfortunately, this can't be transferred to Nim easily, because it requires to analyze the dependencies manually, which is Nim compiler business. The problem also seems unsolved for Elm.

Overall, the current solutions to the problem are fairly involved and the problem has to be solved for any bundler-like preprocessor again. Therefore it would be nice to offer a solution from the Karma config.

### Possible solutions

Some ideas how to address the problem. Note that I'm completely new to Karma, so I don't know if they make sense.

Option 1: Maybe introducing a simple config option `rerunPreprocessorsOnChanges: true` is enough. If set to true, any change would trigger all preprocessors to re-run. This should cover the common bundler-based scenario, where there is one big preprocessor which has to be triggered on all watcher changes.

Option 2: Introduce the `rerunPreprocessorsOnChanges` on a per-preprocessor basis. This would require to use an optional object syntax for the preprocessors (similar to `files`), allowing to enable the auto-rerun only for certain preprocessors.

Option 3: Taking this a step further, the list of watched files itself could be set per preprocessor. Probably this would be too big of a change and a bit too complex.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.