@@ -13,7 +13,7 @@ export default function dataDirectory(dir, opts = {}) {
|
||||
return content
|
||||
},
|
||||
ignorePatterns: [/README\.md$/i],
|
||||
extensions: ['.json', '.md', '.markdown', '.yaml', '.yml'],
|
||||
extensions: ['.json', '.md', '.markdown', '.yml'],
|
||||
}
|
||||
|
||||
opts = Object.assign({}, defaultOpts, opts)
|
||||
@@ -53,7 +53,6 @@ export default function dataDirectory(dir, opts = {}) {
|
||||
case '.json':
|
||||
setWith(data, key, JSON.parse(fileContent), Object)
|
||||
break
|
||||
case '.yaml':
|
||||
case '.yml':
|
||||
setWith(data, key, yaml.load(fileContent, { filename }), Object)
|
||||
break
|
||||
|
||||
@@ -6,7 +6,7 @@ const fixturesDir = path.join(__dirname, 'fixtures')
|
||||
|
||||
describe('data-directory', () => {
|
||||
test('works', async () => {
|
||||
const data = await dataDirectory(fixturesDir)
|
||||
const data = dataDirectory(fixturesDir)
|
||||
const expected = {
|
||||
bar: { another_markup_language: 'yes' },
|
||||
foo: { meaningOfLife: 42 },
|
||||
@@ -19,13 +19,13 @@ describe('data-directory', () => {
|
||||
const preprocess = function (content) {
|
||||
return content.replace('markdown', 'MARKDOWN')
|
||||
}
|
||||
const data = await dataDirectory(fixturesDir, { preprocess })
|
||||
const data = dataDirectory(fixturesDir, { preprocess })
|
||||
expect(data.nested.baz).toBe('I am MARKDOWN!')
|
||||
})
|
||||
|
||||
test('option: extensions array', async () => {
|
||||
const extensions = ['.yaml', 'markdown']
|
||||
const data = await dataDirectory(fixturesDir, { extensions })
|
||||
const extensions = ['.yml', 'markdown']
|
||||
const data = dataDirectory(fixturesDir, { extensions })
|
||||
expect('bar' in data).toBe(true)
|
||||
expect('foo' in data).toBe(false) // JSON file should be ignored
|
||||
})
|
||||
@@ -34,9 +34,9 @@ describe('data-directory', () => {
|
||||
const ignorePatterns = []
|
||||
|
||||
// README is ignored by default
|
||||
expect('README' in (await dataDirectory(fixturesDir))).toBe(false)
|
||||
expect('README' in dataDirectory(fixturesDir)).toBe(false)
|
||||
|
||||
// README can be included by setting empty ignorePatterns array
|
||||
expect('README' in (await dataDirectory(fixturesDir, { ignorePatterns }))).toBe(true)
|
||||
expect('README' in dataDirectory(fixturesDir, { ignorePatterns })).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user