Skills for building AEM Edge Delivery Services sites — block development, content modeling, code review, testing, and page import.
82
76%
Does it follow best practices?
Impact
88%
1.04xAverage score across 6 eval scenarios
Advisory
Suggest reviewing before use
This guide covers the one-time setup of Vitest for unit testing in AEM Edge Delivery projects. Once configured, you won't need to repeat these steps.
Install Vitest and required dependencies:
npm install --save-dev vitest @vitest/ui jsdomOptional but recommended for coverage reports:
npm install --save-dev @vitest/coverage-v8Create vitest.config.js in the project root:
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
environment: 'jsdom',
globals: true,
coverage: {
provider: 'v8',
reporter: ['text', 'html'],
exclude: [
'node_modules/',
'test/',
'**/*.config.js',
],
},
},
});describe, it, expect available without importsAdd test scripts to your package.json:
{
"scripts": {
"test": "vitest run",
"test:watch": "vitest",
"test:ui": "vitest --ui",
"test:coverage": "vitest run --coverage"
}
}npm test - Run all tests once (use in CI or before commits)npm run test:watch - Run tests in watch mode (use during development)npm run test:ui - Open interactive web UI for testsnpm run test:coverage - Generate code coverage reportCreate directories for test files:
mkdir -p test/utils
mkdir -p test/blocksproject-root/
├── scripts/
│ └── utils/
│ └── my-utility.js
├── blocks/
│ └── hero/
│ ├── hero.js
│ ├── hero.css
│ └── utils.js
└── test/
├── utils/
│ └── my-utility.test.js
└── blocks/
└── hero/
└── utils.test.jsTest file naming: {filename}.test.js
Run tests to verify setup:
npm testIf no tests exist yet, you should see:
No test files found, exiting with code 0Create a simple test to verify everything works:
// test/example.test.js
import { describe, it, expect } from 'vitest';
describe('Vitest setup', () => {
it('should be configured correctly', () => {
expect(true).toBe(true);
});
});Run tests again:
npm testYou should see the test pass. Once verified, delete test/example.test.js.
When testing DOM-dependent code, jsdom provides a browser-like environment:
import { describe, it, expect, beforeEach } from 'vitest';
import { JSDOM } from 'jsdom';
describe('DOM manipulation', () => {
let document;
beforeEach(() => {
const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>');
document = dom.window.document;
global.document = document;
});
it('should create elements', () => {
const div = document.createElement('div');
div.textContent = 'Hello';
expect(div.textContent).toBe('Hello');
});
});For GitHub Actions or other CI, tests run automatically with:
npm testConsider adding to your CI workflow:
- name: Run tests
run: npm test
- name: Generate coverage
run: npm run test:coverage"vitest: command not found"
vitest is in devDependencies in package.jsonnpm install"Cannot find module 'jsdom'"
npm install --save-dev jsdomTests not finding imports
Coverage not working
npm install --save-dev @vitest/coverage-v8Once setup is complete:
npm run test:watchnpm testnpm run test:coverageThis is a one-time setup. Once configured, focus on writing valuable tests rather than configuration.
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
skills
analyze-and-plan
block-collection-and-party
block-inventory
building-blocks
code-review
content-driven-development
content-modeling
docs-search
find-test-content
generate-import-html
identify-page-structure
page-decomposition
page-import
preview-import
scrape-webpage
testing-blocks