Skip to content

Commit 1af8dc1

Browse files
author
Kent C. Dodds
committed
Merge pull request #8 from ta2edchimp/ava-bug
Use proxyquire to mock fs object ...
2 parents c2fb726 + 977b631 commit 1af8dc1

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
"eslint": "2.4.0",
3838
"eslint-config-kentcdodds": "6.0.0",
3939
"ghooks": "1.0.3",
40-
"mock-fs": "3.8.0",
4140
"npm-run-all": "1.5.3",
4241
"nyc": "6.1.1",
42+
"proxyquire": "1.7.4",
4343
"semantic-release": "4.3.5",
4444
"validate-commit-msg": "2.4.0"
4545
},

test/bin.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import test from 'ava'
2+
3+
test.todo('test bin later')
4+
5+
try {
6+
require('../bin') // requiring now for coverage until this is tested
7+
} catch (error) {
8+
// ignore the inevitable error
9+
}

test.js renamed to test/index.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
1-
import mock from 'mock-fs'
1+
import proxyquire from 'proxyquire'
22
import test from 'ava'
3-
import findNewRules from './index'
43

5-
try {
6-
require('./bin') // requiring now for coverage until this is tested
7-
} catch (error) {
8-
// ignore the inevitable error
9-
}
10-
11-
test.before(() => {
12-
mock({
13-
'./node_modules/eslint/lib/rules': {
14-
'foo-rule.js': '',
15-
'bar-rule.js': '',
16-
'baz-thing.js': '',
17-
},
18-
})
19-
})
20-
21-
test.after(() => {
22-
mock.restore()
4+
const findNewRules = proxyquire('../index', {
5+
fs: {
6+
readdirSync: () => ['foo-rule.js', 'bar-rule.js', 'baz-thing.js'],
7+
},
238
})
249

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

0 commit comments

Comments
 (0)