All files / bin vows.js

82.05% Statements 32/39
56.25% Branches 9/16
100% Functions 3/3
82.05% Lines 32/39

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84                                            2x   2x 2x 2x       2x   2x       2x   2x 2x 2x   2x 16x 16x 16x     16x 16x   16x   16x   16x     16x 16x 16x 16x 16x           2x 2x     2x 2x 2x 2x 2x     2x        
#!/usr/bin/env node
 
// vows.js -- command-line driver for vows test scripts
//
// Copyright 2016 fuzzy.ai <evan@fuzzy.ai>
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
 
/* jshint esversion: 6 */
 
'use strict'
 
const path = require('path')
 
const _ = require('lodash')
const async = require('async')
const debug = require('debug')('vows:command-line')
 
// This registers a hook so that coffeescript modules can be loaded
 
require('coffeescript/register')
 
const argv = require('yargs')
  .help('h')
  .argv
 
const cwd = process.cwd()
 
let broken = 0
let successes = 0
let failures = 0
 
const runTestSuite = (testFileName, callback) => {
  const testPath = path.join(cwd, testFileName)
  const runner = require(testPath)
  Iif (!_.isFunction(runner)) {
    callback(new Error(`Path ${testFileName} does not return a function`))
  } else {
    runner((err, suiteBroken, suiteSuccesses, suiteFailures) => {
      Iif (err) {
        callback(err)
      } else Iif (!_.isNumber(suiteBroken)) {
        callback(new Error(`suiteBroken for ${testFileName} should be a number, is ${suiteBroken}`))
      } else Iif (!_.isNumber(suiteSuccesses)) {
        callback(new Error(`suiteSuccesses for ${testFileName} should be a number, is ${suiteSuccesses}`))
      } else Iif (!_.isNumber(suiteFailures)) {
        callback(new Error(`suiteFailures for ${testFileName} should be a number, is ${suiteFailures}`))
      } else {
        debug(`Finished suite ${testFileName}: ${suiteBroken}, ${suiteSuccesses}, ${suiteFailures}`)
        broken += suiteBroken
        successes += suiteSuccesses
        failures += suiteFailures
        callback(null)
      }
    })
  }
}
 
async.eachSeries(argv._, runTestSuite, (err) => {
  Iif (err) {
    console.error(err)
  } else {
    console.log('SUMMARY')
    console.log(`\tBroken:\t\t${broken}`)
    console.log(`\tSuccesses:\t${successes}`)
    console.log(`\tFailures:\t${failures}`)
    Iif (broken > 0 || failures > 0) {
      process.exit(1)
    } else {
      process.exit(0)
    }
  }
})