Skip to content

Commit cf1803f

Browse files
committed
feat: add browser tests and lazy catalog architecture
1 parent be4b981 commit cf1803f

29 files changed

Lines changed: 600 additions & 106 deletions

.github/workflows/test.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
verify:
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 20
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-node@v4
17+
with:
18+
node-version: 22
19+
cache: npm
20+
- name: Ensure Podman is available
21+
run: command -v podman || (sudo apt-get update && sudo apt-get install --yes podman)
22+
- run: npm ci
23+
- run: npm run check
24+
- run: npm run format:check
25+
- name: Run browser tests in Podman
26+
run: npm run test:e2e:podman
27+
- name: Upload Playwright report
28+
if: ${{ !cancelled() }}
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: playwright-report
32+
path: |
33+
playwright-report/
34+
test-results/
35+
if-no-files-found: ignore
36+
retention-days: 7

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
node_modules
22
dist
3+
playwright-report
4+
test-results
35
.vite
46
.generated
57
.tmp

CHANGELOG.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,26 @@
1717
- 目录现包含 9 个分类、121 个公开可调用 API 和 121 个独立 demo。
1818
- 新增 API 获得完整中英文说明;`clientOnly` 使用浏览器 demo,两个 HTTP 声明 API 使用请求上下文中的 SSR demo。
1919

20+
### Architecture and Performance
21+
22+
- 生成器新增 `data/catalog-index.json` 轻量发现索引;完整签名、关联类型和 demo 源码继续保存在 `data/catalog.json`
23+
- 首页、搜索和侧栏只加载轻量索引,API 功能区与完整目录通过 Solid `lazy()` 按需加载。
24+
- 浏览器 demo 执行器改为动态导入;结果模型和 SSR demo 分类从运行实现中拆分。
25+
- Hash 导航接入浏览器历史,支持深链接、前进、后退,并在恢复 API 时同步展开所属分类。
26+
- 生产入口从 557.46 KB 降至 230.58 KB,gzip 从 116.20 KB 降至 75.48 KB;完整 API 数据进入独立按需 chunk。
27+
28+
### Test Automation
29+
30+
- 引入 `@playwright/test@1.62.0`,浏览器及系统依赖由 `mcr.microsoft.com/playwright:v1.62.0-noble` Podman 镜像提供。
31+
- 新增桌面搜索与导航、浏览器历史、语言和主题持久化、真实 demo 执行、移动端目录以及按需 chunk 加载测试。
32+
- 新增 GitHub Actions 工作流,并保留失败截图、视频、trace 和 HTML 报告。
33+
- `npm test` 统一执行类型检查、格式检查、121 个 demo 验证和容器化端到端测试。
34+
- 新增测试维护指南与函数代码包交付文档,记录 Podman 排错、`code.zip` 内容、监听端口和启动命令。
35+
2036
### Verification
2137

22-
- 116 个浏览器 demo 和 5 个 SSR demo 全部通过。
38+
- 116 个浏览器 demo 和 5 个 SSR demo 全部通过,合计 121/121。
39+
- Podman Chromium 端到端测试 4/4 通过。
2340
- 类型检查、格式检查和生产构建通过。
2441

2542
## 1.2-2.0.0-beta.27 - 2026-07-29

