Initial commit
This commit is contained in:
12
.claude-plugin/plugin.json
Normal file
12
.claude-plugin/plugin.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "leapmultix-skill-practicing-tdd-with-jest",
|
||||
"description": "Skill practicing-tdd-with-jest from LeapMultix",
|
||||
"version": "1.0.0",
|
||||
"author": {
|
||||
"name": "Julien LE SAUX",
|
||||
"email": "contact@jls42.org"
|
||||
},
|
||||
"skills": [
|
||||
"./skills"
|
||||
]
|
||||
}
|
||||
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# leapmultix-skill-practicing-tdd-with-jest
|
||||
|
||||
Skill practicing-tdd-with-jest from LeapMultix
|
||||
45
plugin.lock.json
Normal file
45
plugin.lock.json
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"$schema": "internal://schemas/plugin.lock.v1.json",
|
||||
"pluginId": "gh:jls42/leapmultix:leapmultix-marketplace/skills/practicing-tdd-with-jest",
|
||||
"normalized": {
|
||||
"repo": null,
|
||||
"ref": "refs/tags/v20251128.0",
|
||||
"commit": "fa06c8b41a71f1bad1325fd82473145589d0b3e2",
|
||||
"treeHash": "1a2ef3d7c416d8e6fe021a3ad8da9a4049bd97d7f10682c7249032694636b888",
|
||||
"generatedAt": "2025-11-28T10:19:14.141275Z",
|
||||
"toolVersion": "publish_plugins.py@0.2.0"
|
||||
},
|
||||
"origin": {
|
||||
"remote": "git@github.com:zhongweili/42plugin-data.git",
|
||||
"branch": "master",
|
||||
"commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390",
|
||||
"repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data"
|
||||
},
|
||||
"manifest": {
|
||||
"name": "leapmultix-skill-practicing-tdd-with-jest",
|
||||
"description": "Skill practicing-tdd-with-jest from LeapMultix",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"content": {
|
||||
"files": [
|
||||
{
|
||||
"path": "README.md",
|
||||
"sha256": "47f01ec460b39d5bf44b1fb10535ac3b86152a5a42cd47dc6cd43665c5b0d170"
|
||||
},
|
||||
{
|
||||
"path": ".claude-plugin/plugin.json",
|
||||
"sha256": "a1dbb4e44d2872fd6b8cfe546e1a4fecdc2968bcc4e70ebe065fc7990bec5bc2"
|
||||
},
|
||||
{
|
||||
"path": "skills/practicing-tdd-with-jest/SKILL.md",
|
||||
"sha256": "cc8296288431fa5f765dfb54d351c1b4846d7e48af24e6f1534b7015f1c9bc8b"
|
||||
}
|
||||
],
|
||||
"dirSha256": "1a2ef3d7c416d8e6fe021a3ad8da9a4049bd97d7f10682c7249032694636b888"
|
||||
},
|
||||
"security": {
|
||||
"scannedAt": null,
|
||||
"scannerVersion": null,
|
||||
"flags": []
|
||||
}
|
||||
}
|
||||
167
skills/practicing-tdd-with-jest/SKILL.md
Normal file
167
skills/practicing-tdd-with-jest/SKILL.md
Normal file
@@ -0,0 +1,167 @@
|
||||
---
|
||||
name: practicing-tdd-with-jest
|
||||
description: Implements features following Test-Driven Development RED/GREEN/REFACTOR cycle with Jest. Use when adding new features, fixing bugs, or refactoring existing code
|
||||
allowed-tools: Read, Write, Grep, Glob, Bash
|
||||
---
|
||||
|
||||
# Test-Driven Development avec Jest
|
||||
|
||||
Implémente code en suivant cycle TDD RED/GREEN/REFACTOR avec Jest.
|
||||
|
||||
## Table des matières
|
||||
|
||||
- [Quand utiliser](#quand-utiliser)
|
||||
- [Cycle TDD : RED → GREEN → REFACTOR](#cycle-tdd--red--green--refactor)
|
||||
- [Scripts npm](#scripts-npm)
|
||||
- [Structure tests (Arrange-Act-Assert)](#structure-tests-arrange-act-assert)
|
||||
- [Assertions Jest essentielles](#assertions-jest-essentielles)
|
||||
- [Mocking](#mocking)
|
||||
- [Tests spécialisés](#tests-spécialisés)
|
||||
- [Couverture](#couverture)
|
||||
- [Bonnes pratiques](#bonnes-pratiques)
|
||||
- [Workflow](#workflow)
|
||||
- [Checklist](#checklist)
|
||||
- [En cas de doute](#en-cas-de-doute)
|
||||
|
||||
## Quand utiliser
|
||||
|
||||
- Implémentation nouvelles features
|
||||
- Correction bugs avec reproduction
|
||||
- Refactoring code existant
|
||||
- Ajout comportements modules
|
||||
- Validation logique complexe
|
||||
|
||||
## Cycle TDD : RED → GREEN → REFACTOR
|
||||
|
||||
**RED (Test échoue) :**
|
||||
|
||||
1. Identifier comportement
|
||||
2. Écrire test AVANT code
|
||||
3. Test DOIT échouer ❌
|
||||
|
||||
**GREEN (Test passe) :**
|
||||
|
||||
1. Code minimum possible
|
||||
2. Pas d'optimisation/généralisation
|
||||
3. Faire passer test uniquement ✅
|
||||
|
||||
**REFACTOR (Améliorer) :**
|
||||
|
||||
1. Nettoyer code (noms, structure)
|
||||
2. Éliminer duplications
|
||||
3. Vérifier tests passent toujours ✅
|
||||
|
||||
## Scripts npm
|
||||
|
||||
- `npm test` - Tous tests
|
||||
- `npm run test:watch` - Mode watch
|
||||
- `npm run test:coverage` - Avec couverture
|
||||
|
||||
## Structure tests (Arrange-Act-Assert)
|
||||
|
||||
**AAA Pattern :**
|
||||
|
||||
- **Arrange :** Préparer données
|
||||
- **Act :** Exécuter action
|
||||
- **Assert :** Vérifier résultat
|
||||
|
||||
**Grouping :**
|
||||
|
||||
- `describe()` - Grouper tests liés
|
||||
- `test()` / `it()` - Tests individuels
|
||||
- `beforeEach()` / `afterEach()` - Setup/cleanup
|
||||
|
||||
**Nommage :** Descriptif ("should do X when Y", "handles edge case Z")
|
||||
|
||||
## Assertions Jest essentielles
|
||||
|
||||
- Égalité: `toBe()` (strict), `toEqual()` (profonde)
|
||||
- Booléens: `toBeTruthy()`, `toBeFalsy()`, `toBeNull()`, `toBeUndefined()`
|
||||
- Nombres: `toBeGreaterThan()`, `toBeLessThan()`, `toBeCloseTo()`
|
||||
- Arrays: `toContain()`, `toHaveLength()`
|
||||
- Exceptions: `toThrow()`, `toThrow(ErrorClass)`
|
||||
|
||||
Voir documentation Jest pour liste complète.
|
||||
|
||||
## Mocking
|
||||
|
||||
**Fonctions :**
|
||||
|
||||
- `jest.fn()` - Mock simple
|
||||
- `mockReturnValue()` - Valeur
|
||||
- `mockResolvedValue()` / `mockRejectedValue()` - Promesses
|
||||
- `toHaveBeenCalled()`, `toHaveBeenCalledWith(args)`, `toHaveBeenCalledTimes(n)`
|
||||
|
||||
**Modules :** Isoler code testé, éviter dépendances externes (API, localStorage)
|
||||
|
||||
## Tests spécialisés
|
||||
|
||||
**Async :** `async/await` recommandé, ou `expect().resolves/rejects`
|
||||
|
||||
**DOM/UI :** jsdom simule DOM - créer, attacher, exécuter, vérifier, cleanup
|
||||
|
||||
**Canvas (jeux arcade) :** Mock context, mock performance.now(), tester logique séparément rendu, tests d'état
|
||||
|
||||
## Couverture
|
||||
|
||||
**Cibles :** Branches > 80%, Functions > 80%, Lines > 80%, Statements > 80%
|
||||
|
||||
Lance `npm run test:coverage`, examine rapport.
|
||||
|
||||
## Bonnes pratiques
|
||||
|
||||
**Do's :**
|
||||
|
||||
- Test AVANT code TOUJOURS
|
||||
- Un test à la fois (RED → GREEN → REFACTOR)
|
||||
- Tests descriptifs (noms clairs)
|
||||
- Isolés, indépendants
|
||||
- Edge cases (null, undefined, limites)
|
||||
- Rapides (< 100ms idéal)
|
||||
|
||||
**Don'ts :**
|
||||
|
||||
- Pas de code avant test
|
||||
- Pas de tests trop larges
|
||||
- Pas de tests fragiles (timing, random)
|
||||
- Pas de RED ignoré (test inutile)
|
||||
- Pas de .skip tests
|
||||
|
||||
## Workflow
|
||||
|
||||
1. **Requirement :** Cas normaux + edge cases
|
||||
2. **Test RED :** Doit échouer
|
||||
3. **Code GREEN :** Minimum pour passer
|
||||
4. **REFACTOR :** Améliorer, tests verts
|
||||
5. **Répéter :** Couverture > 80%
|
||||
|
||||
## Checklist
|
||||
|
||||
- [ ] Test écrit AVANT code
|
||||
- [ ] Test échoue (RED)
|
||||
- [ ] Code minimum
|
||||
- [ ] Test passe (GREEN)
|
||||
- [ ] Refactorisé si besoin
|
||||
- [ ] Noms descriptifs
|
||||
- [ ] AAA pattern
|
||||
- [ ] Mocks isolent
|
||||
- [ ] Edge cases
|
||||
- [ ] Couverture > 80%
|
||||
- [ ] Tests rapides
|
||||
|
||||
## En cas de doute
|
||||
|
||||
**Règles absolues :**
|
||||
|
||||
1. Cycle RED → GREEN → REFACTOR OBLIGATOIRE
|
||||
2. Test doit échouer d'abord (sinon inutile)
|
||||
3. Code minimum (pas sur-engineering)
|
||||
4. Refactor après GREEN seulement
|
||||
5. Tests restent verts après refactor
|
||||
6. Couverture > 80%
|
||||
|
||||
**Références :**
|
||||
|
||||
- Tests existants patterns
|
||||
- jest.config.cjs - Configuration
|
||||
- npm run test:coverage - État actual
|
||||
Reference in New Issue
Block a user