fast-api-tester 1.0.12 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/readme +71 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-api-tester",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "Ultra-fast, connection-pooled API testing library for Node.js",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/readme CHANGED
@@ -187,8 +187,78 @@ Every execution run updates `test-report.html` and persists historical execution
187
187
  - **Historical Execution Trend**: Stacked bar chart visualizing test pass/fail trends over time across consecutive heartbeats.
188
188
  - **Detailed Table View**: Complete summary including HTTP Method, Endpoint, Status Code, Measured Latency, SLA Target, and exact error stack/messages for failing requests.
189
189
 
190
+ ### 🐌 Bandwidth Throttling Simulator
191
+
192
+ Test your API's resilience and SLA assertions under real-world network conditions. The bandwidth simulator introduces precise artificial latency to mimic poor connections, ensuring your timeouts and SLA limits are truly battle-tested before hitting production.
193
+
194
+ **Available Profiles:**
195
+
196
+ - `Slow-3G`: 500ms delay
197
+ - `3G`: 300ms delay
198
+ - `4G`: 100ms delay
199
+ - `None`: 0ms delay (Default)
200
+ - Custom: Pass any raw `number` to simulate exact millisecond latency.
201
+
202
+ **Example Usage:**
203
+
204
+ ```typescript
205
+ import { ApiEngine } from './index';
206
+
207
+ // Initialize the engine with a 3G network profile (adds 300ms artificial delay)
208
+ const api = new ApiEngine()
209
+ .setBaseUrl('https://api.example.com')
210
+ .simulateNetwork('3G');
211
+
212
+ api.startHeartbeat(async () => {
213
+ const res = await api.get('/health');
214
+
215
+ // If the server takes 250ms to respond, total measured latency will be 550ms.
216
+ // This helps ensure your application handles degraded network states gracefully.
217
+ res.expectLatencyUnder(500);
218
+ });
219
+ ```
220
+
221
+ ### ⚖️ Assertion Modes (Hard vs. Soft)
222
+
223
+ The framework supports two distinct validation behaviors to give you maximum flexibility when testing APIs:
224
+
225
+ - **Hard Assertions (Default)**: Designed for strict control flows where subsequent steps depend entirely on the success of the current step. When a hard assertion fails (e.g., unexpected status code or SLA violation), it immediately records the failure, updates the test execution record, and throws a fatal `Error` that aborts the test suite execution instantly.
226
+ - **Soft Assertions**: Designed for comprehensive test reporting where you want to execute an entire suite or multiple checks without stopping at the first error. When a soft assertion fails, it logs a warning, flags the failure in the test record, and continues test execution. This ensures all endpoints are tested and included in the final HTML report and telemetry history, rather than failing fast.
227
+
228
+ #### How the Implementation Works
229
+
230
+ **1. Configuration & Mode State (`AssertionMode`)**
231
+
232
+ - **Global Level**: You can configure the engine-wide default behavior using `engine.setAssertionMode('soft')` or `'hard'`. Every request made through the engine inherits this baseline mode.
233
+ - **Inline Level**: You can override the mode on a per-response chain using `.soft()` or `.hard()` right before your assertions.
234
+
235
+ **2. Centralized Error Handling (`handleAssertionFailure`)**
236
+
237
+ Instead of directly throwing errors inside every expectation method, assertions pass their failure message to a centralized handler:
238
+
239
+ - It updates the `TestExecutionRecord` by setting `passed = false` and appends the error message.
240
+ - If the mode is `'hard'`, it throws an `Error` immediately.
241
+ - If the mode is `'soft'`, it catches/bypasses the throw, logs a warning message to the console (`console.warn`), and allows the script execution to proceed normally.
242
+
243
+ ```typescript
244
+ const engine = new ApiEngine()
245
+ .setBaseUrl('https://api.example.com')
246
+ .setAssertionMode('soft'); // Make all requests log failures but continue
247
+
248
+ await engine.startHeartbeat(async () => {
249
+ // Even if this fails (e.g., latency > 50ms), execution continues!
250
+ await engine.get('/users').then(res => res.expectStatusOk().expectLatencyUnder(50));
251
+
252
+ // This request STILL executes and gets recorded in the HTML report
253
+ await engine.get('/orders').then(res => res.expectStatus(200));
254
+
255
+ // Abort suite hard AT THE END if any soft assertions failed above
256
+ engine.assertAll();
257
+ });
258
+ ```
259
+
190
260
  ---
191
261
 
192
262
  ## 📜 License
193
263
 
194
- [MIT](./LICENSE) © Kushan Amarasiri
264
+ [MIT](./LICENSE) © Kushan Amarasiri