- Create test data before tests run
- Clean up data after tests complete
- Pass dynamic values to your test steps
Hook Structure
Add hooks to your test YAML file:test.yaml
Hook Definition Fields
string
required
Name of the exported function to call.
string
default:".bugster/hooks.ts"
Path to TypeScript file containing the helper function.
array
Array of arguments to pass to the function.
string
Variable name to store the result for later use.
Creating Helper Functions
Default Location
Create a.bugster/hooks.ts file in your project:
.bugster/hooks.ts
Custom File Locations
You can specify helpers from any TypeScript file in your project:Template Variables
Use{{variableName}} to reference values from previous hooks:
Simple Access
Nested Object Access
Array Access
Passing Hook Data to Tests
Hook results are passed to the test ashook_context. Reference them in your test steps using {{data.variableName}}:
Execution Behavior
Before Hooks
Before hooks run sequentially before test execution. If any before hook fails,
the test fails with the hook error. Results are stored in context for
subsequent hooks.
After Hooks
After hooks run after test completion, regardless of test result. Failures are
logged but don’t affect the test result. Use after hooks for cleanup
operations.
Complete Example
test.yaml
Requirements
For path aliases in tsconfig.json, installtsconfig-paths:
Troubleshooting
Hooks file not found
Hooks file not found
Create
.bugster/hooks.ts in your project root or specify the correct file_path for each hook.Cannot find module
Cannot find module
If you’re using path aliases in your tsconfig.json, install
tsconfig-paths:Hook returned empty output
Hook returned empty output
Ensure your helper function returns a value. Check that you’re returning the
correct data type.
Hook failed with error
Hook failed with error
Check your helper function for errors. Verify that any external APIs or databases are accessible.
