|
| 1 | +import fs from 'node:fs' |
| 2 | +import path from 'node:path' |
| 3 | +import { fileURLToPath } from 'node:url' |
| 4 | +import { describe, expect, it } from 'vitest' |
| 5 | +import YAML from 'yaml' |
| 6 | + |
| 7 | +const dirname = path.dirname(fileURLToPath(import.meta.url)) |
| 8 | +const repoRoot = path.resolve(dirname, '../../../..') |
| 9 | +const workflowsRoot = path.join(repoRoot, '.github/workflows') |
| 10 | + |
| 11 | +function readWorkflow(filename: string) { |
| 12 | + const source = fs.readFileSync(path.join(workflowsRoot, filename), 'utf8') |
| 13 | + return { |
| 14 | + source, |
| 15 | + workflow: YAML.parse(source) as Record<string, any>, |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +function stepRuns(workflow: Record<string, any>, jobName: string) { |
| 20 | + const steps: Array<Record<string, unknown>> = workflow.jobs[jobName].steps |
| 21 | + return steps |
| 22 | + .map(step => step.run) |
| 23 | + .filter((run): run is string => typeof run === 'string') |
| 24 | +} |
| 25 | + |
| 26 | +function extractJsonArrays(source: string) { |
| 27 | + return [...source.matchAll(/\[\{.*?\}\]/g)].map((match) => { |
| 28 | + return JSON.parse(match[0]) as Array<Record<string, unknown>> |
| 29 | + }) |
| 30 | +} |
| 31 | + |
| 32 | +function matrixIds(rows: Array<Record<string, unknown>>) { |
| 33 | + return rows.map((row) => { |
| 34 | + return `${row.os}:${row['node-version']}:${row.scenario}` |
| 35 | + }) |
| 36 | +} |
| 37 | + |
| 38 | +function matrixCases(rows: Array<Record<string, unknown>>) { |
| 39 | + return rows.map((row) => { |
| 40 | + const nodeVersion = row['node-version'] ?? 22 |
| 41 | + return `${row.runner_label}:${nodeVersion}:${row.watch_case}:${row.round_profile}` |
| 42 | + }) |
| 43 | +} |
| 44 | + |
| 45 | +describe('ci workflows', () => { |
| 46 | + it('keeps the core CI quality gate on package changes', () => { |
| 47 | + const { workflow } = readWorkflow('ci.yml') |
| 48 | + |
| 49 | + expect(workflow.on.pull_request['paths-ignore']).toEqual(expect.arrayContaining([ |
| 50 | + 'website/**', |
| 51 | + '**/*.md', |
| 52 | + '.changeset/**', |
| 53 | + ])) |
| 54 | + |
| 55 | + expect(stepRuns(workflow, 'quality')).toEqual(expect.arrayContaining([ |
| 56 | + 'pnpm install --frozen-lockfile', |
| 57 | + 'pnpm lint', |
| 58 | + 'pnpm build', |
| 59 | + 'pnpm test', |
| 60 | + ])) |
| 61 | + }) |
| 62 | + |
| 63 | + it('keeps workflow_dispatch compatibility coverage across OS and Node versions', () => { |
| 64 | + const { source, workflow } = readWorkflow('ci.yml') |
| 65 | + const [workflowDispatchRows, pullRequestRows] = extractJsonArrays(source) |
| 66 | + |
| 67 | + expect(workflow.jobs.compatibility.strategy['fail-fast']).toBe(false) |
| 68 | + expect(matrixIds(workflowDispatchRows)).toEqual(expect.arrayContaining([ |
| 69 | + 'ubuntu-latest:20:node20-core', |
| 70 | + 'ubuntu-latest:24:node24-core', |
| 71 | + 'windows-latest:20:windows-node20-core', |
| 72 | + 'windows-latest:22:windows-node22-core', |
| 73 | + 'windows-latest:24:windows-node24-core', |
| 74 | + 'macos-latest:22:macos-node22-core', |
| 75 | + ])) |
| 76 | + expect(matrixIds(pullRequestRows)).toEqual([ |
| 77 | + 'windows-latest:22:windows-node22-core', |
| 78 | + ]) |
| 79 | + |
| 80 | + const compatibilityRuns = stepRuns(workflow, 'compatibility').join('\n') |
| 81 | + expect(compatibilityRuns).toContain('pnpm --filter weapp-tailwindcss... run build') |
| 82 | + expect(compatibilityRuns).toContain('test/cli/postinstall.test.ts') |
| 83 | + expect(compatibilityRuns).toContain('test/bundlers/vite-plugin.uni-app-x.unit.test.ts') |
| 84 | + expect(compatibilityRuns).toContain('test/watch-hmr-coverage-matrix.unit.test.ts') |
| 85 | + }) |
| 86 | +}) |
| 87 | + |
| 88 | +describe('e2e watch workflow', () => { |
| 89 | + it('triggers when core package, platform demos, scripts, or lockfiles change', () => { |
| 90 | + const { workflow } = readWorkflow('e2e-watch.yml') |
| 91 | + |
| 92 | + expect(workflow.on.pull_request.paths).toEqual(expect.arrayContaining([ |
| 93 | + 'packages/weapp-tailwindcss/**', |
| 94 | + 'e2e/watch/**', |
| 95 | + 'demo/**', |
| 96 | + 'apps/**', |
| 97 | + 'scripts/**', |
| 98 | + 'pnpm-lock.yaml', |
| 99 | + '.github/workflows/e2e-watch.yml', |
| 100 | + ])) |
| 101 | + }) |
| 102 | + |
| 103 | + it('keeps PR quick-gate watch coverage on macOS and Windows', () => { |
| 104 | + const { workflow } = readWorkflow('e2e-watch.yml') |
| 105 | + const rows: Array<Record<string, unknown>> = workflow.jobs['pr-quick-gate'].strategy.matrix.include |
| 106 | + |
| 107 | + expect(workflow.jobs['pr-quick-gate'].strategy['fail-fast']).toBe(false) |
| 108 | + expect(matrixCases(rows)).toEqual(expect.arrayContaining([ |
| 109 | + 'macos:22:uni:default', |
| 110 | + 'macos:22:mpx:default', |
| 111 | + 'macos:22:taro:default', |
| 112 | + 'macos:22:uni-app-vue3-vite:issue33', |
| 113 | + 'macos:22:weapp-vite:issue33', |
| 114 | + 'macos:22:taro-webpack:issue33', |
| 115 | + 'macos:22:vite-native-ts:issue33', |
| 116 | + 'windows:22:uni:default', |
| 117 | + 'windows:22:mpx:default', |
| 118 | + 'windows:22:taro:default', |
| 119 | + 'windows:22:uni-app-vue3-vite:issue33', |
| 120 | + 'windows:22:weapp-vite:issue33', |
| 121 | + 'windows:22:taro-webpack:issue33', |
| 122 | + 'windows:22:vite-native-ts:issue33', |
| 123 | + ])) |
| 124 | + expect(stepRuns(workflow, 'pr-quick-gate')).toContain('pnpm e2e:watch') |
| 125 | + }) |
| 126 | + |
| 127 | + it('keeps nightly full-regression coverage for broad cases and Node 24 probes', () => { |
| 128 | + const { workflow } = readWorkflow('e2e-watch.yml') |
| 129 | + const rows: Array<Record<string, unknown>> = workflow.jobs['nightly-full-regression'].strategy.matrix.include |
| 130 | + |
| 131 | + expect(workflow.jobs['nightly-full-regression'].strategy['fail-fast']).toBe(false) |
| 132 | + expect(matrixCases(rows)).toEqual(expect.arrayContaining([ |
| 133 | + 'macos:22:all:default', |
| 134 | + 'windows:22:all:default', |
| 135 | + 'macos:22:demo:default', |
| 136 | + 'windows:22:demo:default', |
| 137 | + 'macos:22:apps:default', |
| 138 | + 'windows:22:apps:default', |
| 139 | + 'macos:24:weapp-vite:issue33', |
| 140 | + 'windows:24:vite-native-ts:issue33', |
| 141 | + ])) |
| 142 | + expect(stepRuns(workflow, 'nightly-full-regression')).toContain('pnpm e2e:watch') |
| 143 | + }) |
| 144 | +}) |
0 commit comments