feat: add ignore option (fix #31) (#37)

- Add functionality to ignore files based on provided
regular expressions
- Support writeIndex and writeIndexCli
- in index.js config must be specified as below

    // @create-index {"ignore":["/foo.js"]}
This commit is contained in:
Dawid Karabin
2017-03-13 20:42:46 +00:00
committed by Gajus Kuizinas
parent 5fea5e63d7
commit bf45925380
20 changed files with 257 additions and 39 deletions
+56
View File
@@ -0,0 +1,56 @@
import path from 'path';
import {
expect
} from 'chai';
import readIndexConfig from '../src/utilities/readIndexConfig';
const fixtures = {
noIndex: path.resolve(__dirname, 'fixtures/read-index-config/no-index'),
withConfig: path.resolve(__dirname, 'fixtures/read-index-config/with-config'),
withInvalidConfig: path.resolve(__dirname, 'fixtures/read-index-config/with-invalid-config'),
withoutConfig: path.resolve(__dirname, 'fixtures/read-index-config/without-config')
};
const expectedValues = {
noIndex: {},
withConfig: {
ignore: ['/foo.js$/']
},
withoutConfig: {}
};
describe('readIndexConfig()', () => {
context('When valid config is defined', () => {
it('reads config object', () => {
const config = readIndexConfig(fixtures.withConfig);
expect(config).to.deep.equal(expectedValues.withConfig);
});
});
context('When invalid config is defined', () => {
it('should throw an error', () => {
const wrappedReadIndexConfig = () => {
readIndexConfig(fixtures.withInvalidConfig);
};
expect(wrappedReadIndexConfig).to.throw(/Configuration object must be a valid JSON./);
});
});
context('When config is NOT defined', () => {
it('returns an empty object', () => {
const config = readIndexConfig(fixtures.withoutConfig);
expect(config).to.deep.equal(expectedValues.withoutConfig);
});
});
context('When index file doesn\'t exist', () => {
it('returns an empty object', () => {
const config = readIndexConfig(fixtures.withoutConfig);
expect(config).to.deep.equal(expectedValues.noIndex);
});
});
});