|
| 1 | +import t from 'tap' |
| 2 | +import { Glob } from '../' |
| 3 | +import { bashResults } from './bash-results' |
| 4 | +import {resolve, sep} from 'path' |
| 5 | + |
| 6 | +const pattern = 'a/b/**' |
| 7 | +process.chdir(__dirname + '/fixtures') |
| 8 | + |
| 9 | +const marks = [true, false] |
| 10 | +for (const mark of marks) { |
| 11 | + t.test('mark=' + mark, t => { |
| 12 | + t.plan(3) |
| 13 | + |
| 14 | + t.test('Emits relative matches prefixed with ./', async t => { |
| 15 | + const g = new Glob(pattern, { dotRelative: true }) |
| 16 | + const results = await g.walk() |
| 17 | + |
| 18 | + t.equal( |
| 19 | + results.length, |
| 20 | + bashResults[pattern].length, |
| 21 | + 'must match all files' |
| 22 | + ) |
| 23 | + for (const m of results) { |
| 24 | + t.ok(m.startsWith('.' + sep)) |
| 25 | + } |
| 26 | + }) |
| 27 | + |
| 28 | + t.test('returns ./ prefixed matches synchronously', async t => { |
| 29 | + const g = new Glob(pattern, { dotRelative: true }) |
| 30 | + const results = g.walkSync() |
| 31 | + |
| 32 | + t.equal( |
| 33 | + results.length, |
| 34 | + bashResults[pattern].length, |
| 35 | + 'must match all files' |
| 36 | + ) |
| 37 | + for (const m of results) { |
| 38 | + t.ok(m.startsWith('.' + sep)) |
| 39 | + } |
| 40 | + }) |
| 41 | + |
| 42 | + t.test('does not prefix with ./ unless dotRelative is true', async t => { |
| 43 | + const g = new Glob(pattern, {}) |
| 44 | + const results = await g.walk() |
| 45 | + |
| 46 | + t.equal( |
| 47 | + results.length, |
| 48 | + bashResults[pattern].length, |
| 49 | + 'must match all files' |
| 50 | + ) |
| 51 | + for (const m of results) { |
| 52 | + t.ok(mark && m === '.' + sep || !m.startsWith('.' + sep)) |
| 53 | + } |
| 54 | + }) |
| 55 | + }) |
| 56 | +} |
| 57 | + |
| 58 | +t.test('does not add ./ for patterns starting in ../', async t => { |
| 59 | + t.plan(2) |
| 60 | + const pattern = '../a/b/**' |
| 61 | + const cwd = resolve(__dirname, 'fixtures/a') |
| 62 | + t.test('async', async t => { |
| 63 | + const g = new Glob(pattern, { dotRelative: true, cwd }) |
| 64 | + for await (const m of g) { |
| 65 | + t.ok(!m.startsWith('.' + sep + '..' + sep)) |
| 66 | + } |
| 67 | + }) |
| 68 | + t.test('sync', t => { |
| 69 | + const g = new Glob(pattern, { dotRelative: true, cwd }) |
| 70 | + for (const m of g) { |
| 71 | + t.ok(!m.startsWith('.' + sep + '..' + sep)) |
| 72 | + } |
| 73 | + t.end() |
| 74 | + }) |
| 75 | +}) |
0 commit comments