Skip to content

Commit a0cc852

Browse files
committed
chore: tailwindcss unit test
1 parent 4bfc52b commit a0cc852

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

packages/weapp-tailwindcss/test/context/tailwindcss.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2860
describe('createTailwindcssPatcherFromContext', () => {

0 commit comments

Comments
 (0)