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

Document Asynchronous Configurations in the Config File's Docs #3788

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion docs/config/01-configuration-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,36 @@ require('ts-node').register({
require('./karma.conf.ts');
```

### Asynchronous Configuration

The function exported by the configuration file may return a promise whose
resolution will tell Karma when all configuration is complete, including the
final call to `config.set()`.

```js
// karma.conf.js
const getAsyncConfig = require('./getAsyncConfig.js');

module.exports = async (config) => {
const asyncInfo = await getAsyncConfig()
config.set({
basePath: '../..',
frameworks: ['jasmine'],
// ... other Karma configuration
// ... including the use of `asyncInfo`
});
}
```

Just as with a synchronous configuration's return value not being used, an
asynchronous configuration's resolved value will not be used. With both
configuration types, `config.set()` MUST BE called to assign the configuration
object.

If you are using the `parseConfig` method from the public API, then please see
the [Public API Documentation][dev/public-api] for details, usage, and
addtional information.

## File Patterns
All of the configuration options, which specify file paths, use the [minimatch][minimatch] library to facilitate flexible
but concise file expressions so you can easily list all of the files you want to include and exclude.
Expand Down Expand Up @@ -526,7 +556,7 @@ The plugin must provide an express/connect middleware function (details about th
function CustomMiddlewareFactory (config) {
return function (request, response, /* next */) {
response.writeHead(200)
return response.end("content!")
return response.end('content!')
}
}
```
Expand Down Expand Up @@ -890,5 +920,6 @@ If you see this error, you can try increasing the socket connection timeout.
[config/files]: files.html
[config/browsers]: browsers.html
[config/preprocessors]: preprocessors.html
[dev/public-api]: ../dev/public-api.html
[log4js]: https://github.com/nomiddlename/log4js-node
[minimatch]: https://github.com/isaacs/minimatch