-
-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: #495
- Loading branch information
Showing
5 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 9.1 | ||
|
||
- Add `dotRelative` option | ||
|
||
## 9.0 | ||
|
||
This is a full rewrite, with significant API and algorithm | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import t from 'tap' | ||
import { Glob } from '../' | ||
import { bashResults } from './bash-results' | ||
import {resolve, sep} from 'path' | ||
|
||
const pattern = 'a/b/**' | ||
process.chdir(__dirname + '/fixtures') | ||
|
||
const marks = [true, false] | ||
for (const mark of marks) { | ||
t.test('mark=' + mark, t => { | ||
t.plan(3) | ||
|
||
t.test('Emits relative matches prefixed with ./', async t => { | ||
const g = new Glob(pattern, { dotRelative: true }) | ||
const results = await g.walk() | ||
|
||
t.equal( | ||
results.length, | ||
bashResults[pattern].length, | ||
'must match all files' | ||
) | ||
for (const m of results) { | ||
t.ok(m.startsWith('.' + sep)) | ||
} | ||
}) | ||
|
||
t.test('returns ./ prefixed matches synchronously', async t => { | ||
const g = new Glob(pattern, { dotRelative: true }) | ||
const results = g.walkSync() | ||
|
||
t.equal( | ||
results.length, | ||
bashResults[pattern].length, | ||
'must match all files' | ||
) | ||
for (const m of results) { | ||
t.ok(m.startsWith('.' + sep)) | ||
} | ||
}) | ||
|
||
t.test('does not prefix with ./ unless dotRelative is true', async t => { | ||
const g = new Glob(pattern, {}) | ||
const results = await g.walk() | ||
|
||
t.equal( | ||
results.length, | ||
bashResults[pattern].length, | ||
'must match all files' | ||
) | ||
for (const m of results) { | ||
t.ok(mark && m === '.' + sep || !m.startsWith('.' + sep)) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
t.test('does not add ./ for patterns starting in ../', async t => { | ||
t.plan(2) | ||
const pattern = '../a/b/**' | ||
const cwd = resolve(__dirname, 'fixtures/a') | ||
t.test('async', async t => { | ||
const g = new Glob(pattern, { dotRelative: true, cwd }) | ||
for await (const m of g) { | ||
t.ok(!m.startsWith('.' + sep + '..' + sep)) | ||
} | ||
}) | ||
t.test('sync', t => { | ||
const g = new Glob(pattern, { dotRelative: true, cwd }) | ||
for (const m of g) { | ||
t.ok(!m.startsWith('.' + sep + '..' + sep)) | ||
} | ||
t.end() | ||
}) | ||
}) |