@@ -4,26 +4,37 @@ import any from '@travi/any';
44import compareScriptNames from './script-comparator.js' ;
55
66describe ( 'script name comparator' , ( ) => {
7+ const A_AFTER_B = 1 ;
8+ const A_BEFORE_B = - 1 ;
9+ const baseScriptName = any . word ( ) ;
10+
711 it ( 'should consider undefined sort orders as equivalent' , async ( ) => {
812 expect ( compareScriptNames ( any . word ( ) , any . word ( ) ) ) . toEqual ( 0 ) ;
913 } ) ;
1014
1115 it ( 'should sort `pre` scripts ahead of their related scripts' , async ( ) => {
12- const baseScriptName = any . word ( ) ;
13- expect ( compareScriptNames ( `pre${ baseScriptName } ` , baseScriptName ) ) . toEqual ( - 1 ) ;
14- expect ( compareScriptNames ( baseScriptName , `pre${ baseScriptName } ` ) ) . toEqual ( 1 ) ;
16+ expect ( compareScriptNames ( `pre${ baseScriptName } ` , baseScriptName ) ) . toEqual ( A_BEFORE_B ) ;
17+ expect ( compareScriptNames ( baseScriptName , `pre${ baseScriptName } ` ) ) . toEqual ( A_AFTER_B ) ;
18+
19+ expect ( compareScriptNames ( 'pretest' , 'test' ) ) . toEqual ( A_BEFORE_B ) ;
20+ expect ( compareScriptNames ( 'test' , 'pretest' ) ) . toEqual ( A_AFTER_B ) ;
21+ } ) ;
22+
23+ it ( 'should sort `post` scripts after of their related scripts' , async ( ) => {
24+ expect ( compareScriptNames ( `post${ baseScriptName } ` , baseScriptName ) ) . toEqual ( A_AFTER_B ) ;
25+ expect ( compareScriptNames ( baseScriptName , `post${ baseScriptName } ` ) ) . toEqual ( A_BEFORE_B ) ;
1526
16- expect ( compareScriptNames ( 'pretest ' , 'test' ) ) . toEqual ( - 1 ) ;
17- expect ( compareScriptNames ( 'test' , 'pretest ' ) ) . toEqual ( 1 ) ;
27+ expect ( compareScriptNames ( 'posttest ' , 'test' ) ) . toEqual ( A_AFTER_B ) ;
28+ expect ( compareScriptNames ( 'test' , 'posttest ' ) ) . toEqual ( A_BEFORE_B ) ;
1829 } ) ;
1930
2031 it ( 'should sort the `test` script ahead of any sub-test scripts' , async ( ) => {
21- expect ( compareScriptNames ( 'test' , `test:${ any . word ( ) } ` ) ) . toEqual ( - 1 ) ;
22- expect ( compareScriptNames ( `test:${ any . word ( ) } ` , 'test' ) ) . toEqual ( 1 ) ;
32+ expect ( compareScriptNames ( 'test' , `test:${ any . word ( ) } ` ) ) . toEqual ( A_BEFORE_B ) ;
33+ expect ( compareScriptNames ( `test:${ any . word ( ) } ` , 'test' ) ) . toEqual ( A_AFTER_B ) ;
2334 } ) ;
2435
2536 it ( 'should sort `lint:` scripts above `test:` scripts' , async ( ) => {
26- expect ( compareScriptNames ( `lint:${ any . word ( ) } ` , `test:${ any . word ( ) } ` ) ) . toEqual ( - 1 ) ;
27- expect ( compareScriptNames ( `test:${ any . word ( ) } ` , `lint:${ any . word ( ) } ` ) ) . toEqual ( 1 ) ;
37+ expect ( compareScriptNames ( `lint:${ any . word ( ) } ` , `test:${ any . word ( ) } ` ) ) . toEqual ( A_BEFORE_B ) ;
38+ expect ( compareScriptNames ( `test:${ any . word ( ) } ` , `lint:${ any . word ( ) } ` ) ) . toEqual ( A_AFTER_B ) ;
2839 } ) ;
2940} ) ;
0 commit comments