Skip to content

Commit 5fde36a

Browse files
committed
test: expand e2e watch hot-update round coverage
1 parent 995f747 commit 5fde36a

6 files changed

Lines changed: 72 additions & 9 deletions

File tree

e2e/watch/hot-update/shared.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export type WatchProjectGroup = 'demo' | 'apps'
88
export type ConcreteWatchCaseName = 'taro' | 'uni' | 'mpx' | 'rax' | 'mina' | 'weapp-vite' | 'uni-app-vue3-vite' | 'uni-app-tailwindcss-v4' | 'taro-vite-tailwindcss-v4' | 'taro-app-vite' | 'taro-webpack-tailwindcss-v4' | 'taro-vue3-app' | 'taro-webpack' | 'vite-native-ts'
99
export type WatchCaseName = ConcreteWatchCaseName | 'both' | 'all' | 'demo' | 'apps'
1010
type MutationKind = 'template' | 'script' | 'style'
11-
type MutationRoundName = 'baseline-arbitrary' | 'complex-corpus'
11+
type MutationRoundName = 'baseline-arbitrary' | 'complex-corpus' | 'hex-arbitrary'
12+
const REQUIRED_MUTATION_ROUNDS: MutationRoundName[] = ['baseline-arbitrary', 'complex-corpus', 'hex-arbitrary']
1213

