Friday, 5 May 2017

Node module not accepting arguments and running twice

I'm having some very strange behaviour running test scripts through yarn or npm using selenium web driver with chai and mocha.

  1. Neither yarn nor npm seem to recognize my custom arguments when processed through process.argv.forEach

  2. My script runs two times when passed through yarn but only once through npm.

This is the command line function I run through powershell

yarn run test-module-a -- --host=192.168.1.1

or

npm run test-module-a -- --host=192.168.1.1

This is my package.json relevant excerpt. Here I define my test and pretest. I don't even question how pretest knows to run before test, but it does...

{ 
   "scripts" : {
       "kill-selenium": "kill -16 $( lsof -i:4444 -t )",
       "help" : "./node_modules/.bin/wdio --help",
       "pretest-module-a" : "start powershell -nologo -noexit -Command \"java -jar selenium-server-standalone-3.4.0.jar\"",
       "test-module-a" : "./node_modules/.bin/wdio ./specs/moduleA/wdio.conf.js"
}

For the test scripts, I have a lot of various modules that inherit from a base module, and they all have their own branches and trunks. So I took the original wdio.conf.js file that comes with wdio and tried to add some pre processing and convenient exports/functions so that other wdio.conf.js scripts could require it and change some settings through a setup function.

This is the main wdio.conf.js, which is basically the same as the default, but I've added these functions/variables to the top.

var host = "";

process.argv.forEach(function(val, index, array){
   console.log(index + ": " + val);
   // 0 : node.exe path
   // 1 : webdriver path
   // 2 : wdio.conf.js path
   // SHOULD PRINT 3 : --host=x.x.x.x  BUT IT DOES NOT
});

// these paths will be used for specific test scripts
// and are generated here for convenience
exports.basePath = "";
exports.prodPath = "";

// this function is called in each product's specific test script
exports.setup = function(product, branch){
   exports.basePath = CONST.SPECS + "base/" + branch;
   exports.prodPath = CONST.SPECS + product + branch;
   console.log("Starting test suite for " product + " " + branch);
   console.log("Running on host " + host);
};

exports.host = host;
exports.config = {
   // the default config stuff for this package is more or less untouched
};

This is my wdio.conf.js for module a

// require the main wdio conf script
var exports = require('../../wdio.conf.js');

var product = "moduleA/";
var branch = "trunk/"

exports.setup(product, branch);

exports.config.specs = [
   // list of scripts
];



via yallo

No comments:

Post a Comment