Skip to content

Commit 78d3c7e

Browse files
committed
test: stabilize static e2e builds
1 parent ae14ffb commit 78d3c7e

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

e2e/apps-generator-mode-compare.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import postcss from 'postcss'
1111
import { describe, expect, it } from 'vitest'
1212
import { createChineseMarkdownReport, createMarkdownReport } from './apps-generator-report'
1313
import { E2E_PROJECTS, NATIVE_PROJECTS } from './projectEntries'
14+
import { clearProjectBuildState } from './projectTest'
1415
import { collectCssSnapshots, resolveSnapshotFile } from './shared'
1516

1617
type GeneratorBuildMode = 'generator' | 'legacy'
@@ -176,6 +177,7 @@ async function cleanProject(root: string) {
176177
fs.rm(path.resolve(root, 'src/node_modules/.cache/weapp-tailwindcss'), { recursive: true, force: true }),
177178
fs.rm(path.resolve(root, '.tw-patch/tailwindcss-target.json'), { force: true }),
178179
])
180+
await clearProjectBuildState(root)
179181
}
180182

181183
async function buildProject(project: CompareProject, mode: GeneratorBuildMode) {

e2e/projectTest.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,41 @@ async function safeRm(target: string) {
3939
async function clearTailwindPatchCaches(root: string) {
4040
const workspaceRoot = path.resolve(root, '..', '..')
4141
const candidates = new Set<string>([
42+
path.resolve(root, 'dist'),
43+
path.resolve(root, 'unpackage'),
4244
path.resolve(root, 'node_modules/.cache/tailwindcss-patch'),
45+
path.resolve(root, 'node_modules/.cache/weapp-tailwindcss'),
4346
path.resolve(root, 'src/node_modules/.cache/tailwindcss-patch'),
47+
path.resolve(root, 'src/node_modules/.cache/weapp-tailwindcss'),
4448
path.resolve(root, 'config/node_modules/.cache/tailwindcss-patch'),
49+
path.resolve(root, 'config/node_modules/.cache/weapp-tailwindcss'),
50+
path.resolve(root, '.tw-patch/tailwindcss-target.json'),
4551
path.resolve(root, 'node_modules/.vite'),
4652
path.resolve(workspaceRoot, 'node_modules/.cache/tailwindcss-patch'),
53+
path.resolve(workspaceRoot, 'node_modules/.cache/weapp-tailwindcss'),
4754
path.resolve(workspaceRoot, 'packages/weapp-tailwindcss/node_modules/.cache/tailwindcss-patch'),
55+
path.resolve(workspaceRoot, 'packages/weapp-tailwindcss/node_modules/.cache/weapp-tailwindcss'),
4856
])
4957

5058
await Promise.all(
5159
Array.from(candidates, target => safeRm(target)),
5260
)
5361
}
5462

63+
export async function clearProjectBuildState(root: string) {
64+
await clearTailwindPatchCaches(root)
65+
}
66+
67+
function shouldSkipAutomator(entry: ProjectEntry) {
68+
if (entry.skipOpenAutomator) {
69+
return true
70+
}
71+
if (process.env.E2E_OPEN_AUTOMATOR === '1') {
72+
return false
73+
}
74+
return process.env.CI === 'true' || process.env.CI === '1'
75+
}
76+
5577
async function expectProjectSnapshot(suite: string, projectName: string, fileName: string, content: string) {
5678
const snapshotPath = await resolveSnapshotFile(__dirname, suite, projectName, fileName)
5779
await expect(content).toMatchFileSnapshot(snapshotPath)
@@ -140,16 +162,14 @@ async function runProjectTest(entry: ProjectEntry, options: ProjectTestOptions)
140162
const root = path.resolve(projectBase, entry.name)
141163
const shouldResetPatchCaches = !entry.name.startsWith('taro-')
142164

143-
if (shouldResetPatchCaches) {
144-
await clearTailwindPatchCaches(root)
145-
}
165+
await clearProjectBuildState(root)
146166

147167
if (process.env.E2E_SKIP_BUILD !== '1') {
148168
await ensureProjectBuilt(root)
149169
}
150170

151171
if (shouldResetPatchCaches) {
152-
await clearTailwindPatchCaches(root)
172+
await clearProjectBuildState(root)
153173
}
154174

155175
let extraction
@@ -194,7 +214,7 @@ async function runProjectTest(entry: ProjectEntry, options: ProjectTestOptions)
194214
await expectProjectSnapshot(options.suite, entry.name, snapshot.fileName, snapshot.content)
195215
}
196216

197-
if (entry.skipOpenAutomator) {
217+
if (shouldSkipAutomator(entry)) {
198218
await wait()
199219
return
200220
}

0 commit comments

Comments
 (0)