/**
 * Common path test module.
 *
 * Check that a common path can be found for paths.
 */ import * as assert from "assert" ; import { commonPath , _splitStrings } from "../../lib/commonPath" ; describe ( "Split an array of strings at a separator" , function ( ) { describe ( "#_splitStrings" , function ( ) { it ( "should split 3 strings correctly with the default separator" , function ( ) { const items = [ "a/b/c" , "ABC/DEF/GHI" , "1/2/3" ] ; const expected = [ [ "a" , "b" , "c" ] , [ "ABC" , "DEF" , "GHI" ] , [ "1" , "2" , "3" ] , ] ; assert . deepStrictEqual ( _splitStrings ( items ) , expected ) ; } ) ; } ) ; } ) ; describe ( "Find the highest common parent directory for paths" , function ( ) { describe ( "#commonPath" , function ( ) { it ( "should give the common path for 3 root repo paths" , function ( ) { const paths = [ "foo" , "bar" , "fizz/buzz" ] ; assert . strictEqual ( commonPath ( paths ) , "repo root" ) ; } ) ; it ( "should give the common path for 2 different paths" , function ( ) { const paths = [ "Foo/test" , "Foo/bar/test" ] ; assert . strictEqual ( commonPath ( paths ) , "Foo" ) ; } ) ; it ( "should give the common path for 3 similar repo paths" , function ( ) { const paths = [ "fizz/buzz/coverage/test" , "fizz/buzz/covert/operator" , "fizz/buzz/tmp/coven/members" , ] ; assert . strictEqual ( commonPath ( paths ) , "fizz/buzz" ) ; } ) ; it ( "should give the common path for 3 related absolute paths" , function ( ) { const paths = [ "/home/user1/tmp/coverage/test" , "/home/user1/tmp/covert/operator" , "/home/user1/tmp/coven/members" , ] ; assert . strictEqual ( commonPath ( paths ) , "/home/user1/tmp" ) ; } ) ; } ) ; } ) ;