Skip to content

Commit a34c9e2

Browse files
clydinfilipesilva
authored andcommitted
fix(@angular-devkit/schematics): move rule with identity is a noop
1 parent a2b298e commit a34c9e2

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

packages/angular_devkit/schematics/src/rules/move.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
import { normalize } from '@angular-devkit/core';
99
import { Rule } from '../engine/interface';
10+
import { noop } from './base';
1011

1112

1213
export function move(from: string, to?: string): Rule {
@@ -18,6 +19,10 @@ export function move(from: string, to?: string): Rule {
1819
const fromPath = normalize('/' + from);
1920
const toPath = normalize('/' + to);
2021

22+
if (fromPath === toPath) {
23+
return noop;
24+
}
25+
2126
return tree => tree.visit(path => {
2227
if (path.startsWith(fromPath)) {
2328
tree.rename(path, toPath + '/' + path.substr(fromPath.length));

packages/angular_devkit/schematics/src/rules/move_spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,20 @@ describe('move', () => {
4848
})
4949
.then(done, done.fail);
5050
});
51+
52+
it('becomes a noop with identical from and to', done => {
53+
const tree = new HostTree();
54+
tree.create('a/b/file1', 'hello world');
55+
tree.create('a/b/file2', 'hello world');
56+
tree.create('a/c/file3', 'hello world');
57+
58+
callRule(move(''), observableOf(tree), context)
59+
.toPromise()
60+
.then(result => {
61+
expect(result.exists('a/b/file1')).toBe(true);
62+
expect(result.exists('a/b/file2')).toBe(true);
63+
expect(result.exists('a/c/file3')).toBe(true);
64+
})
65+
.then(done, done.fail);
66+
});
5167
});

0 commit comments

Comments
 (0)