jpskill.com
🛠️ 開発・MCP コミュニティ

Testing Blocks

AEM Edge Deliveryプロジェクトでブロック、スクリプト、スタイルなどのコード変更をテストし、プルリクエスト前に機能検証を行うためのガイドで、単体テスト、ブラウザテスト、linting、パフォーマンス検証などを実施するSkill。

📜 元の英語説明(参考)

Guide for testing code changes in AEM Edge Delivery projects including blocks, scripts, and styles. Use this skill after making code changes and before opening a pull request to validate functionality. Covers unit testing for utilities and logic, browser testing with Playwright/Puppeteer, linting, performance validation, and guidance on which tests to maintain vs use as throwaway validation.

🇯🇵 日本人クリエイター向け解説

一言でいうと

AEM Edge Deliveryプロジェクトでブロック、スクリプト、スタイルなどのコード変更をテストし、プルリクエスト前に機能検証を行うためのガイドで、単体テスト、ブラウザテスト、linting、パフォーマンス検証などを実施するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o testing-blocks.zip https://jpskill.com/download/9689.zip && unzip -o testing-blocks.zip && rm testing-blocks.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/9689.zip -OutFile "$d\testing-blocks.zip"; Expand-Archive "$d\testing-blocks.zip" -DestinationPath $d -Force; ri "$d\testing-blocks.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して testing-blocks.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → testing-blocks フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Testing Blocks

このスキルでは、AEM Edge Delivery Services プロジェクトにおけるコード変更のテストについて説明します。テストは、価値とコストのバランスを考慮した哲学に従います。つまり、テストがもたらす価値が、作成とメンテナンスにかかるコストを上回る場合に、テストを作成し、維持します。

関連スキル

  • content-driven-development: CDD で作成されたテストコンテンツは、テストの基礎として機能します。
  • building-blocks: このスキルは、ブロックの実装後に自動的に呼び出されます。
  • block-collection-and-party: 同様のブロックからの参照テストパターンを提供する場合があります。

このスキルを使用するタイミング

このスキルは、以下の場合に使用します。

  • ✅ ブロックを実装または変更した後
  • ✅ コアスクリプト (scripts.js, delayed.js, aem.js) を変更した後
  • ✅ スタイル (styles.css, lazy-styles.css) を変更した後
  • ✅ 機能に影響を与える設定を変更した後
  • ✅ コード変更を含むプルリクエストをオープンする前

このスキルは、実装完了後、building-blocks スキルによって自動的に呼び出されるはずです。

テストの哲学: 価値 vs コスト

原則: テストがもたらす価値が、作成とメンテナンスにかかるコストを上回る場合に、テストを作成し、維持します。

Keeper Tests (高価値、維持する価値あり)

以下のユニットテストを作成します。

  • 複数のブロックで使用されるロジックの多いユーティリティ関数
  • データ処理および変換ロジック
  • API 統合および外部サービスとのインタラクション
  • 複雑なアルゴリズムまたはビジネスロジック
  • 共有ライブラリおよびヘルパー関数

これらのテストは、再利用されるコードにおけるリグレッションを検出し、生きたドキュメントとして機能し、高速かつ簡単にメンテナンスできるため、永続的な価値を提供します。

Throwaway Tests (低価値、一度だけ使用)

⚠️ 以下のブラウザテストを使用します。

  • ブロックの装飾ロジック (DOM 変換)
  • 特定の DOM 構造または UI レイアウト
  • 外観の検証
  • ブロック固有のレンダリング動作

これらのテストは、DOM 構造が頻繁に変更され、視覚的な検証には人間の判断が必要であり、UI テストの維持には価値に比べてコストがかかるため、ブラウザで実行する方が適しています。

重要: 使い捨てテストであっても価値があります! 以下の目的で使用してください。

  1. 実装が正しく動作することを検証する
  2. スクリーンショットを撮って、視覚的な正確さを評価する
  3. スクリーンショットを人に見せてフィードバックを得る
  4. レビューを支援するために、PR にスクリーンショットを含める

