Skip to content

Commit

Permalink
test(tests): test for bin.js
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
sarbbottam committed Mar 18, 2016
1 parent 1136ee6 commit 19bf399
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
64 changes: 58 additions & 6 deletions test/bin.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,61 @@
import test from 'ava'
import path from 'path'
import proxyquire from 'proxyquire'

test.todo('test bin later')

try {
require('../bin') // requiring now for coverage until this is tested
} catch (error) {
// ignore the inevitable error
let rules = []
const processCwd = process.cwd
const processExit = process.exit
const consoleLog = console.log // eslint-disable-line no-console
const specifiedFile = './fixtures/.eslintrc'
const mainFile = path.join(process.cwd(), specifiedFile)
const indexStub = {
'./index': () => rules,
}
function outputStatement() {
return `New rules to add to the config: ${rules.join(', ')}.`
}

test.beforeEach((t) => {
process.argv.splice(2, process.argv.length)
process.exit = status => t.same(status, 1)
console.log = statement => t.same(statement, outputStatement()) // eslint-disable-line no-console
})

test.afterEach(() => {
process.cwd = processCwd
process.exit = processExit
console.log = consoleLog // eslint-disable-line no-console
})

test('no new rule and absolute path', () => {
process.argv[2] = mainFile
proxyquire('../bin', indexStub)
})

test('no new rule and relative path', () => {
process.argv[2] = specifiedFile
proxyquire('../bin', indexStub)
})

test('no new rule and no path', () => {
process.cwd = () => mainFile
proxyquire('../bin', indexStub)
})

test('new rule and absolute path', () => {
rules = ['foo']
process.argv[2] = mainFile
proxyquire('../bin', indexStub)
})

test('new rule and relative path', () => {
rules = ['foo', 'bar']
process.argv[2] = specifiedFile
proxyquire('../bin', indexStub)
})

test('new rule and no path', () => {
rules = ['foo', 'bar', 'baz']
process.cwd = () => mainFile
proxyquire('../bin', indexStub)
})
5 changes: 5 additions & 0 deletions test/fixtures/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
rules: {
foo: true,
}
}

0 comments on commit 19bf399

Please sign in to comment.