karma-runner / karma-runner/karma

Consider allowing preprocessors to return a promise, instead of calling `next`

Open
#3,127 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
12k
Forks
1.7k
PR merge metrics
No merged PRs in 30d

Description

I'm wondering if the interface for preprocessor plugins might be cleaner and a little more familiar to new plugin developers, if it allowed preprocessors to return a promise that resolved with the processed content rather than requiring each preprocessor to call `next`. I believe this could easily be done in a backwards compatible way.

In the code, I believe this would look something like this:

**/lib/preprocessor.js**

```js
preprocessors.shift()(content, file, nextPreprocessor)
```

would become

```js
const maybePromise = preprocessors.shift()(content, file, nextPreprocessor)
if (maybePromise && maybePromise.then) {
maybePromise.then(
(result) => nextPreprocessor(null, result),
(error) => nextPreprocessor(error, content)
)
}
```

If this seems like a reasonable idea, I'll see about making the change and putting up a pull request.

Contributor guide

Open the contributing guide

Research direction

Start with lib/preprocessor.js and inspect the existing callback-based preprocessor flow. Determine how promise-returning preprocessors could coexist with the current next interface, including resolved content and errors, while preserving backwards compatibility. Done means both callback and promise preprocessors are supported without breaking existing plugins.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.