Skip to content

Commit 6065288

Browse files
committed
test: add postcss more case
1 parent 1864f0f commit 6065288

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { getDefaultOptions } from '@/defaults'
2+
3+
describe('getDefaultOptions', () => {
4+
it('provides the expected defaults when no overrides are given', () => {
5+
const defaults = getDefaultOptions()
6+
7+
expect(defaults.cssPresetEnv?.features?.['cascade-layers']).toBe(true)
8+
expect(defaults.cssPresetEnv?.features?.['is-pseudo-class']).toEqual({ specificityMatchingName: 'weapp-tw-ig' })
9+
expect(defaults.cssPresetEnv?.features?.['custom-properties']).toBe(false)
10+
expect(defaults.cssPresetEnv?.features?.['color-mix']).toBe(true)
11+
expect(defaults.cssPresetEnv?.features?.['oklab-function']).toBe(true)
12+
expect(defaults.cssPresetEnv?.autoprefixer?.add).toBe(false)
13+
expect(defaults.cssSelectorReplacement).toEqual({ root: 'page', universal: ['view', 'text'] })
14+
expect(defaults.cssRemoveProperty).toBe(true)
15+
})
16+
17+
it('enables custom-properties preservation when cssCalc is truthy', () => {
18+
const defaults = getDefaultOptions({ cssCalc: true })
19+
20+
expect(defaults.cssPresetEnv?.features?.['custom-properties']).toEqual({ preserve: true })
21+
})
22+
23+
it('respects falsy custom-properties overrides', () => {
24+
const defaults = getDefaultOptions({
25+
cssPresetEnv: {
26+
features: {
27+
'custom-properties': false,
28+
},
29+
},
30+
})
31+
32+
expect(defaults.cssPresetEnv?.features?.['custom-properties']).toBe(false)
33+
})
34+
})
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { createInjectPreflight } from '@/preflight'
2+
3+
describe('createInjectPreflight', () => {
4+
it('stringifies values and skips disabled entries', () => {
5+
const inject = createInjectPreflight({
6+
color: 'red',
7+
fontSize: 16,
8+
border: false,
9+
opacity: 0,
10+
})
11+
12+
const result = inject()
13+
14+
expect(result).toEqual([
15+
{ prop: 'color', value: 'red' },
16+
{ prop: 'fontSize', value: '16' },
17+
{ prop: 'opacity', value: '0' },
18+
])
19+
expect(result).toBe(inject())
20+
})
21+
22+
it('returns an empty list when preflight is disabled', () => {
23+
expect(createInjectPreflight(false)()).toEqual([])
24+
expect(createInjectPreflight(undefined)()).toEqual([])
25+
})
26+
27+
it('retains boolean true values', () => {
28+
const inject = createInjectPreflight({ display: true })
29+
30+
expect(inject()).toEqual([{ prop: 'display', value: 'true' }])
31+
})
32+
})
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import type { IMangleScopeContext } from '@weapp-tailwindcss/mangle'
2+
import { composeIsPseudo, internalCssSelectorReplacer } from '@/shared'
3+
4+
describe('internalCssSelectorReplacer', () => {
5+
it('applies the default escape mapping', () => {
6+
expect(internalCssSelectorReplacer('.btn:hover>view+text')).toBe('dbtnchovergviewatext')
7+
})
8+
9+
it('respects custom escape maps', () => {
10+
const value = internalCssSelectorReplacer('view>text.btn', {
11+
escapeMap: {
12+
'.': 'DOT',
13+
'>': 'GT',
14+
},
15+
})
16+
17+
expect(value).toBe('viewGTtextDOTbtn')
18+
})
19+
20+
it('runs the mangle css handler before escaping', () => {
21+
const mangleContext = {
22+
cssHandler: (raw: string) => raw.replace('primary', 'p'),
23+
} as unknown as IMangleScopeContext
24+
25+
const value = internalCssSelectorReplacer('.primary:hover', {
26+
mangleContext,
27+
})
28+
29+
expect(value).toBe('dpchover')
30+
})
31+
})
32+
33+
describe('composeIsPseudo', () => {
34+
it('passes strings through unchanged', () => {
35+
expect(composeIsPseudo(':hover')).toBe(':hover')
36+
})
37+
38+
it('unwraps single-item arrays', () => {
39+
expect(composeIsPseudo([':focus-visible'])).toBe(':focus-visible')
40+
})
41+
42+
it('wraps multiple selectors in :is()', () => {
43+
expect(composeIsPseudo([':hover', ':focus'])).toBe(':is(:hover,:focus)')
44+
})
45+
})

0 commit comments

Comments
 (0)