-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
63 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
rules: { | ||
foo: true, | ||
} | ||
} |