Когда: Каждый commit
Цель: Поймать баги на ранних этапах
JavaScript функции:
// Пример: tests/unit/cart.test.js
describe('Cart functions', () => {
test('addToCart adds item', () => {
const cart = new Cart();
cart.addItem({ id: 1, price: 100 });
expect(cart.items.length).toBe(1);
});
test('calculateTotal sums prices', () => {
const cart = new Cart();
cart.addItem({ id: 1, price: 100 });
cart.addItem({ id: 2, price: 200 });
expect(cart.calculateTotal()).toBe(300);
});
});
CSS переменные (из THEME-SPEC tokens.css):
// tests/unit/tokens.test.js
describe('Color tokens', () => {
test('Primary color defined', () => {
const root = getComputedStyle(document.documentElement);
expect(root.getPropertyValue('--color-primary')).toBeTruthy();
});
test('Accent color defined', () => {
const root = getComputedStyle(document.documentElement);
expect(root.getPropertyValue('--color-accent')).toBeTruthy();
});
});
Покрытие: > 80% для критических функций
ESLint (JavaScript):
// .eslintrc.json
{
"extends": ["eslint:recommended"],
"env": {
"browser": true,
"es2021": true
},
"rules": {
"no-console": "warn",
"no-unused-vars": "error"
}
}
Stylelint (CSS):
// .stylelintrc.json
{
"extends": ["stylelint-config-standard"],
"rules": {
"color-no-invalid-hex": true,
"declaration-no-important": true
}
}
PHPStan (PHP):
phpstan analyse ideal_theme.theme --level 5
TypeScript (если используем):
tsc --noEmit
PHPDoc validation:
/**
* @param string $name
* @return array
*/
function theme_get_suggestions(string $name): array {
// ...
}
Автоматический запуск перед каждым commit:
#!/bin/bash
# .git/hooks/pre-commit
echo "🔍 Running pre-commit checks..."
# 1. ESLint
echo "📝 ESLint..."
npm run lint:js || exit 1
# 2. Stylelint
echo "🎨 Stylelint..."
npm run lint:css || exit 1
# 3. PHPStan
echo "🐘 PHPStan..."
composer run phpstan || exit 1
# 4. Unit тесты
echo "✅ Unit tests..."
npm run test:unit || exit 1
echo "✅ All checks passed!"
{
"scripts": {
"lint:js": "eslint js/**/*.js",
"lint:css": "stylelint css/**/*.css",
"lint": "npm run lint:js && npm run lint:css",
"test:unit": "jest tests/unit",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage"
},
"devDependencies": {
"eslint": "^8.0.0",
"stylelint": "^15.0.0",
"jest": "^29.0.0",
"@testing-library/jest-dom": "^6.0.0"
}
}
{
"scripts": {
"phpstan": "phpstan analyse ideal_theme.theme --level 5",
"phpunit": "phpunit tests/php"
},
"require-dev": {
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.0"
}
}
Требования:
- ✅ ESLint: 0 errors
- ✅ Stylelint: 0 errors
- ✅ PHPStan: level 5, 0 errors
- ✅ Unit tests: 100% pass
- ✅ Code coverage: > 80%
Время выполнения: < 30 секунд
❌ Интеграция компонентов (Стратегия 2)
❌ Drupal установка (Стратегия 3)
❌ Браузерная совместимость (Стратегия 4)
❌ Визуальные регрессии (Стратегия 4)
# 1. Написал код
vim js/cart.js
# 2. Написал тест
vim tests/unit/cart.test.js
# 3. Запустил тесты
npm run test:unit
# 4. Проверил покрытие
npm run test:coverage
# coverage: 85% ✅
# 5. Commit (автоматически запустится pre-commit hook)
git add .
git commit -m "Add cart functionality"
# 🔍 Running pre-commit checks...
# ✅ All checks passed!
# 6. Push
git push
| Инструмент | Назначение | Команда |
|---|---|---|
| Jest | JS unit тесты | npm run test:unit |
| ESLint | JS linting | npm run lint:js |
| Stylelint | CSS linting | npm run lint:css |
| PHPStan | PHP static analysis | composer run phpstan |
| PHPUnit | PHP unit тесты | composer run phpunit |
После прохождения Development Testing → Стратегия 2: Integration Testing
Статус: Готово к использованию
Дата: 2026-01-07