構成: 使い捨てテストは test/tmp/ に、テストコンテンツは drafts/tmp/ に保存します。どちらのディレクトリも一時的なテストアーティファクトがコミットされないように、gitignore に追加する必要があります。

テストチェックリスト

プルリクエストをオープンする前に、以下のすべてを完了してください。

  • [ ] 既存のテストに合格 - すべての keeper テストが変更後も合格すること
  • [ ] ユニットテストの作成 - ロジックの多いユーティリティまたはデータ処理のための新しい keeper テスト
  • [ ] ブラウザ検証 - ローカル開発サーバーで機能をテストし、スクリーンショットをキャプチャすること
  • [ ] すべてのバリアントをテスト - ブロックの各バリアント/構成を検証すること
  • [ ] レスポンシブな動作 - モバイル、タブレット、デスクトップのビューポートでテストすること
  • [ ] Linting に合格 - npm run lint がエラーなしで完了すること
  • [ ] ブランチをプッシュ - コードをコミットしてフィーチャーブランチにプッシュすること
  • [ ] GitHub チェックの検証 - gh checks を使用して、すべての CI チェックが合格することを確認すること

テスト方法の概要

1. ユニットテスト (KEEPER TESTS)

使用するタイミング: ロジックの多い関数、ユーティリティ、データ処理、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 を参照してください。

2. ブラウザテスト (THROWAWAY TESTS)

使用するタイミング: ブロックの装飾、視覚的な検証、DOM 構造、レスポンシブデザイン

構成:

  • テストスクリプト: test/tmp/test-{block}-browser.js
  • テストコンテンツ: drafts/tmp/{block}.html
  • スクリーンショット: test/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 を参照してください。

3. Linting (常に)

使用するタイミング: コミットするたびに

クイックスタート:

# Linting を実行します
npm run lint

# 問題を自動修正します
npm run lint:fix

PR をオープンする前に、Linting に合格する必要があります。 これは必須です。

4. パフォーマンス テスト (自動化)

使用するタイミング: ブランチをプッシュした後、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 を参照してください。

**クイックサマ

📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Testing Blocks

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.

Related Skills

  • content-driven-development: Test content created during CDD serves as the basis for testing
  • building-blocks: This skill is automatically invoked after block implementation
  • block-collection-and-party: May provide reference test patterns from similar blocks

When to Use This Skill

Use this skill:

  • ✅ After implementing or modifying blocks
  • ✅ After changes to core scripts (scripts.js, delayed.js, aem.js)
  • ✅ After style changes (styles.css, lazy-styles.css)
  • ✅ After configuration changes that affect functionality
  • ✅ Before opening any pull request with code changes

This skill should be automatically invoked by the building-blocks skill after implementation is complete.

Testing Philosophy: Value vs Cost

The Principle: Create and maintain tests when the value they bring exceeds the cost of creation and maintenance.

Keeper Tests (High Value, Worth Maintaining)

Write unit tests for:

  • Logic-heavy utility functions used across multiple blocks
  • Data processing and transformation logic
  • API integrations and external service interactions
  • Complex algorithms or business logic
  • Shared libraries and helper functions

These tests provide lasting value because they catch regressions in reused code, serve as living documentation, and are fast and easy to maintain.

Throwaway Tests (Lower Value, Use Once)

⚠️ Use browser tests for:

  • Block decoration logic (DOM transformations)
  • Specific DOM structures or UI layouts
  • Visual appearance validation
  • Block-specific rendering behavior

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:

  1. Validate your implementation works correctly
  2. Take screenshots to evaluate visual correctness
  3. Show screenshots to humans for feedback
  4. Include screenshots in PRs to aid review

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.

Testing Checklist

