karma-runner / karma-runner/karma

Setup globals via karma.conf.js

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

Description

It would be helpful to allow karma to setup globals in karma.conf.js via a `globals` object.
This would be, for instance, helpful with tests that run agains an API (like contract tests).

If the configuration is kept in a json file (common scenario), it currently requires a trickery like this:

``` JS
var fs = require('fs');
var MY_GLOBAL_API = 'some global value';
fs.writeFileSync('globals.js'), 'apiEndpoint = "' + MY_GLOBAL_API + '";', 'utf8');

module.exports = function(config) {

var configuration = {
files: [
'globals.js'
.....
```

It would have been a bit easier with:

``` JS
var MY_GLOBAL_API = 'some global value';
module.exports = function(config) {

var configuration = {
globals.apiEndpoint = MY_GLOBAL_API;
.....
```

Sort of similar to [how](https://github.com/angular/protractor/blob/master/docs/referenceConf.js#L255) protractor does it. I'd be happy to work on a PR.

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.