mocha-parallel-tests icon indicating copy to clipboard operation
mocha-parallel-tests copied to clipboard

how to handle custom flags

Open MaksymDusheiko opened this issue 7 years ago • 0 comments

Trying to parallel our API tests using mocha-parallel-tests. In our testing framework, we have a config file which generates config respecting to sent flags

const argv = require("minimist")(process.argv)    
const env = argv.env || "qa";
export = {
    env: envData.env[env] as Env,
    envUsed: env,
    build: argv.build || "",
    launchName: argv.launchName || "buildName",
    loggerLevel: argv.loggerLevel || "TRACE",
	}

Runner is setuped in the main file:

const Mocha = require('mocha-parallel-tests').default;
    const suites = {
    hcs_smoke: [
       "tests/file1.js",
	   "tests/file2.js",
	   "tests/file3.js",
	   "tests/file4.js",
       ],
    }

const mochaMain = new Mocha({
    timeout: config.timeout,
    reporter: 'mocha-multi-reporters',
    reporterOptions: reporterConfig[config.mode],
    grep: config.grep,
});

// filter test cases
const pathRegExp = new RegExp(config.testTag, "i");
mochaMain.files = suites[config.suite].filter(path => path.match(pathRegExp)).map(path => "./bin/" + path);
if (mochaMain.files <= 0) {
    console.error(`Failed to found tests by pattern ${pathRegExp}`);
    process.exit(1);
}
 const runner = mochaMain.run();

Also, our tests use the config file for running through proper env. Command for run :

node main.js --suite="smoke" --env="dev" 

the issue is - the tests run through QA (default in the config file) env instead of passed in command. Am I correct that each test file run in separate process and it doesn't pass flags to that process? How could it be solved?

MaksymDusheiko avatar Aug 17 '18 07:08 MaksymDusheiko