首页/ AI 技能 / @skilllib/skill-2117939930272414220
Skill站外收录 @skilllib/skill-2117939930272414220

web-renderer-test

为网页渲染器添加可视化快照测试能力,通过定义组件结构、尺寸和帧率等参数生成测试用例,并利用 Vitest 框架捕获渲染结果图像进行比对验证,支持快速定位前端渲染异常。

0.0 (0) 21 次安装 原作者 编程导航
收录于 2026-01-22
测试与安全 AI 技能

Skills.MD

The web renderer is in `packages/web-renderer` and the test suite is in `packages/web-renderer/src/test`. It uses visual snapshot testing using vitest. A test file can for example be executed using: ``` bunx vitest src/test/video.test.tsx ``` ## Example Each test is powered by a fixture in `packages/web-renderer/src/test/fixtures`. A fixture looks like this for example: ```tsx import {AbsoluteFill} from 'remotion'; const Component: React.FC = () => { return ( <AbsoluteFill style={{ justifyContent: 'center', alignItems: 'center', }} > <div style={{ backgroundColor: 'red', width: 100, height: 100, borderRadius: 20, }} /> </AbsoluteFill> ); }; export const backgroundColor = { component: Component, id: 'background-color', width: 200, height: 200, fps: 25, durationInFrames: 1, } as const; ``` The corresponding test looks like this: ```tsx import {test} from 'vitest'; import {renderStillOnWeb} from '../render-still-on-web'; import {backgroundColor} from './fixtures/background-color'; import {testImage} from './utils'; test('should render background-color', async () => { const blob = await renderStillOnWeb({ licenseKey: 'free-license', composition: backgroundColor, frame: 0, inputProps: {}, imageFormat: 'png', }); await testImage({blob, testId: 'background-color'}); }); ``` ## Adding a new test 1. Add a new fixture in `packages/web-renderer/src/test/fixtures`. 2. **Important**: Add the fixture to `packages/web-renderer/src/test/Root.tsx` to add a way to preview it. 3. Add a new test in `packages/web-renderer/src/test`. 4. Run `bunx vitest src/test/video.test.tsx` to execute the test.

评论 0

还没有评论,来抢沙发。