Skip to content

Commit 9cd8a68

Browse files
committed
Add test for --exclude parameter
Adds tests for the current and new behavior of the `--exclude` parameter. Turns out that it didn't work as I expected it to work, namely that it doesn't accept glob patterns.
1 parent d9782c8 commit 9cd8a68

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

bin/__tests__/react-docgen-test.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,39 @@ describe('react-docgen CLI', () => {
239239
run([
240240
'--resolver='+path.join(__dirname, './example/customResolver.js'),
241241
path.join(__dirname, '../../example/components/Component.js'),
242-
]).then(([stdout, stderr]) => {
242+
]).then(([stdout]) => {
243243
expect(stdout).toContain('Custom');
244244
}),
245245
]);
246246
}, TEST_TIMEOUT);
247247
});
248248

249+
describe('--exclude/-e', () => {
250+
it('ignores files by name', () => {
251+
createTempfiles(null, 'foo');
252+
createTempfiles(null, 'bar');
253+
254+
var verify = ([stdout, stderr]) => {
255+
expect(stdout).toBe('');
256+
expect(stderr).toBe('');
257+
};
258+
259+
return run(
260+
['--exclude=Component.js', '--exclude=NoComponent.js', tempDir]
261+
).then(verify);
262+
}, TEST_TIMEOUT);
263+
264+
it('ignores files by regex', () => {
265+
createTempfiles(null, 'foo');
266+
createTempfiles(null, 'bar');
267+
268+
var verify = ([stdout, stderr]) => {
269+
expect(stdout).toBe('');
270+
expect(stderr).toBe('');
271+
};
272+
273+
return run(['--exclude=/.*Component\\.js/', tempDir]).then(verify);
274+
}, TEST_TIMEOUT);
275+
});
276+
249277
});

bin/react-docgen.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ argv
3838
['js', 'jsx'])
3939
.option(
4040
'-e, --exclude <path>',
41-
'Filename pattern to exclude. Default: ' + JSON.stringify(defaultExclude),
41+
'Filename or regex to exclude. Default: ' + JSON.stringify(defaultExclude),
4242
collect,
4343
[])
4444
.option(
@@ -130,7 +130,7 @@ function traverseDir(filePath, result, done) {
130130
{
131131
match: extensions,
132132
exclude:excludePatterns,
133-
excludeDir: ignoreDir
133+
excludeDir: ignoreDir,
134134
},
135135
function(error, content, filename, next) {
136136
if (error) {

0 commit comments

Comments
 (0)