Skip to content

Commit

Permalink
fix(tests): Use proxyquire to mock fs object instead of mocking the f…
Browse files Browse the repository at this point in the history
…ilesystem.
  • Loading branch information
ta2edchimp committed Mar 17, 2016
1 parent 91a3b9b commit 7f96704
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
"eslint": "2.4.0",
"eslint-config-kentcdodds": "6.0.0",
"ghooks": "1.0.3",
"mock-fs": "3.8.0",
"npm-run-all": "1.5.3",
"nyc": "6.1.1",
"proxyquire": "1.7.4",
"semantic-release": "4.3.5",
"validate-commit-msg": "2.4.0"
},
Expand Down
20 changes: 5 additions & 15 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import mock from 'mock-fs'
import proxyquire from 'proxyquire'
import test from 'ava'
import findNewRules from './index'

test.before(() => {
mock({
'./node_modules/eslint/lib/rules': {
'foo-rule.js': '',
'bar-rule.js': '',
'baz-thing.js': '',
},
})
})

test.after(() => {
mock.restore()
const findNewRules = proxyquire('../index', {
fs: {
readdirSync: () => ['foo-rule.js', 'bar-rule.js', 'baz-thing.js'],
},
})

test('returns the difference between what it finds in eslint/lib/rules and the rules array it is passed', t => {
Expand All @@ -26,4 +17,3 @@ test('returns an empty array if there is no difference', t => {
t.true(Array.isArray(missingRules))
t.same(missingRules.length, 0)
})

0 comments on commit 7f96704

Please sign in to comment.