Setup globals via karma.conf.js
See original GitHub issueIt 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:
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:
var MY_GLOBAL_API = 'some global value';
module.exports = function(config) {
var configuration = {
globals.apiEndpoint = MY_GLOBAL_API;
.....
Sort of similar to how protractor does it. I’d be happy to work on a PR.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:20
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Global variables in Karma test runner - Stack Overflow
You either declare that global variable within your test file: var global = "something"; describe('Your test suit', function() { ... });.
Read more >Configuration File - Karma
The easiest way to generate an initial configuration file is by using the karma ... The Karma configuration file can be written in...
Read more >Angular provide a global Module for testing - Developapa
Here are the snippets for Jest and Karma how to add such a module / configuration. Jest. In your jest.setup.ts/js. import 'jest-preset ...
Read more >Jest and Karma in one Angular project | by Oleg Sytnik - Medium
Here we have karma configuration (src/karma.conf.js). You can find the list of available properties and a description of what they do here.
Read more >Untitled
The recommended installation location of Karma is in your global node_modules directory. Installing Karma is done via the Node Package Manager (NPM).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think this could be a plugin rather than core functionality. It would have a config very similar to what you suggesed:
and would under the hood just generate a globals file and inject it into the files array.
Does anyone has solution of this issue since 2016 ?