DEPLOYMENT.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Deployment and Code Package
2+
3+
## 函数代码包
4+
5+
本项目通过生产 Node 服务器同时提供静态页面和 Demo API。每次提交或交付部署版本时,除正常源码变更外,还应在仓库根目录生成一份 `code.zip`
6+
7+
### 打包前检查
8+
9+
```bash
10+
npm ci
11+
npm test
12+
npm run build
13+
```
14+
15+
`npm run build` 会重新生成 `data/catalog-index.json``data/catalog.json`,并将前端生产文件写入 `dist/`
16+
17+
### 生成 ZIP
18+
19+
代码包必须包含 `node_modules`。在仓库根目录执行:
20+
21+
```bash
22+
rm -f code.zip
23+
zip -rq -y code.zip ./ \
24+
-x '.git/*' \
25+
'.generated/*' \
26+
'.tmp/*' \
27+
'dist/.vite/*' \
28+
'playwright-report/*' \
29+
'test-results/*' \
30+
'code.zip'
31+
```
32+
33+
也可以在文件管理器中进入项目根目录,全选所有部署文件和 `node_modules`,右键压缩为 ZIP。ZIP 内应直接看到 `package.json`,不能在外层额外包一层项目目录。
34+
35+
上传前可检查关键内容:
36+
37+
```bash
38+
unzip -l code.zip | rg '(^|/)(package.json|dist/index.html|scripts/demo/server.mjs|data/catalog.json)$'
39+
```
40+
41+
### 函数配置
42+
43+
- 监听端口:`9000`
44+
- 启动命令:`npm start`
45+
- 健康检查:`GET /health`
46+
- 可选端口环境变量:`PORT`
47+
48+
如果平台注入 `PORT`,服务器会优先监听该值;此时平台的“监听端口”必须与 `PORT` 一致。
49+
50+
### 使用依赖层
51+
52+
如果通过函数计算平台的“层”提供依赖,可以不把 `node_modules` 放入 ZIP,但依赖层必须与当前 Node.js 版本、CPU 架构和 `package-lock.json` 一致,并包含全部生产依赖。默认交付方式仍是将 `node_modules` 放入 `code.zip`,以减少环境差异。
53+
54+
## Delivery Checklist
55+
56+
Before each deployment handoff:
57+
58+
1. Run the complete test suite and production build.
59+
2. Generate `code.zip` from the repository root, including `node_modules`.
60+
3. Verify that `package.json` is at the ZIP root.
61+
4. Configure port `9000` and startup command `npm start`.
62+
5. Keep `code.zip` out of Git; it is a delivery artifact and is already ignored.

README.md

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The catalog is generated from the packages installed in this repository. It expo
1010

1111
- Node.js `^20.19.0` or `>=22.12.0`
1212
- npm
13+
- Podman (for containerized browser tests)
1314

1415
## Getting Started
1516

@@ -23,24 +24,40 @@ Vite prints the local development URL, normally <http://localhost:5173/>.
2324
## Commands
2425

2526
```bash
26-
npm run dev # Generate the catalog and start Vite
27-
npm run generate # Rebuild the catalog from installed Solid packages
28-
npm run check # Regenerate and run TypeScript checks
29-
npm run build # Regenerate and create a production build
30-
npm run preview # Preview the production build through Vite
31-
npm start # Serve the build and Demo APIs with the production Node server
32-
npm run verify:demos # Verify all browser and SSR examples
33-
npm run format # Format project source files with Prettier
34-
npm run format:check # Check formatting without writing files
27+
npm run dev # Generate both catalogs and start Vite
28+
npm run generate # Rebuild generated catalog artifacts
29+
npm run check # Regenerate and run TypeScript checks
30+
npm run build # Regenerate and create a production build
31+
npm run preview # Preview the production build through Vite
32+
npm start # Serve the build and Demo APIs with the production Node server
33+
npm test # Run the complete static, demo, and browser test suite
34+
npm run test:e2e # Run Playwright with a locally installed browser
35+
npm run test:e2e:podman # Run Playwright in the pinned browser container
36+
npm run verify:demos # Verify all browser and SSR examples
37+
npm run format # Format project source files with Prettier
38+
npm run format:check # Check formatting without writing files
3539
```
3640

