Testing Blocks by adobe/helix-website
npx skills add https://github.com/adobe/helix-website --skill 'Testing Blocks'此技能指导您完成在 AEM Edge Delivery Services 项目中测试代码更改。测试遵循价值与成本平衡的理念:当测试带来的价值超过其创建和维护成本时,才创建和维护测试。
在以下情况使用此技能:
此技能应在实现完成后由 building-blocks 技能自动调用。
原则: 当测试带来的价值超过其创建和维护成本时,才创建和维护测试。
✅ 为以下内容编写单元测试:
这些测试能提供持久价值,因为它们能捕捉复用代码中的回归问题,充当活的文档,并且维护起来快速简单。
⚠️ 对以下内容使用浏览器测试:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
这些测试最好在浏览器中进行,因为 DOM 结构经常变化,视觉验证需要人工判断,并且相对于其价值,维护 UI 测试的成本很高。
重要提示: 即使是一次性测试也有价值!使用它们来:
组织方式: 将一次性测试保存在 test/tmp/ 中,测试内容保存在 drafts/tmp/ 中。这两个目录都应被 gitignore,以便临时测试工件不会被提交。
在打开拉取请求之前,请完成以下所有项目:
npm run lint 无错误完成gh checks 确认所有 CI 检查通过何时使用: 逻辑密集型函数、工具、数据处理、API 集成
快速开始:
# 验证测试设置(如果未配置,请参阅 resources/vitest-setup.md)
npm test
# 为工具函数编写测试
# test/utils/my-utility.test.js
import { describe, it, expect } from 'vitest';
import { myUtility } from '../../scripts/utils/my-utility.js';
describe('myUtility', () => {
it('should transform input correctly', () => {
expect(myUtility('input')).toBe('OUTPUT');
});
});
# 在开发过程中运行测试
npm run test:watch
详细指南: 参见 resources/unit-testing.md
何时使用: 区块装饰、视觉验证、DOM 结构、响应式设计
组织方式:
test/tmp/test-{block}-browser.jsdrafts/tmp/{block}.htmltest/tmp/screenshots/test/tmp/ 和 drafts/tmp/ 都应被 gitignore快速开始:
# 安装 Playwright
npm install --save-dev playwright
npx playwright install chromium
# 创建测试内容
# drafts/tmp/my-block.html (复制 head.html 内容,添加测试标记)
# 使用 drafts 文件夹启动开发服务器
aem up --html-folder drafts
# 在 test/tmp/ 中创建一次性测试脚本
# test/tmp/test-my-block.js
import { chromium } from 'playwright';
import { mkdir } from 'fs/promises';
async function test() {
await mkdir('./test/tmp/screenshots', { recursive: true });
const browser = await chromium.launch({ headless: false });
const page = await browser.newPage();
await page.goto('http://localhost:3000/drafts/tmp/my-block');
await page.waitForSelector('.my-block');
await page.screenshot({
path: './test/tmp/screenshots/my-block.png',
fullPage: true
});
await browser.close();
}
test().catch(console.error);
# 运行测试
node test/tmp/test-my-block.js
# 完成后清理(可选 - 反正已被 gitignore)
rm -rf test/tmp/*
详细指南: 参见 resources/browser-testing.md
何时使用: 每次提交之前
快速开始:
# 运行代码检查
npm run lint
# 自动修复问题
npm run lint:fix
在打开 PR 之前,代码检查必须通过。 没有商量余地。
何时使用: 推送分支后,通过 GitHub 检查自动进行
快速开始:
# 推送分支
git push -u origin your-branch
# 创建包含测试链接的 PR
# PR 描述中必须包含:
# Preview: https://branch--repo--owner.aem.page/path/to/test
# 监控检查
gh pr checks --watch
当您在 PR 描述中包含测试链接时,性能测试会自动运行。
有关详细的分步工作流程,请参见 resources/testing-workflow.md。
快速摘要:
npm run test:watchnpm test - 所有测试通过npm run lint - 代码检查通过test/tmp/ 中编写一次性浏览器测试drafts/tmp/ 中创建测试内容test/tmp/screenshots/ 的截图gh checksgh pr checks有关详细的故障排除指南,请参见 resources/troubleshooting.md。
常见问题:
npm test -- path/to/test.jsnpm run lint:fixgh pr checks 获取详细信息aem up --html-folder draftsdrafts/tmp/ 中是否存在测试内容/tmp/ 路径:http://localhost:3000/drafts/tmp/my-blockawait page.waitForSelector('.block')resources/unit-testing.md - 编写和维护单元测试的完整指南resources/browser-testing.md - Playwright/Puppeteer 工作流程和最佳实践resources/testing-workflow.md - 从开发到 PR 的分步工作流程resources/troubleshooting.md - 常见测试问题的解决方案resources/vitest-setup.md - 一次性配置指南building-blocks 技能在实现后会自动调用此技能。
预期流程:
构建区块提供:
此技能返回:
AEM Edge Delivery 中的测试遵循务实的价值与成本平衡方法:
为以下内容创建保留测试:
对以下内容使用一次性浏览器测试:
始终执行:
记住: 目标是确信您的代码正常工作,而不是达到 100% 的测试覆盖率。编写能提供价值的测试,并在浏览器中验证其他所有内容。
每周安装次数
0
代码仓库
GitHub 星标数
40
首次出现
1970年1月1日
安全审计
This skill guides you through testing code changes in AEM Edge Delivery Services projects. Testing follows a value-versus-cost philosophy: create and maintain tests when the value they bring exceeds the cost of creation and maintenance.
Use this skill:
This skill should be automatically invoked by the building-blocks skill after implementation is complete.
The Principle: Create and maintain tests when the value they bring exceeds the cost of creation and maintenance.
✅ Write unit tests for:
These tests provide lasting value because they catch regressions in reused code, serve as living documentation, and are fast and easy to maintain.
⚠️ Use browser tests for:
These tests are better done in a browser because DOM structures change frequently, visual validation requires human judgment, and maintaining UI tests is expensive relative to their value.
Important: Even throwaway tests have value! Use them to:
Organization: Keep throwaway tests in test/tmp/ and test content in drafts/tmp/. Both directories should be gitignored so temporary test artifacts aren't committed.
Before opening a pull request, complete ALL of the following:
npm run lint completes without errorsgh checks to confirm all CI checks passWhen to use: Logic-heavy functions, utilities, data processing, API integrations
Quick start:
# Verify test setup (see resources/vitest-setup.md if not configured)
npm test
# Write test for utility function
# test/utils/my-utility.test.js
import { describe, it, expect } from 'vitest';
import { myUtility } from '../../scripts/utils/my-utility.js';
describe('myUtility', () => {
it('should transform input correctly', () => {
expect(myUtility('input')).toBe('OUTPUT');
});
});
# Run tests during development
npm run test:watch
Detailed guide: See resources/unit-testing.md
When to use: Block decoration, visual validation, DOM structure, responsive design
Organization:
test/tmp/test-{block}-browser.jsdrafts/tmp/{block}.htmltest/tmp/screenshots/test/tmp/ and drafts/tmp/ should be gitignoredQuick start:
# Install Playwright
npm install --save-dev playwright
npx playwright install chromium
# Create test content
# drafts/tmp/my-block.html (copy head.html content, add test markup)
# Start dev server with drafts folder
aem up --html-folder drafts
# Create throwaway test script in test/tmp/
# test/tmp/test-my-block.js
import { chromium } from 'playwright';
import { mkdir } from 'fs/promises';
async function test() {
await mkdir('./test/tmp/screenshots', { recursive: true });
const browser = await chromium.launch({ headless: false });
const page = await browser.newPage();
await page.goto('http://localhost:3000/drafts/tmp/my-block');
await page.waitForSelector('.my-block');
await page.screenshot({
path: './test/tmp/screenshots/my-block.png',
fullPage: true
});
await browser.close();
}
test().catch(console.error);
# Run the test
node test/tmp/test-my-block.js
# Clean up when done (optional - gitignored either way)
rm -rf test/tmp/*
Detailed guide: See resources/browser-testing.md
When to use: Before every commit
Quick start:
# Run linting
npm run lint
# Auto-fix issues
npm run lint:fix
Linting MUST pass before opening a PR. Non-negotiable.
When to use: After pushing branch, automatically via GitHub checks
Quick start:
# Push branch
git push -u origin your-branch
# Create PR with test link
# PR description MUST include:
# Preview: https://branch--repo--owner.aem.page/path/to/test
# Monitor checks
gh pr checks --watch
Performance tests run automatically when you include a test link in your PR description.
For detailed step-by-step workflow, see resources/testing-workflow.md.
Quick summary:
npm run test:watchnpm test - all tests passnpm run lint - linting passestest/tmp/drafts/tmp/test/tmp/screenshots/gh checksgh pr checksFor detailed troubleshooting guide, see resources/troubleshooting.md.
Common issues:
npm test -- path/to/test.jsnpm run lint:fixgh pr checks for detailsaem up --html-folder draftsdrafts/tmp//tmp/ path: http://localhost:3000/drafts/tmp/my-blockawait page.waitForSelector('.block')resources/unit-testing.md - Complete guide to writing and maintaining unit testsresources/browser-testing.md - Playwright/Puppeteer workflows and best practicesresources/testing-workflow.md - Step-by-step workflow from dev to PRresources/troubleshooting.md - Solutions to common testing issuesresources/vitest-setup.md - One-time configuration guideThe building-blocks skill automatically invokes this skill after implementation.
Expected flow:
Building blocks provides:
This skill returns:
Testing in AEM Edge Delivery follows a pragmatic value-versus-cost approach:
Create keeper tests for:
Use throwaway browser tests for:
Always do:
Remember: The goal is confidence that your code works correctly, not achieving 100% test coverage. Write tests that provide value, and validate everything else in a browser.
Weekly Installs
0
Repository
GitHub Stars
40
First Seen
Jan 1, 1970
Security Audits
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
150,000 周安装