1+ /* eslint-disable @typescript-eslint/no-unsafe-call */
12jest . mock ( './getCachedItemPath' , ( ) =>
23 jest . fn (
34 ( ) =>
45 '/home/uname/.emulsify/cache/systems/12345/compound/components/00-base/colors' ,
56 ) ,
67) ;
78import { copy , remove } from 'fs-extra' ;
9+ import getEmulsifyConfig from '../project/getEmulsifyConfig' ;
810import copyItemFromCache from './copyItemFromCache' ;
911
12+ // Mock the getEmulsifyConfig function
13+ jest . mock ( '../project/getEmulsifyConfig' , ( ) => jest . fn ( ) ) ;
14+
1015describe ( 'copyItemFromCache' , ( ) => {
16+ const mockConfig = {
17+ system : {
18+ checkout : 'checkoutBranch' ,
19+ } ,
20+ } ;
21+
22+ beforeEach ( ( ) => {
23+ jest . clearAllMocks ( ) ;
24+ ( getEmulsifyConfig as jest . Mock ) . mockResolvedValue ( mockConfig ) ; // Ensure proper casting
25+ } ) ;
26+
1127 it ( 'can copy an item from cache to the given destination' , async ( ) => {
1228 await copyItemFromCache (
1329 'systems' ,
@@ -19,6 +35,7 @@ describe('copyItemFromCache', () => {
1935 '/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors' ,
2036 ) ;
2137 } ) ;
38+
2239 it ( 'can remove a destination before copying items from the cache if "force" is true' , async ( ) => {
2340 await copyItemFromCache (
2441 'systems' ,
@@ -30,4 +47,34 @@ describe('copyItemFromCache', () => {
3047 '/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors' ,
3148 ) ;
3249 } ) ;
50+
51+ it ( 'should handle missing emulsifyConfig system checkout' , async ( ) => {
52+ ( getEmulsifyConfig as jest . Mock ) . mockResolvedValue ( { system : { } } ) ;
53+
54+ await copyItemFromCache (
55+ 'systems' ,
56+ [ 'compound' , 'components' , '00-base' , 'colors' ] ,
57+ '/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors' ,
58+ ) ;
59+
60+ expect ( copy ) . toHaveBeenCalledWith (
61+ '/home/uname/.emulsify/cache/systems/12345/compound/components/00-base/colors' ,
62+ '/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors' ,
63+ ) ;
64+ } ) ;
65+
66+ it ( 'should handle undefined emulsifyConfig' , async ( ) => {
67+ ( getEmulsifyConfig as jest . Mock ) . mockResolvedValue ( undefined ) ;
68+
69+ await copyItemFromCache (
70+ 'systems' ,
71+ [ 'compound' , 'components' , '00-base' , 'colors' ] ,
72+ '/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors' ,
73+ ) ;
74+
75+ expect ( copy ) . toHaveBeenCalledWith (
76+ '/home/uname/.emulsify/cache/systems/12345/compound/components/00-base/colors' ,
77+ '/home/uname/Projects/drupal/web/themes/custom/cornflake/components/00-base/colors' ,
78+ ) ;
79+ } ) ;
3380} ) ;
0 commit comments