Before opening a pull request, complete ALL of the following:

  • [ ] Existing tests pass - All keeper tests still pass with your changes
  • [ ] Unit tests written - New keeper tests for any logic-heavy utilities or data processing
  • [ ] Browser validation - Feature tested in local dev server, screenshots captured
  • [ ] All variants tested - Each variant/configuration of blocks validated
  • [ ] Responsive behavior - Tested on mobile, tablet, desktop viewports
  • [ ] Linting passes - npm run lint completes without errors
  • [ ] Branch pushed - Code committed and pushed to feature branch
  • [ ] GitHub checks verified - Use gh checks to confirm all CI checks pass

Testing Methods Overview

1. Unit Tests (KEEPER TESTS)

When 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

2. Browser Testing (THROWAWAY TESTS)

When to use: Block decoration, visual validation, DOM structure, responsive design

Organization:

  • Test scripts: test/tmp/test-{block}-browser.js
  • Test content: drafts/tmp/{block}.html
  • Screenshots: test/tmp/screenshots/
  • Both test/tmp/ and drafts/tmp/ should be gitignored

Quick 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

3. Linting (ALWAYS)

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.

4. Performance Testing (AUTOMATED)

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.

Complete Workflow

For detailed step-by-step workflow, see resources/testing-workflow.md.

Quick summary:

During Development

  1. Write unit tests for new utilities
  2. Run npm run test:watch
  3. Manually test in browser

Before Committing

  1. Run npm test - all tests pass
  2. Run npm run lint - linting passes
  3. Write throwaway browser test in test/tmp/
  4. Create test content in drafts/tmp/
  5. Review screenshots from test/tmp/screenshots/
  6. Manual validation in browser

Before Opening PR

  1. Commit and push to feature branch (test/tmp/ won't be included)
  2. Verify branch preview loads
  3. Run gh checks
  4. Create PR with test link
  5. Monitor gh pr checks

After PR Review

  1. Address feedback
  2. Re-test
  3. Verify checks pass

Troubleshooting

For detailed troubleshooting guide, see resources/troubleshooting.md.

Common issues:

Tests fail

  • Read error message carefully
  • Run single test: npm test -- path/to/test.js
  • Fix code or update test

Linting fails

  • Run npm run lint:fix
  • Manually fix remaining issues

GitHub checks fail

  • Ensure PR has test link
  • Check gh pr checks for details
  • Fix performance issues if PSI fails

Browser tests fail

  • Verify dev server running: aem up --html-folder drafts
  • Check test content exists in drafts/tmp/
  • Verify URL uses /tmp/ path: http://localhost:3000/drafts/tmp/my-block
  • Add waits: await page.waitForSelector('.block')

Resources

  • Unit Testing: resources/unit-testing.md - Complete guide to writing and maintaining unit tests
  • Browser Testing: resources/browser-testing.md - Playwright/Puppeteer workflows and best practices
  • Testing Workflow: resources/testing-workflow.md - Step-by-step workflow from dev to PR
  • Troubleshooting: resources/troubleshooting.md - Solutions to common testing issues
  • Vitest Setup: resources/vitest-setup.md - One-time configuration guide

Integration with Building Blocks Skill

The building-blocks skill automatically invokes this skill after implementation.

Expected flow:

  1. Building blocks completes implementation
  2. Invokes testing-blocks skill
  3. This skill guides testing process
  4. Returns control when testing complete

Building blocks provides:

  • Block name being tested
  • Test content URL from CDD process
  • Any variants that need testing

This skill returns:

  • Confirmation all tests pass
  • Screenshots from browser testing (if requested)
  • Any issues discovered during testing

Summary

Testing in AEM Edge Delivery follows a pragmatic value-versus-cost approach:

Create keeper tests for:

  • Logic-heavy utilities
  • Data processing and transformations
  • API integrations
  • Shared libraries

Use throwaway browser tests for:

  • Block decoration validation
  • Visual appearance
  • DOM structure
  • Interactive behavior

Always do:

  • Run linting before commits
  • Test manually in browser
  • Verify GitHub checks pass
  • Include test links in PRs

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.