2015-05-21 12:07:52 -04:00
/// <reference path="../typings/node/node.d.ts" />
/// <reference path="../typings/jasmine/jasmine.d.ts" />
2015-09-26 02:13:37 -04:00
console . warn (
"Skipping all tests in broccoli-merge-trees.spec.ts because they require mock-fs which is currently incompatible with node 4.x. See: https://github.com/tschaub/mock-fs/issues/59" ) ;
/ *
2015-05-21 12:07:52 -04:00
let mockfs = require ( 'mock-fs' ) ;
import fs = require ( 'fs' ) ;
import { TreeDiffer } from './tree-differ' ;
import { MergeTrees } from './broccoli-merge-trees' ;
describe ( 'MergeTrees' , ( ) = > {
afterEach ( ( ) = > mockfs . restore ( ) ) ;
function mergeTrees ( inputPaths , cachePath , options ) {
return new MergeTrees ( inputPaths , cachePath , options ) ;
}
function MakeTreeDiffers ( rootDirs ) {
let treeDiffers = rootDirs . map ( ( rootDir ) = > new TreeDiffer ( 'MergeTrees' , rootDir ) ) ;
treeDiffers . diffTrees = ( ) = > { return treeDiffers . map ( tree = > tree . diffTree ( ) ) ; } ;
return treeDiffers ;
}
function read ( path ) { return fs . readFileSync ( path , "utf-8" ) ; }
2015-06-04 17:39:53 -04:00
it ( 'should copy the file from the right-most inputTree with overwrite=true' , ( ) = > {
2015-05-21 12:07:52 -04:00
let testDir : any = {
'tree1' : { 'foo.js' : mockfs . file ( { content : 'tree1/foo.js content' , mtime : new Date ( 1000 ) } ) } ,
'tree2' : { 'foo.js' : mockfs . file ( { content : 'tree2/foo.js content' , mtime : new Date ( 1000 ) } ) } ,
'tree3' : { 'foo.js' : mockfs . file ( { content : 'tree3/foo.js content' , mtime : new Date ( 1000 ) } ) }
} ;
mockfs ( testDir ) ;
let treeDiffer = MakeTreeDiffers ( [ 'tree1' , 'tree2' , 'tree3' ] ) ;
2015-06-04 17:39:53 -04:00
let treeMerger = mergeTrees ( [ 'tree1' , 'tree2' , 'tree3' ] , 'dest' , { overwrite : true } ) ;
2015-05-21 12:07:52 -04:00
treeMerger . rebuild ( treeDiffer . diffTrees ( ) ) ;
expect ( read ( 'dest/foo.js' ) ) . toBe ( 'tree3/foo.js content' ) ;
delete testDir . tree2 [ 'foo.js' ] ;
delete testDir . tree3 [ 'foo.js' ] ;
mockfs ( testDir ) ;
treeMerger . rebuild ( treeDiffer . diffTrees ( ) ) ;
expect ( read ( 'dest/foo.js' ) ) . toBe ( 'tree1/foo.js content' ) ;
testDir . tree2 [ 'foo.js' ] = mockfs . file ( { content : 'tree2/foo.js content' , mtime : new Date ( 1000 ) } ) ;
mockfs ( testDir ) ;
treeMerger . rebuild ( treeDiffer . diffTrees ( ) ) ;
expect ( read ( 'dest/foo.js' ) ) . toBe ( 'tree2/foo.js content' ) ;
} ) ;
2015-06-04 17:39:53 -04:00
2015-05-31 20:24:21 -04:00
it ( 'should throw if duplicates are found during the initial build' , ( ) = > {
2015-06-04 17:39:53 -04:00
let testDir : any = {
'tree1' : { 'foo.js' : mockfs . file ( { content : 'tree1/foo.js content' , mtime : new Date ( 1000 ) } ) } ,
'tree2' : { 'foo.js' : mockfs . file ( { content : 'tree2/foo.js content' , mtime : new Date ( 1000 ) } ) } ,
'tree3' : { 'foo.js' : mockfs . file ( { content : 'tree3/foo.js content' , mtime : new Date ( 1000 ) } ) }
} ;
mockfs ( testDir ) ;
let treeDiffer = MakeTreeDiffers ( [ 'tree1' , 'tree2' , 'tree3' ] ) ;
let treeMerger = mergeTrees ( [ 'tree1' , 'tree2' , 'tree3' ] , 'dest' , { } ) ;
2015-06-12 10:50:45 -04:00
expect ( ( ) = > treeMerger . rebuild ( treeDiffer . diffTrees ( ) ) )
2015-06-16 12:24:29 -04:00
. toThrowError (
'Duplicate path found while merging trees. Path: "foo.js".\n' +
'Either remove the duplicate or enable the "overwrite" option for this merge.' ) ;
2015-06-04 17:39:53 -04:00
2015-05-31 20:24:21 -04:00
testDir = {
'tree1' : { 'foo.js' : mockfs . file ( { content : 'tree1/foo.js content' , mtime : new Date ( 1000 ) } ) } ,
'tree2' : { } ,
'tree3' : { }
} ;
mockfs ( testDir ) ;
} ) ;
it ( 'should throw if duplicates are found during rebuild' , ( ) = > {
let testDir = {
'tree1' : { 'foo.js' : mockfs . file ( { content : 'tree1/foo.js content' , mtime : new Date ( 1000 ) } ) } ,
'tree2' : { } ,
'tree3' : { }
} ;
2015-06-04 17:39:53 -04:00
mockfs ( testDir ) ;
2015-05-31 20:24:21 -04:00
let treeDiffer = MakeTreeDiffers ( [ 'tree1' , 'tree2' , 'tree3' ] ) ;
let treeMerger = mergeTrees ( [ 'tree1' , 'tree2' , 'tree3' ] , 'dest' , { } ) ;
2015-06-04 17:39:53 -04:00
expect ( ( ) = > treeMerger . rebuild ( treeDiffer . diffTrees ( ) ) ) . not . toThrow ( ) ;
2015-05-31 20:24:21 -04:00
2015-06-04 17:39:53 -04:00
testDir . tree2 [ 'foo.js' ] = mockfs . file ( { content : 'tree2/foo.js content' , mtime : new Date ( 1000 ) } ) ;
mockfs ( testDir ) ;
2015-06-12 10:50:45 -04:00
expect ( ( ) = > treeMerger . rebuild ( treeDiffer . diffTrees ( ) ) )
2015-06-16 12:24:29 -04:00
. toThrowError (
'Duplicate path found while merging trees. Path: "foo.js".\n' +
'Either remove the duplicate or enable the "overwrite" option for this merge.' ) ;
2015-06-04 17:39:53 -04:00
} ) ;
2015-05-21 12:07:52 -04:00
} ) ;
2015-09-26 02:13:37 -04:00
* /