37-
`predev`, `precheck`, and `prebuild` regenerate the API catalog automatically.
41+
`predev`, `precheck`, and `prebuild` regenerate both API catalog artifacts automatically.
42+
43+
## Browser Tests
44+
45+
The end-to-end suite uses Playwright and the `mcr.microsoft.com/playwright:v1.62.0-noble` Podman image. The image owns Chromium and its system libraries, so no browser is installed on the host. The suite builds the production app, starts a Vite preview server inside the temporary container, and covers desktop search and browser history, persisted locale and theme preferences, executable demos, the mobile catalog, and the lazy API chunk boundary.
46+
47+
```bash
48+
npm run test:e2e:podman
49+
```
50+
51+
Failures retain screenshots, videos, and Playwright traces under `test-results/`; the HTML report is written to `playwright-report/`. Override the image for an internal registry or mirror with `PLAYWRIGHT_IMAGE` while keeping its Playwright version aligned with `@playwright/test`.
52+
53+
GitHub Actions runs type checks, formatting checks, and the same Podman browser suite on pushes and pull requests. See [tests/README.md](tests/README.md) for the test layers, environment overrides, and artifact workflow.
3854

3955
## Project Structure
4056

4157
```text
4258
data/
43-
catalog.json Generated metadata, locale text pools, and demo source pool
59+
catalog-index.json Lightweight generated navigation and search index
60+
catalog.json Complete metadata, locale text pools, and demo source pool
4461
4562
scripts/
4663
README.md Catalog and demo tooling documentation
@@ -63,7 +80,8 @@ scripts/
6380
6481
src/
6582
main.tsx Browser entry and application composition
66-
data/catalog.ts Typed adapter for generated data
83+
data/catalog-index.ts Eager adapter for lightweight discovery data
84+
data/catalog.ts Lazy adapter for complete API reference data
6785
features/api/ API page and reference view
6886
features/demo/ Controller, view, and runtime adapter
6987
features/home/ Project home page
@@ -73,6 +91,10 @@ src/
7391
lib/preferences.ts Safe browser preference adapter
7492
ui/ Shared classes, highlighting, and icons
7593
tailwind.css CSS-first Tailwind design system
94+
95+
tests/
96+
README.md Test architecture and troubleshooting
97+
e2e/ Playwright production-browser workflows
7698
```
7799

78100
`data` is generated, `scripts/catalog` owns catalog content and generation, `scripts/demo` owns executable demo services, and `src` contains the browser application.
@@ -86,7 +108,7 @@ src/
86108
3. Has at least one callable TypeScript signature.
87109
4. Is not marked `@internal`.
88110

89-
The generated `data/catalog.json` stores metadata, categories, localized prose, demo source, and compact record indexes. [src/data/catalog.ts](src/data/catalog.ts) validates and expands it for the application. Do not edit or manually format this generated file.
111+
The generator writes two artifacts. `data/catalog-index.json` contains only the bilingual summaries and identity fields needed by navigation and search. `data/catalog.json` stores complete signatures, related types, localized prose pools, and demo source. [src/data/catalog-index.ts](src/data/catalog-index.ts) loads the index eagerly, while [src/data/catalog.ts](src/data/catalog.ts) validates and expands the complete catalog only when an API page is opened. Do not edit or manually format either generated file.
90112

91113
English and Chinese API prose is resolved by `scripts/catalog/locale-en.mjs` and `scripts/catalog/locale-zh-cn.mjs`. Each strategy contains the current API content and a resolver for APIs discovered in later package versions. Every API has its own language-neutral, complete demo program in `scripts/catalog/demos.mjs`.
92114

@@ -130,9 +152,11 @@ Current verified surface:
130152

131153
## Frontend Architecture
132154

133-
The application is a Solid single-page interface with hash-based API selection. It does not use a router or external state manager. A single optional active-document ID represents both home and API routes, avoiding duplicated route state.
155+
The application is a Solid single-page interface with hash-based API selection. It does not use a router or external state manager. A single optional active-document ID represents both home and API routes, while a small history adapter keeps deep links and browser back/forward navigation synchronized.
134156

157+
- Navigation and search use a lightweight generated index; complete reference data and the API feature load on demand.
135158
- Demo execution stays in the feature controller; inline and fullscreen editors share one implementation.
159+
- The browser runtime is dynamically imported only when an example executes; result types and SSR classification live in a dependency-light model.
136160
- Tailwind CSS v4 provides the CSS-first design system and utility styles.
137161
- Prism provides TypeScript/TSX highlighting.
138162
- Lucide provides interface icons.
@@ -146,6 +170,8 @@ The application is a Solid single-page interface with hash-based API selection.
146170

