mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-16 18:43:42 +08:00
fix(@angular-devkit/schematics): move rule with identity is a noop
This commit is contained in:
parent
43b850b8cb
commit
a29a53e2ff
@ -7,6 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
import { normalize } from '@angular-devkit/core';
|
import { normalize } from '@angular-devkit/core';
|
||||||
import { Rule } from '../engine/interface';
|
import { Rule } from '../engine/interface';
|
||||||
|
import { noop } from './base';
|
||||||
|
|
||||||
|
|
||||||
export function move(from: string, to?: string): Rule {
|
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 fromPath = normalize('/' + from);
|
||||||
const toPath = normalize('/' + to);
|
const toPath = normalize('/' + to);
|
||||||
|
|
||||||
|
if (fromPath === toPath) {
|
||||||
|
return noop;
|
||||||
|
}
|
||||||
|
|
||||||
return tree => tree.visit(path => {
|
return tree => tree.visit(path => {
|
||||||
if (path.startsWith(fromPath)) {
|
if (path.startsWith(fromPath)) {
|
||||||
tree.rename(path, toPath + '/' + path.substr(fromPath.length));
|
tree.rename(path, toPath + '/' + path.substr(fromPath.length));
|
||||||
|
@ -48,4 +48,20 @@ describe('move', () => {
|
|||||||
})
|
})
|
||||||
.then(done, done.fail);
|
.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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user