@@ -9,14 +9,21 @@ const readFile = async (path: string): Promise<string> => {
99 readFile1 ( path , ( _ , data ) => res ( data . toString ( ) ) ) ,
1010 ) ;
1111} ;
12+
1213const removeWhitespace = ( str : string ) => str . replace ( / \s / g, "" ) ;
14+
1315vi . mock ( "fs/promises" , ( ) => {
1416 return {
1517 readFile : async ( name : string ) => {
1618 if ( name === "app.config.ts" ) {
19+ const sampleConfig : string = await readFile ( "./packages/commands/tests/assets/sample_app_config.txt" ) ;
20+ return sampleConfig ;
21+ }
22+ if ( name === "vite.config.ts" ) {
1723 const sampleConfig : string = await readFile ( "./packages/commands/tests/assets/sample_vite_config.txt" ) ;
1824 return sampleConfig ;
1925 }
26+
2027 return "{}" ;
2128 } ,
2229 writeFile : async ( _ , contents : string ) => {
@@ -46,22 +53,41 @@ vi.mock("@solid-cli/utils/updates", async () => {
4653
4754vi . mock ( "../src/lib/utils/helpers.ts" , async ( ) => {
4855 return {
49- getConfigFile : async ( ) : Promise < string > => new Promise ( ( r ) => r ( "app.config.ts" ) ) ,
50- fileExists : ( path : string ) => path . includes ( "app_config" ) || path . includes ( "app.tsx" ) || path . includes ( "index.tsx" ) ,
56+ getConfigFile : async ( file : string ) : Promise < string > => new Promise ( ( r ) => r ( `${ file } .config.ts` ) ) ,
57+ fileExists : ( path : string ) =>
58+ path . includes ( "vite_config" ) ||
59+ path . includes ( "app_config" ) ||
60+ path . includes ( "app.tsx" ) ||
61+ path . includes ( "index.tsx" ) ,
5162 getRootFile : async ( ) : Promise < string > => new Promise ( ( r ) => r ( "./src/app.tsx" ) ) ,
5263 } ;
5364} ) ;
65+
66+ let testingSolidStart = false ;
67+
68+ vi . mock ( "@solid-cli/utils" , async ( ) => {
69+ return {
70+ isSolidStart : async ( ) => new Promise ( ( r ) => r ( testingSolidStart ) ) ,
71+ } ;
72+ } ) ;
73+
5474describe ( "Update config" , ( ) => {
55- it (
56- "Adds a plugin properly to the config" ,
57- async ( ) => {
58- await handleAdd ( [ "unocss" ] ) ;
75+ it ( "Adds a plugin properly to the app config" , { timeout : 50000 } , async ( ) => {
76+ testingSolidStart = true ;
77+ await handleAdd ( [ "unocss" ] ) ;
5978
60- const expected = await readFile ( "./packages/commands/tests/assets/sample_unocss_result.txt" ) ;
61- // @ts -ignore
62- const newConfig = UPDATESQUEUE . find ( ( u ) => u . name === "app.config.ts" ) ?. contents ;
63- expect ( removeWhitespace ( expected ) ) . toBe ( removeWhitespace ( newConfig ) ) ;
64- } ,
65- { timeout : 50000 } ,
66- ) ;
79+ const expected = await readFile ( "./packages/commands/tests/assets/sample_unocss_app_result.txt" ) ;
80+ // @ts -ignore
81+ const newConfig = UPDATESQUEUE . find ( ( u ) => u . name === "app.config.ts" ) ?. contents ;
82+ expect ( removeWhitespace ( newConfig ) ) . toBe ( removeWhitespace ( expected ) ) ;
83+ } ) ;
84+ it ( "Adds a plugin properly to the vite config" , { timeout : 50000 } , async ( ) => {
85+ testingSolidStart = false ;
86+ await handleAdd ( [ "unocss" ] ) ;
87+
88+ const expected = await readFile ( "./packages/commands/tests/assets/sample_unocss_vite_result.txt" ) ;
89+ // @ts -ignore
90+ const newConfig = UPDATESQUEUE . find ( ( u ) => u . name === "vite.config.ts" ) ?. contents ;
91+ expect ( removeWhitespace ( newConfig ) ) . toBe ( removeWhitespace ( expected ) ) ;
92+ } ) ;
6793} ) ;
0 commit comments