File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
packages/angular_devkit/schematics/src/rules Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 77 */
88import { normalize } from '@angular-devkit/core' ;
99import { Rule } from '../engine/interface' ;
10+ import { noop } from './base' ;
1011
1112
1213export 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 ) ) ;
Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments