mcp-wordpress 1.3.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +151 -772
  2. package/dist/cache/CacheInvalidation.d.ts.map +1 -1
  3. package/dist/client/CachedWordPressClient.d.ts.map +1 -1
  4. package/dist/client/CachedWordPressClient.js.map +1 -1
  5. package/dist/client/api.d.ts.map +1 -1
  6. package/dist/client/api.js +11 -3
  7. package/dist/client/api.js.map +1 -1
  8. package/dist/client/auth.js.map +1 -1
  9. package/dist/client/managers/AuthenticationManager.js.map +1 -1
  10. package/dist/client/managers/RequestManager.js +0 -1
  11. package/dist/client/managers/RequestManager.js.map +1 -1
  12. package/dist/config/ServerConfiguration.d.ts.map +1 -1
  13. package/dist/config/ServerConfiguration.js +18 -0
  14. package/dist/config/ServerConfiguration.js.map +1 -1
  15. package/dist/docs/MarkdownFormatter.js.map +1 -1
  16. package/dist/dxt-entry.d.ts +6 -0
  17. package/dist/dxt-entry.d.ts.map +1 -0
  18. package/dist/dxt-entry.js +38 -0
  19. package/dist/dxt-entry.js.map +1 -0
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +34 -2
  22. package/dist/index.js.map +1 -1
  23. package/dist/mcp-wordpress-1.5.0.tgz +0 -0
  24. package/dist/performance/MetricsCollector.d.ts.map +1 -1
  25. package/dist/performance/PerformanceAnalytics.d.ts.map +1 -1
  26. package/dist/performance/PerformanceAnalytics.js.map +1 -1
  27. package/dist/performance/PerformanceMonitor.d.ts.map +1 -1
  28. package/dist/security/InputValidator.js.map +1 -1
  29. package/dist/security/SecurityConfig.d.ts.map +1 -1
  30. package/dist/server/ToolRegistry.js.map +1 -1
  31. package/dist/tools/cache.js +1 -1
  32. package/dist/tools/cache.js.map +1 -1
  33. package/dist/tools/performance.js.map +1 -1
  34. package/docs/DOCKER.md +8 -1
  35. package/docs/api/README.md +82 -75
  36. package/docs/api/categories/site.md +2 -0
  37. package/docs/api/tools/wp_approve_comment.md +0 -6
  38. package/docs/api/tools/wp_cache_clear.md +5 -14
  39. package/docs/api/tools/wp_cache_info.md +5 -14
  40. package/docs/api/tools/wp_cache_stats.md +5 -14
  41. package/docs/api/tools/wp_cache_warm.md +5 -14
  42. package/docs/api/tools/wp_create_application_password.md +3 -11
  43. package/docs/api/tools/wp_create_category.md +3 -11
  44. package/docs/api/tools/wp_create_comment.md +5 -14
  45. package/docs/api/tools/wp_create_page.md +5 -13
  46. package/docs/api/tools/wp_create_post.md +6 -12
  47. package/docs/api/tools/wp_create_tag.md +3 -11
  48. package/docs/api/tools/wp_create_user.md +5 -13
  49. package/docs/api/tools/wp_delete_application_password.md +3 -11
  50. package/docs/api/tools/wp_delete_category.md +3 -11
  51. package/docs/api/tools/wp_delete_comment.md +3 -11
  52. package/docs/api/tools/wp_delete_media.md +3 -10
  53. package/docs/api/tools/wp_delete_page.md +3 -10
  54. package/docs/api/tools/wp_delete_post.md +4 -9
  55. package/docs/api/tools/wp_delete_tag.md +3 -11
  56. package/docs/api/tools/wp_delete_user.md +3 -10
  57. package/docs/api/tools/wp_get_application_passwords.md +3 -11
  58. package/docs/api/tools/wp_get_auth_status.md +3 -11
  59. package/docs/api/tools/wp_get_category.md +3 -11
  60. package/docs/api/tools/wp_get_comment.md +3 -11
  61. package/docs/api/tools/wp_get_current_user.md +3 -11
  62. package/docs/api/tools/wp_get_media.md +3 -11
  63. package/docs/api/tools/wp_get_page.md +3 -11
  64. package/docs/api/tools/wp_get_page_revisions.md +3 -11
  65. package/docs/api/tools/wp_get_post.md +4 -10
  66. package/docs/api/tools/wp_get_post_revisions.md +3 -11
  67. package/docs/api/tools/wp_get_site_settings.md +3 -10
  68. package/docs/api/tools/wp_get_tag.md +3 -11
  69. package/docs/api/tools/wp_get_user.md +3 -11
  70. package/docs/api/tools/wp_list_categories.md +3 -11
  71. package/docs/api/tools/wp_list_comments.md +3 -11
  72. package/docs/api/tools/wp_list_media.md +5 -14
  73. package/docs/api/tools/wp_list_pages.md +5 -14
  74. package/docs/api/tools/wp_list_posts.md +6 -13
  75. package/docs/api/tools/wp_list_tags.md +3 -11
  76. package/docs/api/tools/wp_list_users.md +3 -11
  77. package/docs/api/tools/wp_performance_alerts.md +7 -17
  78. package/docs/api/tools/wp_performance_benchmark.md +7 -17
  79. package/docs/api/tools/wp_performance_export.md +7 -17
  80. package/docs/api/tools/wp_performance_history.md +7 -17
  81. package/docs/api/tools/wp_performance_optimize.md +7 -17
  82. package/docs/api/tools/wp_performance_stats.md +7 -17
  83. package/docs/api/tools/wp_search_site.md +3 -11
  84. package/docs/api/tools/wp_spam_comment.md +3 -11
  85. package/docs/api/tools/wp_switch_auth_method.md +5 -14
  86. package/docs/api/tools/wp_test_auth.md +3 -11
  87. package/docs/api/tools/wp_update_category.md +3 -11
  88. package/docs/api/tools/wp_update_comment.md +5 -14
  89. package/docs/api/tools/wp_update_media.md +5 -14
  90. package/docs/api/tools/wp_update_page.md +5 -13
  91. package/docs/api/tools/wp_update_post.md +6 -12
  92. package/docs/api/tools/wp_update_site_settings.md +5 -14
  93. package/docs/api/tools/wp_update_tag.md +3 -11
  94. package/docs/api/tools/wp_update_user.md +5 -13
  95. package/docs/api/tools/wp_upload_media.md +5 -13
  96. package/docs/api/types/WordPressPost.md +0 -2
  97. package/docs/developer/API_REFERENCE.md +668 -0
  98. package/docs/developer/ARCHITECTURE.md +374 -0
  99. package/docs/developer/BUILD_SYSTEM.md +460 -0
  100. package/docs/developer/CONTRIBUTING.md +469 -0
  101. package/docs/developer/DEVELOPMENT_SETUP.md +463 -0
  102. package/docs/developer/DXT-DEBUG-BEST-PRACTICES.md +212 -0
  103. package/docs/developer/GITHUB_ACTIONS_SETUP.md +2 -1
  104. package/docs/developer/MAINTENANCE.md +5 -5
  105. package/docs/developer/MIGRATION_GUIDE.md +7 -5
  106. package/docs/developer/NPM_AUTH_SETUP.md +4 -4
  107. package/docs/developer/README.md +242 -0
  108. package/docs/developer/REFACTORING.md +15 -10
  109. package/docs/developer/RELEASE_PROCESS.md +528 -0
  110. package/docs/developer/TESTING.md +734 -0
  111. package/docs/releases/COMMUNITY_ANNOUNCEMENT_v1.1.2.md +9 -3
  112. package/docs/releases/RELEASE_NOTES_v1.1.2.md +4 -4
  113. package/docs/user-guides/DOCKER_SETUP.md +2 -2
  114. package/docs/user-guides/DTX_SETUP.md +3 -3
  115. package/docs/user-guides/DXT_INSTALLATION.md +149 -0
  116. package/docs/user-guides/NPX_SETUP.md +2 -2
  117. package/package.json +5 -4
  118. package/src/cache/CacheInvalidation.ts +1 -1
  119. package/src/client/CachedWordPressClient.ts +15 -15
  120. package/src/client/api.ts +54 -47
  121. package/src/client/auth.ts +88 -88
  122. package/src/client/managers/AuthenticationManager.ts +112 -112
  123. package/src/client/managers/RequestManager.ts +1 -1
  124. package/src/config/ServerConfiguration.ts +39 -0
  125. package/src/docs/MarkdownFormatter.ts +4 -4
  126. package/src/dxt-entry.cjs +55 -0
  127. package/src/dxt-entry.ts +55 -0
  128. package/src/index.ts +55 -2
  129. package/src/performance/MetricsCollector.ts +3 -3
  130. package/src/performance/PerformanceAnalytics.ts +16 -16
  131. package/src/performance/PerformanceMonitor.ts +1 -1
  132. package/src/security/InputValidator.ts +4 -4
  133. package/src/security/SecurityConfig.ts +1 -1
  134. package/src/server/ToolRegistry.ts +12 -12
  135. package/src/tools/cache.ts +1 -1
  136. package/src/tools/performance.ts +17 -17
  137. package/dist/mcp-wordpress-1.3.1.tgz +0 -0