147171
Detailed maintenance documentation:
148172

173+
- [Deployment and code packaging](./DEPLOYMENT.md)
149174
- [Release changes](./CHANGELOG.md)
150175
- [Catalog and demo tooling](./scripts/README.md)
176+
- [Testing and browser automation](./tests/README.md)
151177
- [Adding a locale](./src/features/i18n/README.md)

README.zh-CN.md

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
- Node.js `^20.19.0``>=22.12.0`
1212
- npm
13+
- Podman(用于容器化浏览器测试)
1314

1415
## 快速开始
1516

@@ -23,24 +24,40 @@ Vite 会输出本地开发地址,通常为 <http://localhost:5173/>。
2324
## 常用命令
2425

2526
```bash
26-
npm run dev # 生成目录并启动 Vite
27-
npm run generate # 根据已安装的 Solid 包重新生成目录
28-
npm run check # 重新生成目录并执行 TypeScript 检查
29-
npm run build # 重新生成目录并构建生产版本
30-
npm run preview # 通过 Vite 预览生产构建
31-
npm start # 使用生产 Node 服务器提供构建产物和示例接口
32-
npm run verify:demos # 验证全部浏览器与 SSR 示例
33-
npm run format # 使用 Prettier 格式化项目源码
34-
npm run format:check # 仅检查格式,不写入文件
27+
npm run dev # 生成两个目录产物并启动 Vite
28+
npm run generate # 重新生成目录产物
29+
npm run check # 重新生成目录并执行 TypeScript 检查
30+
npm run build # 重新生成目录并构建生产版本
31+
npm run preview # 通过 Vite 预览生产构建
32+
npm start # 使用生产 Node 服务器提供构建产物和示例接口
33+
npm test # 执行完整静态、Demo 与浏览器测试
34+
npm run test:e2e # 使用本机已安装的浏览器运行 Playwright
35+
npm run test:e2e:podman # 在固定版本浏览器容器中运行 Playwright
36+
npm run verify:demos # 验证全部浏览器与 SSR 示例
37+
npm run format # 使用 Prettier 格式化项目源码
38+
npm run format:check # 仅检查格式,不写入文件
3539
```
3640

37-
`predev``precheck``prebuild` 会自动重新生成 API 目录。
41+
`predev``precheck``prebuild` 会自动重新生成两个 API 目录产物。
42+
43+
## 浏览器测试
44+
45+
端到端测试使用 Playwright 和 Podman 镜像 `mcr.microsoft.com/playwright:v1.62.0-noble`。Chromium 及其系统依赖均由镜像提供,宿主机无需安装浏览器。测试会在临时容器中构建生产版本、启动 Vite 预览服务,并覆盖桌面端搜索与浏览器历史、语言和主题持久化、可执行示例、移动端目录以及 API chunk 懒加载边界。
46+
47+
```bash
48+
npm run test:e2e:podman
49+
```
50+
51+
失败时,截图、视频和 Playwright trace 会保留在 `test-results/`,HTML 报告输出到 `playwright-report/`。内部镜像仓库或镜像代理可通过 `PLAYWRIGHT_IMAGE` 覆盖默认镜像,但镜像中的 Playwright 版本必须与 `@playwright/test` 保持一致。
52+
53+
GitHub Actions 会在 push 和 pull request 时执行类型检查、格式检查和同一套 Podman 浏览器测试。测试分层、环境变量和失败产物排查方式见 [tests/README.md](tests/README.md)
3854

3955
## 项目结构
4056

