Skip to content

Commit

Permalink
[#59] Add tests for the optional extensions parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
richardgarnier committed Nov 26, 2018
1 parent 608ebe5 commit 8b8744f
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var assert = require('assert');
var requireDir = require('..');

// first test regularly:
assert.deepEqual(requireDir('./simple'), {
a: 'a',
b: 'b',
});

// only js files
assert.deepEqual(requireDir('./simple', {extensions: ['.js']}), {
a: 'a'
});

// both js and json files
assert.deepEqual(requireDir('./simple', {extensions: ['.js', '.json']}), {
a: 'a',
b: 'b'
});

// then test with recursing:
assert.deepEqual(requireDir('./recurse', {recurse: true, extensions: ['.js']}), {
a: 'a',
b: {
'1': {
foo: 'foo'
},
'2': {} // note how the directory is always returned
},
c: {}
// note that node_modules was explicitly ignored
});

console.log('Extensions tests passed.');

0 comments on commit 8b8744f

Please sign in to comment.