Skip to content

Commit 69e0ee7

Browse files
committed
Add test for ignore option with trailing slashes
Fixes #160
1 parent 11dd2df commit 69e0ee7

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/globby.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,41 @@ test('expandDirectories and ignores option', async t => {
344344
}), ['tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp']);
345345
});
346346

347+
test('ignore option with trailing slashes on directories (issue #160)', async t => {
348+
const temporaryCwd = temporaryDirectory();
349+
const ignoreFirst = path.join(temporaryCwd, 'ignore-first');
350+
const ignoreSecond = path.join(temporaryCwd, 'ignore-second');
351+
const keepThis = path.join(temporaryCwd, 'keep-this.txt');
352+
353+
fs.mkdirSync(ignoreFirst);
354+
fs.mkdirSync(ignoreSecond);
355+
fs.writeFileSync(path.join(ignoreFirst, 'file.txt'), '', 'utf8');
356+
fs.writeFileSync(path.join(ignoreSecond, 'file.txt'), '', 'utf8');
357+
fs.writeFileSync(keepThis, '', 'utf8');
358+
359+
try {
360+
// Test with trailing slash on first directory
361+
const result1 = await runGlobby(t, '**/*', {
362+
cwd: temporaryCwd,
363+
ignore: ['ignore-first/', 'ignore-second'],
364+
});
365+
t.false(result1.some(file => file.includes('ignore-first')), 'ignore-first/ with trailing slash should be ignored');
366+
t.false(result1.some(file => file.includes('ignore-second')), 'ignore-second without trailing slash should be ignored');
367+
t.true(result1.includes('keep-this.txt'), 'keep-this.txt should not be ignored');
368+
369+
// Test with trailing slashes on both directories
370+
const result2 = await runGlobby(t, '**/*', {
371+
cwd: temporaryCwd,
372+
ignore: ['ignore-first/', 'ignore-second/'],
373+
});
374+
t.false(result2.some(file => file.includes('ignore-first')), 'ignore-first/ should be ignored');
375+
t.false(result2.some(file => file.includes('ignore-second')), 'ignore-second/ should be ignored');
376+
t.true(result2.includes('keep-this.txt'), 'keep-this.txt should not be ignored');
377+
} finally {
378+
fs.rmSync(temporaryCwd, {recursive: true, force: true});
379+
}
380+
});
381+
347382
test('absolute:true, expandDirectories:false, onlyFiles:false, gitignore:true and top level folder', async t => {
348383
const result = await runGlobby(t, '.', {
349384
absolute: true,

0 commit comments

Comments
 (0)