fix: use the basename as the entry name for static patterns
The static reader built the entry from the pattern as is, so `name` and
`dirent.name` were the whole pattern, while the dynamic reader returns
the basename. The same `objectMode: true` option therefore produced a
different entry shape depending on whether the pattern was static:
globSync('fixtures/file.md', { objectMode: true })
// name: 'fixtures/file.md', path: 'fixtures/file.md'
globSync('fixtures/*.md', { objectMode: true })
// name: 'file.md', path: 'fixtures/file.md'
Note that `path` already agreed between the two readers, only `name`
diverged. Use the basename for the entry name and for the dirent built
from the stats, which matches both the dynamic reader and the entry
builder the tests already use.
Fixes #487
This commit is contained in:
1 parent
ed3aca1ad6
commit
e246fef883
3 files changed
+45
-2
No files matched your search
@@ -77,6 +77,30 @@ describe('Readers → Reader', () => {
|
||||
assert.ok(actual.dirent.isFile());
|
||||
});
|
||||
|
||||
it('should return created entry with the basename as name when the pattern has a directory', () => {
|
||||
const reader = getReader();
|
||||
const pattern = 'directory/config.json';
|
||||
const stats = new Stats({ mode: StatsMode.File });
|
||||
|
||||
const actual = reader.makeEntry(stats, pattern);
|
||||
|
||||
assert.strictEqual(actual.name, 'config.json');
|
||||
assert.strictEqual(actual.path, pattern);
|
||||
assert.strictEqual(actual.dirent.name, 'config.json');
|
||||
});
|
||||
|
||||
it('should return created entry with the basename as name when the pattern has a leading dot segment', () => {
|
||||
const reader = getReader();
|
||||
const pattern = './config.json';
|
||||
const stats = new Stats({ mode: StatsMode.File });
|
||||
|
||||
const actual = reader.makeEntry(stats, pattern);
|
||||
|
||||
assert.strictEqual(actual.name, 'config.json');
|
||||
assert.strictEqual(actual.path, pattern);
|
||||
assert.strictEqual(actual.dirent.name, 'config.json');
|
||||
});
|
||||
|
||||
it('should return created entry with fs.Stats', () => {
|
||||
const reader = getReader({ stats: true });
|
||||
const pattern = 'config.json';
|
||||
|
||||
Reference in new issue
Block a user