Search code examples
node.jsgruntjsenvironment-variableskarma-runnernode-webkit

node-webkit karma temporary environment variable


I am developing an app using node-webkit and for testing i use

https://github.com/mllrsohn/grunt-node-webkit-builder

However, it requires the presence of an environment variable named NODEWEBKIT_BIN.

Since i want my project to be runnable for anyone, i would like to set this environment variable temporarily, for the duration of the testing/building phase.

  • I have tried to see if this is possible using package.json but it is not (and it is also not recommended).
  • I have also tried to use package.json scripts to call a custom config.sh script wherein i use 'export' to export the environment variable. This has no use since the env. variable is only available in the terminal opened to run the script, and is no longer there when Karma starts the node-webkit 'browser'.
  • i have googled for karma set environment variable but that yields nothing useful as well.

Basically, is this even possible? Or should i just demand that anyone cloning my project sets this environment variable?

[edit] i am currently looking into setting process.env.NODEWEBKIT_BIN directly inside the karma.conf.js file on the first line, it looks like it might just work.


Solution

  • Awesome, this works, for anyone wondering:

    // temp set environment variable for node-webkit
    process.env.NODEWEBKIT_BIN = '/Applications/node-webkit.app/Contents/MacOS/node-webkit';
    
    module.exports = function(config){
    config.set({
    
    basePath : './',
    
    files : [
      ...
      'App/scripts/tests/**/*.js'
      ...
    ],
    
    frameworks: ['jasmine'],
    
    browsers : ['NodeWebkit'],
    
    singleRun: true
    
    });
    };