wishthis/node_modules/require-dir/test/mapKey.js
2022-01-21 09:28:41 +01:00

29 lines
640 B
JavaScript

var assert = require('assert');
var requireDir = require('..');
var mapper = function(v, f) {
return f.toUpperCase();
};
// first test without recursing:
assert.deepEqual(requireDir('./recurse', { mapKey: mapper }), {
A: 'a',
});
// then test with recursing:
assert.deepEqual(requireDir('./recurse', { recurse: true, mapKey: mapper }), {
A: 'a',
B: {
'1': {
FOO: 'foo',
BAR: 'bar',
},
'2': {} // note how the directory is always returned
},
C: {
'3': 3
},
// note that node_modules was explicitly ignored
});
console.log('mapKey tests passed.');