4157
```text
4258
data/
43-
catalog.json 生成的元数据、本地化文本池和示例源码池
59+
catalog-index.json 生成的轻量导航与搜索索引
60+
catalog.json 完整元数据、本地化文本池和示例源码池
4461
4562
scripts/
4663
README.md 目录和示例工具文档
@@ -63,7 +80,8 @@ scripts/
6380
6481
src/
6582
main.tsx 浏览器入口与应用组合
66-
data/catalog.ts 生成数据的类型适配器
83+
data/catalog-index.ts 轻量发现数据的首屏适配器
84+
data/catalog.ts 完整 API 参考数据的懒加载适配器
6785
features/api/ API 页面与参考视图
6886
features/demo/ 示例控制器、视图与运行时适配器
6987
features/home/ 项目首页
@@ -73,6 +91,10 @@ src/
7391
lib/preferences.ts 安全的浏览器偏好适配器
7492
ui/ 共享样式、代码高亮与图标
7593
tailwind.css Tailwind CSS 设计系统
94+
95+
tests/
96+
README.md 测试架构与问题排查
97+
e2e/ Playwright 生产浏览器流程
7698
```
7799

78100
`data` 保存生成产物,`scripts/catalog` 负责目录内容与生成,`scripts/demo` 负责可执行示例服务,`src` 包含浏览器应用。
@@ -86,7 +108,7 @@ src/
86108
3. 至少有一个可调用的 TypeScript 签名。
87109
4. 没有标记为 `@internal`
88110

89-
生成的 `data/catalog.json` 保存元数据、分类、本地化内容、示例源码和紧凑记录索引[src/data/catalog.ts](src/data/catalog.ts) 负责验证并展开数据供应用使用。不要编辑或手动格式化该生成文件
111+
生成器会写入两个产物。`data/catalog-index.json` 只包含导航和搜索所需的双语摘要与标识字段;`data/catalog.json` 保存完整签名、关联类型、本地化文本池和示例源码[src/data/catalog-index.ts](src/data/catalog-index.ts) 在首屏加载轻量索引,[src/data/catalog.ts](src/data/catalog.ts) 仅在打开 API 页面时验证并展开完整目录。不要编辑或手动格式化这两个生成文件
90112

91113
中英文 API 内容分别由 `scripts/catalog/locale-en.mjs``scripts/catalog/locale-zh-cn.mjs` 解析。每种策略包含当前 API 内容,以及用于处理未来新增 API 的回退解析器。每个 API 都在 `scripts/catalog/demos.mjs` 中拥有独立、完整且与语言无关的示例程序。
92114

@@ -130,9 +152,11 @@ SSR 示例为只读,只执行可信的生成源码。源码和请求正文上
130152

131153
## 前端架构
132154

133-
应用是使用 Hash 选择 API 的 Solid 单页界面,不依赖路由器或外部状态管理器。首页和 API 页面由单一的可选当前文档 ID 表达,避免维护重复路由状态
155+
应用是使用 Hash 选择 API 的 Solid 单页界面,不依赖路由器或外部状态管理器。首页和 API 页面由单一的可选当前文档 ID 表达,小型历史适配层负责同步深链接和浏览器前进、后退行为
134156

157+
- 导航与搜索使用轻量生成索引;完整参考数据和 API 功能区按需加载。
135158
- 示例执行由功能控制器负责,内嵌与全屏编辑器复用同一实现。
159+
- 浏览器运行时仅在执行示例时动态导入;结果类型和 SSR 分类位于无重依赖的模型层。
136160
- Tailwind CSS v4 提供 CSS-first 设计系统和工具类。
137161
- Prism 提供 TypeScript/TSX 代码高亮。
138162
- Lucide 提供界面图标。
@@ -146,6 +170,8 @@ SSR 示例为只读,只执行可信的生成源码。源码和请求正文上
146170

147171
详细维护文档:
148172

173+
- [部署与代码包](./DEPLOYMENT.md)
149174
- [版本变更](./CHANGELOG.md)
150175
- [目录与示例工具](./scripts/README.md)
176+
- [测试与浏览器自动化](./tests/README.md)
151177
- [添加语言](./src/features/i18n/README.md)

data/catalog-index.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)