@@ -23,6 +23,38 @@ describe('resolveTailwindcssBasedir', () => {
2323
2424 expect ( resolveTailwindcssBasedir ( ) ) . toBe ( path . normalize ( '/workspace/apps/vite-native-skyline' ) )
2525 } )
26+
27+ it ( 'resolves relative base against generic env anchor (prefers INIT_CWD over PWD)' , async ( ) => {
28+ process . env . PWD = '/anchor/from-pwd'
29+ process . env . INIT_CWD = '/ignored-init-cwd'
30+ const { resolveTailwindcssBasedir } = await import ( '@/context/tailwindcss' )
31+
32+ expect ( resolveTailwindcssBasedir ( './apps/demo' ) ) . toBe ( path . normalize ( '/ignored-init-cwd/apps/demo' ) )
33+ } )
34+
35+ it ( 'falls back to PWD when INIT_CWD is absent' , async ( ) => {
36+ process . env . PWD = '/anchor/from-pwd-only'
37+ delete process . env . INIT_CWD
38+ const { resolveTailwindcssBasedir } = await import ( '@/context/tailwindcss' )
39+
40+ expect ( resolveTailwindcssBasedir ( './apps/demo' ) ) . toBe ( path . normalize ( '/anchor/from-pwd-only/apps/demo' ) )
41+ } )
42+
43+ it ( 'prefers specific base env over generic anchors' , async ( ) => {
44+ process . env . PWD = '/generic/pwd'
45+ process . env . WEAPP_TAILWINDCSS_BASEDIR = '/specific/base'
46+ const { resolveTailwindcssBasedir } = await import ( '@/context/tailwindcss' )
47+
48+ expect ( resolveTailwindcssBasedir ( './tailwind' ) ) . toBe ( path . normalize ( '/specific/base/tailwind' ) )
49+ } )
50+
51+ it ( 'falls back to provided fallback when env not set' , async ( ) => {
52+ delete process . env . PWD
53+ delete process . env . INIT_CWD
54+ const { resolveTailwindcssBasedir } = await import ( '@/context/tailwindcss' )
55+
56+ expect ( resolveTailwindcssBasedir ( undefined , '/custom/fallback' ) ) . toBe ( path . normalize ( '/custom/fallback' ) )
57+ } )
2658} )
2759
2860describe ( 'createTailwindcssPatcherFromContext' , ( ) => {
0 commit comments