Code coverage report for lib/test.js

Statements: 100% (24 / 24)      Branches: 100% (6 / 6)      Functions: 100% (5 / 5)      Lines: 100% (24 / 24)      Ignored: none     

All files » lib/ » test.js
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 451 1 1 1 1               1   6 6 6   6 6 8 2 6 1   5       1   5   5 5 5       6 6       1
var _      = require('lodash');
var async  = require('async');
var fs     = require('fs');
var jazz   = require('jazz');
var yamljs = require('yaml-js');
 
/**
 * Load a test YAML file.
 *
 * @param {String} file: test file
 * @param {Function} cb: standard cb(err, result) callback
 */
function load(file, cb) {
 
  var params   = { _env: process.env };
  var fixtures = [];
  var tests    = [];
 
  var data = yamljs.load(fs.readFileSync(file).toString()) || [];
  data.forEach(function (item) {
    if (item.params) {
      params = _.extend(params, item.params);
    } else if (item.fixtures) {
      fixtures = fixtures.concat(item.fixtures);
    } else {
      tests.push(item);
    }
  });
 
  function iter(test, cb) {
 
    test.file = file;
 
    jazz.compile(test.command).process(params, function (data) {
      test.command = data;
      cb();
    });
  }
 
  async.each(tests, iter, function (err, results) {
    cb(err, tests, fixtures);
  });
}
 
exports.load = load;