All files / piscosour/lib functionalTests.js

0% Statements 0/23
0% Branches 0/2
0% Functions 0/2
0% Lines 0/23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46                                                                                           
'use strict';
 
const path = require('path');
 
const logger = require('./logger');
const search =  require('./utils/search');
const fsUtils =  require('./utils/fsUtils');
const launcher = require('./utils/launcher');
const constants = require('./utils/constants');
const Waterfall = require('./utils/waterfall');
 
const tests = {
  run(ok, ko) {
    const executable = path.join(process.cwd(), 'bin', 'pisco.js');
 
    if (fsUtils.exists(executable)) {
      const testModules = search.searchByKeyword(constants.functionalTestsKeyword);
      logger.info('Number of functional testing modules detected: ', '#green', testModules.length);
      const promises = [];
 
      const execute = (module, cmd, args, options) => {
        logger.info('Executing', constants.toolName, 'functional tests from', '#cyan', module.name, '(', '#green', module.version, ')');
        return launcher.execute(cmd, args, options);
      };
 
      process.env.piscoExec = `${process.execPath} ${executable} --uuid ${constants.uuid}`;
 
      testModules.forEach((module) => {
        promises.push({
          fn: execute,
          args: [module, constants.testLauncher, ['-u', 'tdd', '--recursive', path.join(constants.npmFolder, module.name, 'test'), '--timeout', 5000], {stdio: [process.stdin, process.stdout, process.stderr]}],
          obj: this
        });
      });
      const waterfall = new Waterfall({
        promises: promises,
        logger: logger
      });
      waterfall.start().then(ok, ko);
    } else {
      logger.info('There is no executable', '#cyan', executable, '\n\n', '#yellow', 'Go to the root of a recipe and execute tests again.\n');
    }
  }
};
 
module.exports = tests;