Testing your hooks
Cloudhooks provides comprehensive testing capabilities to ensure your hooks work as intended before deployment. You can test your hooks directly from the "Hook" tab using the "Run test" button.
Testing Capabilities
Running Tests
- Hook code must be saved before running tests
- Code must be free of syntax errors before it can be tested.
- Tests execute your hook with a customizable payload
- Real-time execution logs are displayed
- Test results show success or failure status
Test Environment Features
API Library Tab
- Complete documentation for all available actions
- Example code for each action
- Ready-to-use code snippets
- Detailed parameter descriptions
Payload Tab
- For webhook triggers: Edit pre-populated payloads based on webhook topic
- For external triggers: Modify example payload from trigger configuration
- Test different scenarios with customized payload data
- JSON validation and formatting
Test Results Tab
- Clear success/failure status indication
- Success criteria: No error log entries present
- Comprehensive log entries showing:
- Action logs: Records of action invocations
- Console logs: Output from console.log() messages
- Error logs: Uncaught exceptions and console.error() messages
Tips for improving your testing experience
Using test mode
The hook context includes an isTestMode property that lets you implement different behaviors during testing. This is particularly useful for:
- Using development API endpoints
- Testing with mock data
- Implementing test-specific logic
Example:
Working with Shopify APIs
Important considerations when testing Shopify API interactions:
- Shopify API calls are always live, even in test mode
- Consider using:
- Test-specific identifiers in your payloads
- A dedicated development store for testing
- Conditional logic based on isTestMode
Preventing timeouts
Hook tests timeout after 30 seconds. To avoid timeouts:
- Properly handle all promises:
- Use await or .then() syntax
- Always wait for promises to complete
- Implement error handling:
- Catch and handle promise rejections
- Avoid unhandled errors that can crash the test runner
Debugging with logs
Effective debugging strategies:
- Use logging to track execution flow
- Mark important data points
- Monitor payload processing
- Track API responses
For detailed logging guidance, see our debug with log entries documentation.