@@ -0,0 +1,734 @@
1
+ # Testing Guide
2
+
3
+ Comprehensive guide to the test suite, testing strategies, and best practices for the MCP WordPress Server.
4
+
5
+ ## 🧪 Test Infrastructure
6
+
7
+ ### Current Test Status ✅
8
+
9
+ - **Main Test Suite**: 207/207 passed (100%)
10
+ - **Security Tests**: 40/40 passed (100%)
11
+ - **Performance Tests**: 8/8 passed (100%)
12
+ - **CI/CD Pipeline**: Fully functional
13
+ - **Code Coverage**: 95%+ coverage maintained
14
+
15
+ ### Test Architecture
16
+
17
+ ```text
18
+ tests/
19
+ ├── unit/ # Unit tests (17 tests)
20
+ │ ├── security-utils.test.js
21
+ │ ├── cache-manager.test.js
22
+ │ └── helper-functions.test.js
23
+ ├── integration/ # Integration tests (54 tests)
24
+ │ ├── wordpress-api.test.js
25
+ │ ├── multi-site.test.js
26
+ │ └── auth-methods.test.js
27
+ ├── security/ # Security tests (40 tests)
28
+ │ ├── input-validation.test.js
29
+ │ ├── auth-security.test.js
30
+ │ ├── penetration.test.js
31
+ │ └── vulnerability.test.js
32
+ ├── performance/ # Performance tests (8 tests)
33
+ │ ├── benchmarks.test.js
34
+ │ ├── regression.test.js
35
+ │ └── load-testing.test.js
36
+ ├── cache/ # Cache tests (37 tests)
37
+ │ ├── cache-functionality.test.js
38
+ │ ├── cache-invalidation.test.js
39
+ │ └── cache-performance.test.js
40
+ ├── property/ # Property-based tests (12 tests)
41
+ │ ├── data-structure.test.js
42
+ │ └── edge-cases.test.js
43
+ ├── config/ # Configuration tests (27 tests)
44
+ │ ├── schema-validation.test.js
45
+ │ ├── multi-site-config.test.js
46
+ │ └── environment-config.test.js
47
+ ├── contracts/ # Contract tests (mock)
48
+ │ ├── pact-testing.test.js
49
+ │ └── api-contracts.test.js
50
+ ├── typescript-build.test.js # TypeScript build tests (21 tests)
51
+ ├── auth-headers-fix.test.js # Authentication header tests
52
+ ├── config-loading.test.js # Configuration loading tests
53
+ ├── tool-validation.test.js # Tool validation tests
54
+ ├── env-loading.test.js # Environment loading tests (7 tests)
55
+ └── upload-timeout.test.js # Upload timeout tests (12 tests)
56
+ ```
57
+
58
+ ## 🚀 Running Tests
59
+
60
+ ### Quick Commands
61
+
62
+ ```bash
63
+ # Run all tests
64
+ npm test
65
+
66
+ # Run specific test suites
67
+ npm run test:unit # Unit tests only
68
+ npm run test:integration # Integration tests only
69
+ npm run test:security # Security tests only
70
+ npm run test:performance # Performance tests only
71
+ npm run test:cache # Cache tests only
72
+ npm run test:config # Configuration tests only
73
+ npm run test:property # Property-based tests only
74
+
75
+ # Development commands
76
+ npm run test:watch # Watch mode
77
+ npm run test:coverage # Generate coverage report
78
+ npm run test:fast # Quick validation
79
+ ```
80
+
81
+ ### Advanced Test Commands
82
+
83
+ ```bash
84
+ # TypeScript and build tests
85
+ npm run test:typescript # TypeScript compilation tests
86
+ npm run test:tools # Tool functionality tests
87
+ npm run test:mcp # MCP protocol tests
88
+
89
+ # Multi-site and authentication
90
+ npm run test:multisite # Multi-site configuration tests
91
+ npm run test:auth # Authentication method tests
92
+
93
+ # Contract testing
94
+ npm run test:contracts # Mock contract tests
95
+ npm run test:contracts:live # Live WordPress contract tests
96
+
97
+ # Docker test environment
98
+ npm run test:with-env # Tests with Docker WordPress
99
+ ./scripts/start-test-env.sh # Start test environment
100
+ ```
101
+
102
+ ## 🔧 Test Configuration
103
+
104
+ ### Jest Configuration
105
+
106
+ ```javascript
107
+ // jest.config.js
108
+ module.exports = {
109
+ testEnvironment: "node",
110
+ testMatch: ["**/tests/**/*.test.js"],
111
+ collectCoverageFrom: ["src/**/*.ts", "!src/**/*.d.ts", "!src/**/*.test.ts"],
112
+ coverageThreshold: {
113
+ global: {
114
+ branches: 50,
115
+ functions: 50,
116
+ lines: 50,
117
+ statements: 50,
118
+ },
119
+ },
120
+ setupFilesAfterEnv: ["<rootDir>/tests/setup.js"],
121
+ testTimeout: 30000,
122
+ };
123
+ ```
124
+
125
+ ### Test Environment Setup
126
+
127
+ ```javascript
128
+ // tests/setup.js
129
+ const { performance } = require("perf_hooks");
130
+
131
+ // Global test utilities
132
+ global.testUtils = {
133
+ createMockClient: () => ({
134
+ /* mock client */
135
+ }),
136
+ generateTestData: (schema) => ({
137
+ /* generated data */
138
+ }),
139
+ measurePerformance: (fn) => {
140
+ const start = performance.now();
141
+ const result = fn();
142
+ const duration = performance.now() - start;
143
+ return { result, duration };
144
+ },
145
+ };
146
+
147
+ // Setup test environment
148
+ beforeAll(() => {
149
+ process.env.NODE_ENV = "test";
150
+ process.env.DEBUG = "false";
151
+ });
152
+
153
+ afterAll(() => {
154
+ // Cleanup test environment
155
+ });
156
+ ```
157
+
158
+ ## 📝 Test Categories
159
+
160
+ ### Unit Tests
161
+
162
+ **Purpose**: Test individual components in isolation
163
+
164
+ **Coverage**:
165
+
166
+ - Security utilities and helper functions
167
+ - Cache manager functionality
168
+ - Input validation logic
169
+ - Error handling mechanisms
170
+
171
+ **Example**:
172
+
173
+ ```javascript
174
+ // tests/unit/security-utils.test.js
175
+ describe("SecurityUtils", () => {
176
+ test("should sanitize input correctly", () => {
177
+ const input = '<script>alert("xss")</script>';
178
+ const sanitized = SecurityUtils.sanitizeInput(input);
179
+ expect(sanitized).not.toContain("<script>");
180
+ });
181
+
182
+ test("should validate email format", () => {
183
+ expect(SecurityUtils.isValidEmail("test@example.com")).toBe(true);
184
+ expect(SecurityUtils.isValidEmail("invalid-email")).toBe(false);
185
+ });
186
+ });
187
+ ```
188
+
189
+ ### Integration Tests
190
+
191
+ **Purpose**: Test multi-component interactions with real WordPress instances
192
+
193
+ **Coverage**:
194
+
195
+ - WordPress API connectivity
196
+ - Multi-site configuration
197
+ - Authentication method validation
198
+ - End-to-end tool functionality
199
+
200
+ **Example**:
201
+
202
+ ```javascript
203
+ // tests/integration/wordpress-api.test.js
204
+ describe("WordPress API Integration", () => {
205
+ let client;
206
+
207
+ beforeAll(async () => {
208
+ client = new WordPressClient({
209
+ siteUrl: process.env.WORDPRESS_TEST_URL,
210
+ username: "admin",
211
+ appPassword: "test test test test test test",
212
+ });
213
+ });
214
+
215
+ test("should create and retrieve post", async () => {
216
+ const post = await client.posts.create({
217
+ title: "Test Post",
218
+ content: "Test content",
219
+ status: "publish",
220
+ });
221
+
222
+ expect(post.id).toBeDefined();
223
+ expect(post.title).toBe("Test Post");
224
+
225
+ const retrieved = await client.posts.get({ id: post.id });
226
+ expect(retrieved.title).toBe("Test Post");
227
+ });
228
+ });
229
+ ```
230
+
231
+ ### Security Tests
232
+
233
+ **Purpose**: Validate security measures and vulnerability protection
234
+
235
+ **Coverage**:
236
+
237
+ - Input validation and sanitization
238
+ - Authentication security
239
+ - Authorization checks
240
+ - XSS and SQL injection prevention
241
+ - Rate limiting and DoS protection
242
+
243
+ **Example**:
244
+
245
+ ```javascript
246
+ // tests/security/input-validation.test.js
247
+ describe("Input Validation Security", () => {
248
+ test("should reject malicious script injection", () => {
249
+ const maliciousInput = {
250
+ title: '<script>alert("xss")</script>',
251
+ content: '"><script>alert("xss")</script>',
252
+ };
253
+
254
+ expect(() => {
255
+ createPostSchema.parse(maliciousInput);
256
+ }).toThrow("Invalid input");
257
+ });
258
+
259
+ test("should prevent SQL injection in search", () => {
260
+ const sqlInjection = "'; DROP TABLE posts; --";
261
+ expect(() => {
262
+ searchSchema.parse({ query: sqlInjection });
263
+ }).toThrow("Invalid characters");
264
+ });
265
+ });
266
+ ```
267
+
268
+ ### Performance Tests
269
+
270
+ **Purpose**: Ensure performance standards and detect regressions
271
+
272
+ **Coverage**:
273
+
274
+ - Response time benchmarks
275
+ - Memory usage monitoring
276
+ - Cache performance validation
277
+ - Load testing scenarios
278
+
279
+ **Example**:
280
+
281
+ ```javascript
282
+ // tests/performance/benchmarks.test.js
283
+ describe("Performance Benchmarks", () => {
284
+ test("should handle post creation under 500ms", async () => {
285
+ const start = performance.now();
286
+
287
+ await client.posts.create({
288
+ title: "Performance Test",
289
+ content: "Test content",
290
+ });
291
+
292
+ const duration = performance.now() - start;
293
+ expect(duration).toBeLessThan(500);
294
+ });
295
+
296
+ test("should maintain cache hit rate above 70%", async () => {
297
+ // Warm cache
298
+ await client.posts.list();
299
+ await client.posts.list();
300
+
301
+ const stats = await client.cache.getStats();
302
+ expect(stats.hitRate).toBeGreaterThan(0.7);
303
+ });
304
+ });
305
+ ```
306
+
307
+ ### Cache Tests
308
+
309
+ **Purpose**: Validate caching functionality and performance
310
+
311
+ **Coverage**:
312
+
313
+ - Cache hit and miss scenarios
314
+ - Cache invalidation logic
315
+ - Multi-site cache isolation
316
+ - Cache performance optimization
317
+
318
+ **Example**:
319
+
320
+ ```javascript
321
+ // tests/cache/cache-functionality.test.js
322
+ describe("Cache Functionality", () => {
323
+ test("should cache GET requests", async () => {
324
+ const client = new CachedWordPressClient(config);
325
+
326
+ // First request - cache miss
327
+ const start1 = performance.now();
328
+ const posts1 = await client.posts.list();
329
+ const duration1 = performance.now() - start1;
330
+
331
+ // Second request - cache hit
332
+ const start2 = performance.now();
333
+ const posts2 = await client.posts.list();
334
+ const duration2 = performance.now() - start2;
335
+
336
+ expect(posts1).toEqual(posts2);
337
+ expect(duration2).toBeLessThan(duration1 * 0.1); // 90% faster
338
+ });
339
+
340
+ test("should invalidate cache on updates", async () => {
341
+ const client = new CachedWordPressClient(config);
342
+
343
+ // Cache posts list
344
+ await client.posts.list();
345
+
346
+ // Create new post
347
+ await client.posts.create({
348
+ title: "New Post",
349
+ content: "Content",
350
+ });
351
+
352
+ // List should be refreshed
353
+ const posts = await client.posts.list();
354
+ expect(posts.some((p) => p.title === "New Post")).toBe(true);
355
+ });
356
+ });
357
+ ```
358
+
359
+ ### Property-Based Tests
360
+
361
+ **Purpose**: Test with generated data to find edge cases
362
+
363
+ **Coverage**:
364
+
365
+ - Data structure validation
366
+ - Edge case discovery
367
+ - Input boundary testing
368
+ - Randomized testing scenarios
369
+
370
+ **Example**:
371
+
372
+ ```javascript
373
+ // tests/property/data-structure.test.js
374
+ const fc = require("fast-check");
375
+
376
+ describe("Property-Based Testing", () => {
377
+ test("should handle any valid post data", () => {
378
+ fc.assert(
379
+ fc.property(
380
+ fc.record({
381
+ title: fc.string({ minLength: 1, maxLength: 200 }),
382
+ content: fc.string(),
383
+ status: fc.constantFrom("draft", "publish", "private"),
384
+ }),
385
+ async (postData) => {
386
+ const result = await client.posts.create(postData);
387
+ expect(result.title).toBe(postData.title);
388
+ expect(result.status).toBe(postData.status);
389
+ },
390
+ ),
391
+ );
392
+ });
393
+ });
394
+ ```
395
+
396
+ ### Configuration Tests
397
+
398
+ **Purpose**: Validate configuration loading and validation
399
+
400
+ **Coverage**:
401
+
402
+ - Multi-site configuration validation
403
+ - Environment variable loading
404
+ - Schema validation with Zod
405
+ - Configuration error handling
406
+
407
+ **Example**:
408
+
409
+ ```javascript
410
+ // tests/config/schema-validation.test.js
411
+ describe("Configuration Schema Validation", () => {
412
+ test("should validate multi-site configuration", () => {
413
+ const validConfig = {
414
+ sites: [
415
+ {
416
+ id: "site1",
417
+ name: "Test Site",
418
+ config: {
419
+ WORDPRESS_SITE_URL: "https://example.com",
420
+ WORDPRESS_USERNAME: "admin",
421
+ WORDPRESS_APP_PASSWORD: "test test test test test test",
422
+ },
423
+ },
424
+ ],
425
+ };
426
+
427
+ expect(() => {
428
+ multiSiteConfigSchema.parse(validConfig);
429
+ }).not.toThrow();
430
+ });
431
+
432
+ test("should reject invalid site URLs", () => {
433
+ const invalidConfig = {
434
+ sites: [
435
+ {
436
+ id: "site1",
437
+ name: "Test Site",
438
+ config: {
439
+ WORDPRESS_SITE_URL: "invalid-url",
440
+ WORDPRESS_USERNAME: "admin",
441
+ WORDPRESS_APP_PASSWORD: "password",
442
+ },
443
+ },
444
+ ],
445
+ };
446
+
447
+ expect(() => {
448
+ multiSiteConfigSchema.parse(invalidConfig);
449
+ }).toThrow("Invalid URL");
450
+ });
451
+ });
452
+ ```
453
+
454
+ ## 🐳 Docker Test Environment
455
+
456
+ ### Docker Environment Setup
457
+
458
+ ```bash
459
+ # Start complete test environment
460
+ ./scripts/start-test-env.sh
461
+
462
+ # This creates:
463
+ # - WordPress instance on http://localhost:8081
464
+ # - MySQL database
465
+ # - Pre-configured admin user
466
+ # - Application password setup
467
+ ```
468
+
469
+ ### Docker Compose Configuration
470
+
471
+ ```yaml
472
+ # docker-compose.test.yml
473
+ version: "3.8"
474
+ services:
475
+ wordpress:
476
+ image: wordpress:latest
477
+ ports:
478
+ - "8081:80"
479
+ environment:
480
+ WORDPRESS_DB_HOST: db
481
+ WORDPRESS_DB_USER: wordpress
482
+ WORDPRESS_DB_PASSWORD: wordpress
483
+ WORDPRESS_DB_NAME: wordpress
484
+ depends_on:
485
+ - db
486
+ volumes:
487
+ - ./tests/wordpress-config.php:/var/www/html/wp-config.php
488
+
489
+ db:
490
+ image: mysql:8.0
491
+ environment:
492
+ MYSQL_DATABASE: wordpress
493
+ MYSQL_USER: wordpress
494
+ MYSQL_PASSWORD: wordpress
495
+ MYSQL_ROOT_PASSWORD: root
496
+ volumes:
497
+ - db_data:/var/lib/mysql
498
+
499
+ volumes:
500
+ db_data:
501
+ ```
502
+
503
+ ### Test Environment Usage
504
+
505
+ ```bash
506
+ # Run tests with Docker environment
507
+ npm run test:with-env
508
+
509
+ # Run specific tests against Docker
510
+ WORDPRESS_TEST_URL=http://localhost:8081 npm test
511
+
512
+ # Clean up test environment
513
+ docker-compose -f docker-compose.test.yml down -v
514
+ ```
515
+
516
+ ## 📊 Test Reporting
517
+
518
+ ### Coverage Reports
519
+
520
+ ```bash
521
+ # Generate coverage report
522
+ npm run test:coverage
523
+
524
+ # Coverage report locations:
525
+ # - coverage/lcov-report/index.html (HTML report)
526
+ # - coverage/lcov.info (LCOV format)
527
+ # - coverage/coverage-final.json (JSON format)
528
+ ```
529
+
530
+ ### Performance Metrics
531
+
532
+ ```bash
533
+ # Performance test reporting
534
+ npm run test:performance
535
+
536
+ # Generates:
537
+ # - Performance benchmarks
538
+ # - Regression detection
539
+ # - Memory usage analysis
540
+ # - Response time metrics
541
+ ```
542
+
543
+ ## 🔄 Continuous Integration
544
+
545
+ ### GitHub Actions Workflow
546
+
547
+ ```yaml
548
+ # .github/workflows/ci.yml
549
+ name: CI/CD Pipeline
550
+
551
+ on: [push, pull_request]
552
+
553
+ jobs:
554
+ test:
555
+ runs-on: ubuntu-latest
556
+ strategy:
557
+ matrix:
558
+ node-version: [18, 20]
559
+ steps:
560
+ - uses: actions/checkout@v4
561
+ - name: Setup Node.js
562
+ uses: actions/setup-node@v4
563
+ with:
564
+ node-version: ${{ matrix.node-version }}
565
+ - name: Install dependencies
566
+ run: npm ci
567
+ - name: Run tests
568
+ run: npm test
569
+ - name: Run security tests
570
+ run: npm run test:security
571
+ - name: Run performance tests
572
+ run: npm run test:performance
573
+ - name: Upload coverage
574
+ uses: codecov/codecov-action@v3
575
+ ```
576
+
577
+ ### Test Quality Gates
578
+
579
+ **Pre-Commit Hooks**:
580
+
581
+ - ESLint validation
582
+ - TypeScript type checking
583
+ - Quick test validation
584
+ - Security scanning
585
+
586
+ **Pre-Push Hooks**:
587
+
588
+ - Full test suite execution
589
+ - Security audit
590
+ - Performance regression tests
591
+ - Coverage threshold validation
592
+
593
+ ## 🧩 Writing Tests
594
+
595
+ ### Test Structure
596
+
597
+ ```javascript
598
+ // Standard test structure
599
+ describe("Component Name", () => {
600
+ // Setup
601
+ beforeAll(() => {
602
+ // One-time setup
603
+ });
604
+
605
+ beforeEach(() => {
606
+ // Per-test setup
607
+ });
608
+
609
+ // Test cases
610
+ describe("method name", () => {
611
+ test("should do something specific", () => {
612
+ // Arrange
613
+ const input = "test data";
614
+
615
+ // Act
616
+ const result = component.method(input);
617
+
618
+ // Assert
619
+ expect(result).toBe("expected output");
620
+ });
621
+ });
622
+
623
+ // Cleanup
624
+ afterEach(() => {
625
+ // Per-test cleanup
626
+ });
627
+
628
+ afterAll(() => {
629
+ // One-time cleanup
630
+ });
631
+ });
632
+ ```
633
+
634
+ ### Test Best Practices
635
+
636
+ 1. **Descriptive Test Names**: Use clear, specific test descriptions
637
+ 2. **Arrange-Act-Assert Pattern**: Structure tests consistently
638
+ 3. **Mock External Dependencies**: Isolate units under test
639
+ 4. **Test Edge Cases**: Include boundary conditions and error scenarios
640
+ 5. **Performance Aware**: Include performance assertions where relevant
641
+ 6. **Security Focused**: Test security-related functionality thoroughly
642
+
643
+ ### Mock Utilities
644
+
645
+ ```javascript
646
+ // tests/utils/mocks.js
647
+ export const mockWordPressClient = {
648
+ posts: {
649
+ create: jest.fn(),
650
+ update: jest.fn(),
651
+ delete: jest.fn(),
652
+ get: jest.fn(),
653
+ list: jest.fn(),
654
+ },
655
+ auth: {
656
+ authenticate: jest.fn(),
657
+ getAuthHeaders: jest.fn(),
658
+ },
659
+ };
660
+
661
+ export const mockConfig = {
662
+ siteUrl: "https://test.example.com",
663
+ username: "testuser",
664
+ appPassword: "test test test test test test",
665
+ };
666
+ ```
667
+
668
+ ## 📈 Test Metrics
669
+
670
+ ### Key Performance Indicators
671
+
672
+ - **Test Coverage**: 95%+ maintained
673
+ - **Test Execution Time**: < 5 minutes for full suite
674
+ - **Test Reliability**: 100% pass rate in CI/CD
675
+ - **Security Test Coverage**: 100% of security features tested
676
+ - **Performance Regression**: < 20% performance degradation threshold
677
+
678
+ ### Test Health Dashboard
679
+
680
+ ```bash
681
+ # Check test health
682
+ npm run test:health
683
+
684
+ # Outputs:
685
+ # - Test execution time trends
686
+ # - Coverage percentage by component
687
+ # - Flaky test detection
688
+ # - Performance regression alerts
689
+ ```
690
+
691
+ ## 🔍 Debugging Tests
692
+
693
+ ### Debug Mode
694
+
695
+ ```bash
696
+ # Run tests with debug output
697
+ DEBUG=true npm test
698
+
699
+ # Debug specific test file
700
+ DEBUG=true npm test -- tests/integration/wordpress-api.test.js
701
+
702
+ # Debug with Node.js inspector
703
+ node --inspect-brk ./node_modules/.bin/jest --runInBand
704
+ ```
705
+
706
+ ### Test Debugging Tools
707
+
708
+ ```javascript
709
+ // Debug utility functions
710
+ const debug = require("debug")("test:debug");
711
+
712
+ describe("Debug Example", () => {
713
+ test("should debug test execution", () => {
714
+ debug("Starting test execution");
715
+
716
+ const result = someFunction();
717
+ debug("Function result:", result);
718
+
719
+ expect(result).toBeDefined();
720
+ });
721
+ });
722
+ ```
723
+
724
+ ## 📚 Further Reading
725
+
726
+ - **[Architecture Guide](ARCHITECTURE.md)** - System design and patterns
727
+ - **[API Reference](API_REFERENCE.md)** - Complete technical API documentation
728
+ - **[Security Guidelines](SECURITY_DEVELOPMENT.md)** - Security best practices
729
+ - **[Performance Guide](PERFORMANCE_DEVELOPMENT.md)** - Performance optimization
730
+
731
+ ---
732
+
733
+ **Need help with testing?** This comprehensive testing infrastructure ensures code quality, security,
734
+ and performance. All tests are designed to be fast, reliable, and maintainable.