Skip to content

feat: add Jest matchers with global configuration and e2e testing#23

Merged
ike18t merged 5 commits intomasterfrom
matcher
Jul 15, 2025
Merged

feat: add Jest matchers with global configuration and e2e testing#23
ike18t merged 5 commits intomasterfrom
matcher

Conversation

@ike18t
Copy link
Owner

@ike18t ike18t commented Jul 15, 2025

Summary

This PR adds comprehensive Jest matcher support for testing WireMock interactions, along with e2e testing infrastructure and improved build configuration.

✨ New Features

Jest Matchers

  • toHaveBeenRequested(options?) - Verify stub received at least one request
  • toHaveBeenRequestedWith(expected, options?) - Verify stub received request with specific payload
  • toHaveBeenRequestedTimes(expectedCount, options?) - Verify stub received exact number of requests
  • Built-in retry logic with configurable delays for async operations
  • Global configuration via Configuration.setMatcherOptions()
  • TypeScript support with proper type declarations

E2E Testing

  • Testcontainers integration for real WireMock server testing
  • Comprehensive test coverage for all matcher functionality
  • Complex payload testing with nested JSON objects
  • Request counting and verification scenarios

Developer Experience

  • Separate build configuration (tsconfig.build.json) for clean artifacts
  • Improved ESLint configuration with proper ignores
  • Comprehensive documentation with examples and API reference
  • Maintained test file linting while excluding from builds

🔧 Technical Details

Configuration

// Global matcher defaults
Configuration.setMatcherOptions({
  retries: 10,  // Default: 15
  delay: 100    // Default: 200ms
});

// Per-matcher overrides
await expect(stubId).toHaveBeenRequested({ retries: 5, delay: 50 });

Usage Example

import { wiremockMapperMatchers } from 'wiremock-mapper';

expect.extend(wiremockMapperMatchers);

// Test endpoint was called with specific payload
await expect(stubId).toHaveBeenRequestedWith({
  name: 'John Doe',
  email: 'john@example.com'
});

📦 Breaking Changes

None - all changes are additive and backward compatible.

🧪 Testing

- All existing tests continue to pass
- Added 5 new e2e tests using testcontainers
- Test coverage maintained at >90%
- Linting passes for all files including test files

📚 Documentation

- Added comprehensive Jest matchers section to README
- Included setup instructions, API reference, and examples
- Added troubleshooting guidance
- Updated with global configuration options

🚀 Release Notes

This will be released as v0.7.1 with the following highlights:
- Jest matchers for improved testing experience
- E2e testing infrastructure
- Enhanced developer tooling
- Comprehensive documentation updates

ike18t and others added 5 commits July 15, 2025 13:12
- Add wiremockMapperMatchers with toHaveBeenRequested, toHaveBeenRequestedWith, and toHaveBeenRequestedTimes
- Add global matcher configuration via Configuration.setMatcherOptions
- Include built-in retry logic for async request verification
- Export Jest matchers as optional utility from main index
- Add TypeScript declarations for Jest matcher interface

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add comprehensive e2e tests using testcontainers for WireMock
- Test Jest matchers with real WireMock server
- Add testcontainers dependency
- Test complex JSON payloads and request verification
- Verify global and local matcher configuration

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add separate tsconfig.build.json for clean build artifacts
- Update ESLint config to ignore dist directory
- Maintain linting for spec files while excluding from build
- Update build script to use separate TypeScript config

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add Jest matchers section with setup instructions
- Document all three matchers: toHaveBeenRequested, toHaveBeenRequestedWith, toHaveBeenRequestedTimes
- Add global configuration documentation
- Include matcher options table and examples
- Add complete test example showing typical usage

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@ike18t ike18t merged commit 7758aa0 into master Jul 15, 2025
4 checks passed
@ike18t ike18t mentioned this pull request Jul 15, 2025
@ike18t ike18t deleted the matcher branch July 15, 2025 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant