All files / piscosour/lib/tests stepTester.js

0% Statements 0/24
0% Branches 0/8
0% Functions 0/3
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                                                                                     
'use strict';
 
const path = require('path');
const logger = require('../logger');
 
const stepper = require('../stepper');
const context = require('../context');
const _ = require('lodash');
 
let config;
 
const getConfig = () => {
  if (!config) {
    config = require('../config').setOptions({isGlobal: false, isTest: true});
  }
  return config;
};
 
const tester = {
  setLoggerLevel(level) {
    logger.setLevel(level);
  },
  loadStep(normal) {
    return getConfig().load(normal).step;
  },
  runStep(normal) {
    return new Promise((ok, ko) => {
      if (normal.baseDir) {
        getConfig().get().rootDir = path.resolve(normal.baseDir);
        process.chdir(getConfig().get().rootDir);
      }
      if (!normal.context) {
        normal.context = context.whoami(true);
      }
      normal.context = typeof normal.context === 'string' ? [ normal.context ] : normal.context;
      logger.info('#green', 'contexts:', normal.context);
      normal.params = _.mapValues(getConfig().getStepParams(normal), (params, _context) => _.merge(params, normal.params));
      stepper.execute(normal, ok, ko);
    });
  }
};
 
module.exports = tester;