Skip to main content
Hooks allow you to run setup and cleanup code before and after your tests. They are TypeScript/JavaScript functions that execute in your project’s context, enabling you to:
  • 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 as hook_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

Node.js must be installed for hooks to run. TypeScript helpers require tsx which is installed automatically via npx.
For path aliases in tsconfig.json, install tsconfig-paths:

Troubleshooting

Create .bugster/hooks.ts in your project root or specify the correct file_path for each hook.
If you’re using path aliases in your tsconfig.json, install tsconfig-paths:
Ensure your helper function returns a value. Check that you’re returning the correct data type.
Check your helper function for errors. Verify that any external APIs or databases are accessible.