Node.js QuickStart Guide
This guide will walk you through integrating Hypertest into your Node.js application. In about 10 minutes, you'll capture your first tests, run them against your code, and see HyperTest automatically catch a bug.
Prerequisites
A working Node.js application.
Access to your HyperTest dashboard to get your API Key and Service ID.
Before adding HyperTest code, confirm your application starts correctly on your machine.
This ensures that any future issues are related to the integration, not your base application.
Start your app and hit a few requests to confirm this before proceeding further.
1. Update Project Files
First, modify package.json to include the required dependencies and scripts.
1. Update package.json
Open your package.json and merge the following dependencies, devDependencies, and scripts.
2. Install Packages
After saving the file, run this command in your terminal. It will read the updated package.json and install the new dependencies.
3. Add Config Files in project root
Create two configuration files in your project's root directory.
1. .ht-nycrc (Tells nyc how to report coverage for HyperTest)
2. .htConf.js (Main configuration for the HyperTest CLI)
2. Instrument Your Application
Now, add the HyperTest SDK to your app's main entry point (e.g., index.js, server.js, app.ts etc).
1. Initialize the SDK
Add this code to the very top of your entry file, before any other imports.
2. Mark the App as Ready
Call htSdk.markAppAsReady() once your app is listening for requests.
3. Capture & Establish Baseline
Let's generate your initial test suite and lock it in as the baseline.
1. Capture Tests
Start your app using the special nyc script.
Now, use your app and make API calls (via Postman, cURL, etc.) to the endpoints you want to test. Check your HyperTest dashboard to see tests appear in real-time. When you're done, stop your application (Ctrl+C).
2. Establish Coverage Baseline
Run this command to save the current code coverage as the "golden" version.
The update-coverage
command is only supposed to be run on your master branch beacuse that establishes your current baseline of both reponses and code coverage
The --skip-git-uncommited-check
flag is for debugging only which lets update-coverage
command run on any branch
After integration, you'll not be using the --skip-git-uncommited-check
flag
4. Catch Your First Bug!
This is the magic moment. Let's introduce a bug and watch HyperTest catch it.
1. Make a code change
In one of your API endpoints captured previously, introduce a small breaking change (e.g., change a response message, status code, or calculation).
2. Run the Test
Execute the main test command.
HyperTest will now start your app, replay the captured tests against your modified code, and compare the behavior against the baseline.
3. See the Results
The CLI will output a link to the test run on your HyperTest dashboard. Click it to see a detailed report of the regression you just introduced, complete with payload diffs and coverage changes.
Congratulations! You have successfully integrated HyperTest.
Last updated