|
7 | 7 | */
|
8 | 8 | import { normalize, virtualFs } from '@angular-devkit/core';
|
9 | 9 | import { FilterHostTree, HostTree } from './host-tree';
|
| 10 | +import { MergeStrategy } from './interface'; |
10 | 11 |
|
11 | 12 | describe('HostTree', () => {
|
| 13 | + describe('merge', () => { |
| 14 | + it('should create files from each tree', () => { |
| 15 | + const tree = new HostTree(); |
| 16 | + tree.create('/file1', 'a'); |
| 17 | + const tree2 = new HostTree(); |
| 18 | + tree2.create('/file2', 'a'); |
| 19 | + tree.merge(tree2); |
| 20 | + expect(tree.actions[0].kind).toEqual('c'); |
| 21 | + expect(tree.actions[1].kind).toEqual('c'); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should overwrite if the file exists in one tree', () => { |
| 25 | + const tree = new HostTree(); |
| 26 | + tree.create('/file1', 'a'); |
| 27 | + const tree2 = new HostTree(); |
| 28 | + tree2.create('/file1', 'b'); |
| 29 | + tree.merge(tree2, MergeStrategy.Overwrite); |
| 30 | + expect(tree.actions[0].kind).toEqual('c'); |
| 31 | + }); |
12 | 32 |
|
| 33 | + it('should throw if the file exists in one tree with the correct MergeStrategy', () => { |
| 34 | + const tree = new HostTree(); |
| 35 | + tree.create('/file1', 'a'); |
| 36 | + const tree2 = new HostTree(); |
| 37 | + tree2.create('/file1', 'b'); |
| 38 | + expect(() => tree.merge(tree2)).toThrow(); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should not have a second action if the file content is the same', () => { |
| 42 | + const tree = new HostTree(); |
| 43 | + tree.create('/file1', 'a'); |
| 44 | + const tree2 = new HostTree(); |
| 45 | + tree2.create('/file1', 'a'); |
| 46 | + tree.merge(tree2, MergeStrategy.Overwrite); |
| 47 | + expect(tree.actions[0].kind).toEqual('c'); |
| 48 | + expect(tree.actions.length).toEqual(1); |
| 49 | + }); |
| 50 | + }); |
13 | 51 | });
|
14 | 52 |
|
15 | 53 | describe('FilterHostTree', () => {
|
|
0 commit comments