fix(@angular-devkit/schematics): move rule with identity is a noop

This commit is contained in:
Charles Lyding 2018-07-25 12:35:41 -04:00 committed by Filipe Silva
parent 43b850b8cb
commit a29a53e2ff
2 changed files with 21 additions and 0 deletions

View File

@ -7,6 +7,7 @@
*/
import { normalize } from '@angular-devkit/core';
import { Rule } from '../engine/interface';
import { noop } from './base';
export function move(from: string, to?: string): Rule {
@ -18,6 +19,10 @@ export function move(from: string, to?: string): Rule {
const fromPath = normalize('/' + from);
const toPath = normalize('/' + to);
if (fromPath === toPath) {
return noop;
}
return tree => tree.visit(path => {
if (path.startsWith(fromPath)) {
tree.rename(path, toPath + '/' + path.substr(fromPath.length));

View File

@ -48,4 +48,20 @@ describe('move', () => {
})
.then(done, done.fail);
});
it('becomes a noop with identical from and to', done => {
const tree = new HostTree();
tree.create('a/b/file1', 'hello world');
tree.create('a/b/file2', 'hello world');
tree.create('a/c/file3', 'hello world');
callRule(move(''), observableOf(tree), context)
.toPromise()
.then(result => {
expect(result.exists('a/b/file1')).toBe(true);
expect(result.exists('a/b/file2')).toBe(true);
expect(result.exists('a/c/file3')).toBe(true);
})
.then(done, done.fail);
});
});