mirror of
https://github.com/toddbluhm/env-cmd.git
synced 2025-12-08 18:23:33 +00:00
Fix test coverage
This commit is contained in:
parent
39c0760630
commit
a2777a636c
21
lib/index.js
21
lib/index.js
@ -4,14 +4,6 @@ const spawn = require('cross-spawn').spawn
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
process.on('uncaughtException', function (e) {
|
||||
if (e.message.match(/passed/gi)) {
|
||||
console.log(PrintHelp())
|
||||
}
|
||||
console.log(e.message)
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
function EnvCmd (args) {
|
||||
const parsedArgs = ParseArgs(args)
|
||||
const env = ParseEnvFile(parsedArgs.envFilePath)
|
||||
@ -93,9 +85,20 @@ Options:
|
||||
`
|
||||
}
|
||||
|
||||
function HandleUncaughtExceptions (e) {
|
||||
if (e.message.match(/passed/gi)) {
|
||||
console.log(PrintHelp())
|
||||
}
|
||||
console.log(e.message)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
process.on('uncaughtException', HandleUncaughtExceptions)
|
||||
|
||||
module.exports = {
|
||||
EnvCmd,
|
||||
ParseArgs,
|
||||
ParseEnvFile,
|
||||
PrintHelp
|
||||
PrintHelp,
|
||||
HandleUncaughtExceptions
|
||||
}
|
||||
|
||||
23
test/test.js
23
test/test.js
@ -4,6 +4,7 @@ const assert = require('better-assert')
|
||||
const describe = require('mocha').describe
|
||||
const it = require('mocha').it
|
||||
const afterEach = require('mocha').afterEach
|
||||
const beforeEach = require('mocha').beforeEach
|
||||
const path = require('path')
|
||||
const proxyquire = require('proxyquire')
|
||||
const sinon = require('sinon')
|
||||
@ -21,6 +22,7 @@ const EnvCmd = lib.EnvCmd
|
||||
const ParseArgs = lib.ParseArgs
|
||||
const ParseEnvFile = lib.ParseEnvFile
|
||||
const PrintHelp = lib.PrintHelp
|
||||
const HandleUncaughtExceptions = lib.HandleUncaughtExceptions
|
||||
|
||||
describe('env-cmd', function () {
|
||||
describe('ParseArgs', function () {
|
||||
@ -109,4 +111,25 @@ describe('env-cmd', function () {
|
||||
assert(helpText.match(/-e/).length !== 0)
|
||||
})
|
||||
})
|
||||
describe('HandleUncaughtExceptions', function () {
|
||||
beforeEach(function () {
|
||||
this.logStub = sinon.stub(console, 'log')
|
||||
this.processStub = sinon.stub(process, 'exit')
|
||||
})
|
||||
afterEach(function () {
|
||||
this.logStub.restore()
|
||||
this.processStub.restore()
|
||||
})
|
||||
it('should print help text and error if error contains \'passed\'', function () {
|
||||
HandleUncaughtExceptions(new Error('print help text passed now'))
|
||||
assert(this.logStub.calledTwice)
|
||||
this.logStub.restore() // restore here so test success logs get printed
|
||||
})
|
||||
|
||||
it('should print just there error if error does not contain \'passed\'', function () {
|
||||
HandleUncaughtExceptions(new Error('do not print help text now'))
|
||||
assert(this.logStub.calledOnce)
|
||||
this.logStub.restore() // restore here so test success logs get printed
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user