1314
interface MutationRoundReport {
1415
roundName: MutationRoundName
@@ -313,8 +314,9 @@ async function runWatchHmrCommand(cwd: string, args: string[], commandTimeoutMs:
313314
function assertHotUpdateReport(report: HotUpdateReport, target: WatchCaseName, maxHotUpdateMs: number) {
314315
expect(report.summary.count).toBeGreaterThan(0)
315316
expect(report.cases.length).toBe(report.summary.count)
316-
expect(report.summaryByRound['baseline-arbitrary']?.count).toBe(report.summary.count)
317-
expect(report.summaryByRound['complex-corpus']?.count).toBe(report.summary.count)
317+
for (const roundName of REQUIRED_MUTATION_ROUNDS) {
318+
expect(report.summaryByRound[roundName]?.count).toBe(report.summary.count)
319+
}
318320
expect(report.summaryByMutationKind.template?.count).toBe(report.summary.count)
319321
expect(report.summaryByMutationKind.script?.count).toBe(report.summary.count)
320322
expect(report.summaryByMutationKind.style?.count).toBe(report.summary.count)
@@ -339,7 +341,7 @@ function assertHotUpdateReport(report: HotUpdateReport, target: WatchCaseName, m
339341
expect(item.rollbackEffectiveMs).toBeGreaterThan(0)
340342
expect(item.classTokens.length).toBeGreaterThanOrEqual(12)
341343
expect(item.escapedClasses.length).toBe(item.classTokens.length)
342-
expect(item.rounds.length).toBe(2)
344+
expect(item.rounds.length).toBeGreaterThanOrEqual(REQUIRED_MUTATION_ROUNDS.length)
343345
expect(item.mutationMetrics.length).toBe(3)
344346
expect(item.summaryByMutationKind.template?.count).toBe(1)
345347
expect(item.summaryByMutationKind.script?.count).toBe(1)
@@ -354,12 +356,18 @@ function assertHotUpdateReport(report: HotUpdateReport, target: WatchCaseName, m
354356

355357
const baselineRound = item.rounds.find(round => round.roundName === 'baseline-arbitrary')
356358
const complexRound = item.rounds.find(round => round.roundName === 'complex-corpus')
359+
const hexRound = item.rounds.find(round => round.roundName === 'hex-arbitrary')
357360
expect(baselineRound).toBeDefined()
358361
expect(complexRound).toBeDefined()
362+
expect(hexRound).toBeDefined()
359363
expect(baselineRound?.classTokens.length).toBeGreaterThanOrEqual(7)
360364
expect(complexRound?.classTokens.length).toBeGreaterThanOrEqual(12)
365+
expect(hexRound?.classTokens.length).toBeGreaterThanOrEqual(5)
366+
expect(hexRound?.classTokens.some(token => token.startsWith('bg-[#'))).toBe(true)
361367
expect(complexRound?.hotUpdateEffectiveMs).toBeGreaterThan(0)
362368
expect(complexRound?.rollbackEffectiveMs).toBeGreaterThan(0)
369+
expect(hexRound?.hotUpdateEffectiveMs).toBeGreaterThan(0)
370+
expect(hexRound?.rollbackEffectiveMs).toBeGreaterThan(0)
363371
expect(item.roundComparison).toBeDefined()
364372
expect(item.roundComparison?.hotUpdateRatio).toBeGreaterThan(0)
365373
expect(item.roundComparison?.rollbackRatio).toBeGreaterThan(0)
@@ -395,7 +403,10 @@ function assertHotUpdateReport(report: HotUpdateReport, target: WatchCaseName, m
395403
expect(scriptMetric?.hotUpdateEffectiveMs).toBeLessThanOrEqual(maxHotUpdateMs)
396404

397405
if (templateMetric && templateMetric.mutationKind !== 'style') {
398-
expect(templateMetric.rounds.length).toBe(2)
406+
expect(templateMetric.rounds.length).toBeGreaterThanOrEqual(REQUIRED_MUTATION_ROUNDS.length)
407+
for (const roundName of REQUIRED_MUTATION_ROUNDS) {
408+
expect(templateMetric.rounds.some(round => round.roundName === roundName)).toBe(true)
409+
}
399410
expect(templateMetric.verifiedGlobalStyleEscapedClasses.length).toBeGreaterThanOrEqual(templateMetric.minRequiredGlobalStyleEscapedClasses)
400411
assertHasWxssOutput(
401412
normalizeGlobalStyleOutputs(templateMetric.globalStyleOutputs ?? templateMetric.globalStyleOutput),
@@ -404,7 +415,10 @@ function assertHotUpdateReport(report: HotUpdateReport, target: WatchCaseName, m
404415
}
405416

406417
if (scriptMetric && scriptMetric.mutationKind !== 'style') {
407-
expect(scriptMetric.rounds.length).toBe(2)
418+
expect(scriptMetric.rounds.length).toBeGreaterThanOrEqual(REQUIRED_MUTATION_ROUNDS.length)
419+
for (const roundName of REQUIRED_MUTATION_ROUNDS) {
420+
expect(scriptMetric.rounds.some(round => round.roundName === roundName)).toBe(true)
421+
}
408422
expect(scriptMetric.verifiedGlobalStyleEscapedClasses.length).toBeGreaterThanOrEqual(scriptMetric.minRequiredGlobalStyleEscapedClasses)
409423
assertHasWxssOutput(
410424
normalizeGlobalStyleOutputs(scriptMetric.globalStyleOutputs ?? scriptMetric.globalStyleOutput),

packages/weapp-tailwindcss/scripts/watch-hmr-regression/cases/apps.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ function buildHexScriptRoundConfigs() {
3838
]
3939
},
4040
},
41+
{
42+
name: 'hex-arbitrary' as const,
43+
buildClassTokens(seed: string) {
44+
const numericSeed = seed.replace(/\D/g, '').padEnd(8, '0')
45+
const hex = `${numericSeed.slice(0, 2)}00`
46+
const textPx = Number(numericSeed.slice(0, 2)) + 46
47+
const heightPx = Number(numericSeed.slice(2, 4)) + 28
48+
return [
49+
`bg-[#${hex}]`,
50+
`text-[${textPx}px]`,
51+
`h-[${heightPx}px]`,
52+
]
53+
},
54+
},
4155
]
4256
}
4357

packages/weapp-tailwindcss/scripts/watch-hmr-regression/cases/demo/extended.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ function buildHexScriptRoundConfigs() {
4141
]
4242
},
4343
},
44+
{
45+
name: 'hex-arbitrary' as const,
46+
buildClassTokens(seed: string) {
47+
const numericSeed = seed.replace(/\D/g, '').padEnd(8, '0')
48+
const hex = `${numericSeed.slice(0, 2)}00`
49+
const textPx = Number(numericSeed.slice(0, 2)) + 46
50+
const heightPx = Number(numericSeed.slice(2, 4)) + 28
51+
return [
52+
`bg-[#${hex}]`,
53+
`text-[${textPx}px]`,
54+
`h-[${heightPx}px]`,
55+
]
56+
},
57+
},
4458
]
4559
}
4660

@@ -253,6 +267,7 @@ export function buildDemoExtendedCases(baseCwd: string): WatchCase[] {
253267
sourceFile: path.resolve(baseCwd, 'demo/taro-webpack-tailwindcss-v4/src/pages/index/index.tsx'),
254268
verifyEscapedIn: ['js'],
255269
verifyClassLiteralIn: ['js'],
270+
forbidBgHexTruncationIn: ['js'],
256271
roundConfigs: buildHexScriptRoundConfigs(),
257272
mutate(source, payload) {
258273
return mutateTsxScriptByReturnAnchor(source, payload)

packages/weapp-tailwindcss/scripts/watch-hmr-regression/mutations/tokens.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ export function buildComplexCorpusClassTokens(seed: string) {
3434
]
3535
}
3636

37+
export function buildHexArbitraryClassTokens(seed: string) {
38+
const numericSeed = seed.replace(/\D/g, '').padEnd(8, '0')
39+
const hex6 = numericSeed.slice(0, 6)
40+
const hex4 = `${numericSeed.slice(0, 2)}00`
41+
const ringPx = Number(numericSeed.slice(2, 4)) + 1
42+
const spacePx = Number(numericSeed.slice(4, 6)) + 8
43+
44+
return [
45+
`bg-[#${hex4}]`,
46+
`text-[${Number(numericSeed.slice(0, 2)) + 28}px]`,
47+
`h-[${Number(numericSeed.slice(2, 4)) + 16}px]`,
48+
`ring-[${ringPx}.5px]`,
49+
`shadow-[0_${spacePx}px_${spacePx + 2}px_#${hex6}]`,
50+
]
51+
}
52+
3753
export function resolveMutationRoundConfigs(): MutationRoundConfig[] {
3854
return [
3955
{
@@ -44,5 +60,9 @@ export function resolveMutationRoundConfigs(): MutationRoundConfig[] {
4460
name: 'complex-corpus',
4561
buildClassTokens: buildComplexCorpusClassTokens,
4662
},
63+
{
64+
name: 'hex-arbitrary',
65+
buildClassTokens: buildHexArbitraryClassTokens,
66+
},
4767
]
4868
}

packages/weapp-tailwindcss/scripts/watch-hmr-regression/summary.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { promises as fs } from 'node:fs'
33
import path from 'node:path'
44
import process from 'node:process'
55
import { formatPath } from './cli'
6+
import { MUTATION_ROUND_NAMES } from './types'
67

78
interface SummarySample {
89
hotUpdateEffectiveMs: number
@@ -14,8 +15,6 @@ function resolvePreferredRound(rounds: MutationRoundMetrics[]) {
1415
?? rounds[rounds.length - 1]
1516
}
1617

17-
const MUTATION_ROUND_NAMES: MutationRoundName[] = ['baseline-arbitrary', 'complex-corpus']
18-
1918
export function summarizeSamples(samples: SummarySample[]): WatchSummary {
2019
const count = samples.length
2120
if (count === 0) {

packages/weapp-tailwindcss/scripts/watch-hmr-regression/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import type { ChildProcessWithoutNullStreams } from 'node:child_process'
33
export type WatchProjectGroup = 'demo' | 'apps'
44
export type ConcreteWatchCaseName = 'taro' | 'uni' | 'mpx' | 'rax' | 'mina' | 'weapp-vite' | 'uni-app-vue3-vite' | 'uni-app-tailwindcss-v4' | 'taro-vite-tailwindcss-v4' | 'taro-app-vite' | 'taro-webpack-tailwindcss-v4' | 'taro-vue3-app' | 'taro-webpack' | 'vite-native-ts'
55
export type WatchCaseName = ConcreteWatchCaseName | 'both' | 'all' | 'demo' | 'apps'
6-
export type MutationRoundName = 'baseline-arbitrary' | 'complex-corpus'
6+
export const MUTATION_ROUND_NAMES = ['baseline-arbitrary', 'complex-corpus', 'hex-arbitrary'] as const
7+
export type MutationRoundName = typeof MUTATION_ROUND_NAMES[number]
78
export type MutationKind = 'template' | 'script' | 'style'
89

910
export interface CliOptions {

0 commit comments

Comments
 (0)