fix(devkit): tree.children should support writes to directories that have the same name as their parent (#16074)
This commit is contained in:
parent
cd2f41a110
commit
63e67bf142
@ -355,6 +355,14 @@ describe('tree', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should support nested dirs with same name as parent', () => {
|
||||
tree.write('/parent-a/parent-a/parent-a-file.txt', 'parent content');
|
||||
expect(tree.children('/parent-a')).toEqual(['parent-a']);
|
||||
expect(tree.children('/parent-a/parent-a')).toEqual([
|
||||
'parent-a-file.txt',
|
||||
]);
|
||||
});
|
||||
|
||||
describe('at the root', () => {
|
||||
it('should return a list of children', () => {
|
||||
expect(tree.children('')).toEqual(['parent', 'root-file.txt']);
|
||||
|
||||
@ -403,8 +403,12 @@ export class FsTree implements Tree {
|
||||
}
|
||||
Object.keys(this.recordedChanges).forEach((f) => {
|
||||
if (f.startsWith(`${path}/`)) {
|
||||
const [_, file] = f.split(`${path}/`);
|
||||
res[file.split('/')[0]] = true;
|
||||
// Remove the current folder's path from the directory
|
||||
const file = f.substring(path.length + 1);
|
||||
// Split the path on segments, and take the first one
|
||||
const basePath = file.split('/')[0];
|
||||
// Mark it as a child of the current directory
|
||||
res[basePath] = true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user