Skip to content

Commit a3aa1e4

Browse files
committed
test: fix e2e watch demo regressions
1 parent 869868d commit a3aa1e4

5 files changed

Lines changed: 53 additions & 3 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ website/tests/index.spec.ts-snapshots
131131
/.playwright-cli/
132132
/.playwright-mcp/
133133
.tmp/
134+
.codex-tmp/
134135
**/.weapp-vite/
135136

136137
# Python cache

demo/gulp-tailwindcss-v4/gulpfile.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ const generator = {
5252
const { transformJs, transformWxml, transformWxss } = createPlugins({
5353
rem2rpx: true,
5454
generator,
55+
tailwindcss: {
56+
version: 4,
57+
packageName: 'tailwindcss',
58+
postcssPlugin: '@tailwindcss/postcss',
59+
},
5560
})
5661
// {
5762
// mangle: true

packages/weapp-tailwindcss/test/watch-hmr-regression.unit.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
import {
1818
buildHexScriptRoundConfigs,
1919
buildIssue33HighRiskRoundConfigs,
20+
buildTailwindV4JsContentRoundConfigs,
2021
} from '../../../tools/weapp-tailwindcss-scripts/src/watch-hmr-regression/cases/round-configs'
2122
import {
2223
resolveReportPath,
@@ -789,6 +790,32 @@ describe('watch-hmr regression cases', () => {
789790
expect(hexRound?.buildClassTokens('12345678').some(token => token.startsWith('shadow-[0_'))).toBe(true)
790791
})
791792

793+
it('keeps tailwind v4 js content rounds to tokens that produce css from script scanning', () => {
794+
const [, complexRound] = buildTailwindV4JsContentRoundConfigs()
795+
const tokens = complexRound?.buildClassTokens('123456') ?? []
796+
797+
expect(tokens).toEqual(expect.arrayContaining([
798+
'!mt-2',
799+
'-translate-y-1',
800+
'data-[state=open]:opacity-100',
801+
'[mask-type:luminance]',
802+
]))
803+
expect(tokens).not.toEqual(expect.arrayContaining([
804+
'[@supports(display:grid)]:grid',
805+
'supports-[backdrop-filter:blur(2px)]:backdrop-blur-[2px]',
806+
'[@media(any-hover:hover){&:hover}]:opacity-100',
807+
'supports-[display:grid]:grid',
808+
]))
809+
})
810+
811+
it('uses tailwind v4 js content rounds for gulp v4 script mutations', () => {
812+
const gulpV4Case = buildDemoBaseCases('/repo').find(watchCase => watchCase.name === 'gulp-tailwindcss-v4')
813+
const [, complexRound] = gulpV4Case?.scriptMutation.roundConfigs ?? []
814+
815+
expect(complexRound?.name).toBe('complex-corpus')
816+
expect(complexRound?.buildClassTokens('123456')).not.toContain('[@media(any-hover:hover){&:hover}]:opacity-100')
817+
})
818+
792819
it('tracks taro webpack v4 style outputs in both page and app wxss candidates', () => {
793820
const taroWebpackCase = buildDemoExtendedCases('/repo').find(item => item.name === 'taro-webpack-react-tailwindcss-v4')
794821

tools/weapp-tailwindcss-scripts/src/watch-hmr-regression/cases/demo/base.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
mutateVueScriptSetupObjectKeyByAnchorWithCommentCarrier,
1313
replaceExactSnippet,
1414
} from '../../text'
15-
import { buildHexScriptRoundConfigs, buildIssue33HighRiskRoundConfigs } from '../round-configs'
15+
import { buildHexScriptRoundConfigs, buildIssue33HighRiskRoundConfigs, buildTailwindV4JsContentRoundConfigs } from '../round-configs'
1616

1717
const taroWatchEnv = {
1818
TARO_BUILD_STRICT: '1',
@@ -325,7 +325,7 @@ export function buildDemoBaseCases(baseCwd: string): WatchCase[] {
325325
scriptMutation: {
326326
...gulpCase.scriptMutation,
327327
sourceFile: path.resolve(baseCwd, 'demo/gulp-tailwindcss-v4/src/pages/index/index.ts'),
328-
roundConfigs: buildHexScriptRoundConfigs(),
328+
roundConfigs: buildTailwindV4JsContentRoundConfigs(),
329329
},
330330
styleMutation: {
331331
...gulpCase.styleMutation,
@@ -369,7 +369,7 @@ export function buildDemoBaseCases(baseCwd: string): WatchCase[] {
369369
mutate(source, payload) {
370370
return replaceExactSnippet(
371371
source,
372-
'const pageClassName = \'bg-[#123456]\'',
372+
'const pageClassName = \'bg-[#d72929]\'',
373373
`const pageClassName = '${payload.classLiteral}'`,
374374
'weapp-vite script class anchor',
375375
)

tools/weapp-tailwindcss-scripts/src/watch-hmr-regression/cases/round-configs.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import {
88
} from '../mutations/tokens'
99

1010
const NON_DIGIT_RE = /\D/g
11+
const TAILWIND_V4_JS_CONTENT_UNSUPPORTED_TOKENS = new Set([
12+
'[@supports(display:grid)]:grid',
13+
'supports-[backdrop-filter:blur(2px)]:backdrop-blur-[2px]',
14+
'[@media(any-hover:hover){&:hover}]:opacity-100',
15+
'supports-[display:grid]:grid',
16+
])
1117

1218
export function buildHexScriptRoundConfigs() {
1319
const rounds = [
@@ -73,6 +79,17 @@ export function buildHexScriptRoundConfigs() {
7379
]
7480
}
7581

82+
export function buildTailwindV4JsContentRoundConfigs() {
83+
return buildHexScriptRoundConfigs().map(roundConfig => ({
84+
...roundConfig,
85+
buildClassTokens(seed: string) {
86+
return roundConfig
87+
.buildClassTokens(seed)
88+
.filter(token => !TAILWIND_V4_JS_CONTENT_UNSUPPORTED_TOKENS.has(token))
89+
},
90+
}))
91+
}
92+
7693
export function buildIssue33ScriptRoundConfigs() {
7794
return [
7895
{

0 commit comments

Comments
 (0)