k6-perf-reporter 1.0.0

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 (113) hide show
  1. package/.claude/settings.local.json +54 -0
  2. package/.config.example.json +8 -0
  3. package/.config.json +8 -0
  4. package/.eslintrc.json +18 -0
  5. package/.github/workflows/build.yml +30 -0
  6. package/.github/workflows/release.yml +44 -0
  7. package/README.md +449 -0
  8. package/dist/cli-reporter.d.ts +5 -0
  9. package/dist/cli-reporter.d.ts.map +1 -0
  10. package/dist/cli-reporter.js +71 -0
  11. package/dist/cli-reporter.js.map +1 -0
  12. package/dist/cli.d.ts +2 -0
  13. package/dist/cli.d.ts.map +1 -0
  14. package/dist/cli.js +43 -0
  15. package/dist/cli.js.map +1 -0
  16. package/dist/config.d.ts +14 -0
  17. package/dist/config.d.ts.map +1 -0
  18. package/dist/config.js +26 -0
  19. package/dist/config.js.map +1 -0
  20. package/dist/data-collector.d.ts +14 -0
  21. package/dist/data-collector.d.ts.map +1 -0
  22. package/dist/data-collector.js +51 -0
  23. package/dist/data-collector.js.map +1 -0
  24. package/dist/data-extractor.d.ts +31 -0
  25. package/dist/data-extractor.d.ts.map +1 -0
  26. package/dist/data-extractor.js +250 -0
  27. package/dist/data-extractor.js.map +1 -0
  28. package/dist/explore.d.ts +2 -0
  29. package/dist/explore.d.ts.map +1 -0
  30. package/dist/explore.js +27 -0
  31. package/dist/explore.js.map +1 -0
  32. package/dist/index.d.ts +7 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +43 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/influx-client.d.ts +16 -0
  37. package/dist/influx-client.d.ts.map +1 -0
  38. package/dist/influx-client.interface.d.ts +21 -0
  39. package/dist/influx-client.interface.d.ts.map +1 -0
  40. package/dist/influx-client.interface.js +3 -0
  41. package/dist/influx-client.interface.js.map +1 -0
  42. package/dist/influx-client.js +35 -0
  43. package/dist/influx-client.js.map +1 -0
  44. package/dist/influx-data-extractor.d.ts +112 -0
  45. package/dist/influx-data-extractor.d.ts.map +1 -0
  46. package/dist/influx-data-extractor.interface.d.ts +21 -0
  47. package/dist/influx-data-extractor.interface.d.ts.map +1 -0
  48. package/dist/influx-data-extractor.interface.js +3 -0
  49. package/dist/influx-data-extractor.interface.js.map +1 -0
  50. package/dist/influx-data-extractor.js +445 -0
  51. package/dist/influx-data-extractor.js.map +1 -0
  52. package/dist/influx.d.ts +122 -0
  53. package/dist/influx.d.ts.map +1 -0
  54. package/dist/influx.js +899 -0
  55. package/dist/influx.js.map +1 -0
  56. package/dist/logger.d.ts +7 -0
  57. package/dist/logger.d.ts.map +1 -0
  58. package/dist/logger.js +12 -0
  59. package/dist/logger.js.map +1 -0
  60. package/dist/metrics-collector.d.ts +10 -0
  61. package/dist/metrics-collector.d.ts.map +1 -0
  62. package/dist/metrics-collector.js +99 -0
  63. package/dist/metrics-collector.js.map +1 -0
  64. package/dist/metrics-collector.test.d.ts +2 -0
  65. package/dist/metrics-collector.test.d.ts.map +1 -0
  66. package/dist/metrics-collector.test.js +235 -0
  67. package/dist/metrics-collector.test.js.map +1 -0
  68. package/dist/reporters/cli-reporter.d.ts +9 -0
  69. package/dist/reporters/cli-reporter.d.ts.map +1 -0
  70. package/dist/reporters/cli-reporter.js +141 -0
  71. package/dist/reporters/cli-reporter.js.map +1 -0
  72. package/dist/reporters/cli.d.ts +5 -0
  73. package/dist/reporters/cli.d.ts.map +1 -0
  74. package/dist/reporters/cli.js +150 -0
  75. package/dist/reporters/cli.js.map +1 -0
  76. package/dist/reporters/index.d.ts +3 -0
  77. package/dist/reporters/index.d.ts.map +1 -0
  78. package/dist/reporters/index.js +8 -0
  79. package/dist/reporters/index.js.map +1 -0
  80. package/dist/reporters/json-reporter.d.ts +5 -0
  81. package/dist/reporters/json-reporter.d.ts.map +1 -0
  82. package/dist/reporters/json-reporter.js +18 -0
  83. package/dist/reporters/json-reporter.js.map +1 -0
  84. package/dist/reporters/json.d.ts +5 -0
  85. package/dist/reporters/json.d.ts.map +1 -0
  86. package/dist/reporters/json.js +70 -0
  87. package/dist/reporters/json.js.map +1 -0
  88. package/dist/reporters/markdown.d.ts +5 -0
  89. package/dist/reporters/markdown.d.ts.map +1 -0
  90. package/dist/reporters/markdown.js +87 -0
  91. package/dist/reporters/markdown.js.map +1 -0
  92. package/dist/reports.d.ts +11 -0
  93. package/dist/reports.d.ts.map +1 -0
  94. package/dist/reports.js +325 -0
  95. package/dist/reports.js.map +1 -0
  96. package/dist/types.d.ts +113 -0
  97. package/dist/types.d.ts.map +1 -0
  98. package/dist/types.js +4 -0
  99. package/dist/types.js.map +1 -0
  100. package/dist/utils.d.ts +2 -0
  101. package/dist/utils.d.ts.map +1 -0
  102. package/dist/utils.js +19 -0
  103. package/dist/utils.js.map +1 -0
  104. package/package.json +33 -0
  105. package/src/cli.ts +47 -0
  106. package/src/config.ts +31 -0
  107. package/src/data-collector.ts +66 -0
  108. package/src/influx-client.ts +48 -0
  109. package/src/influx-data-extractor.ts +722 -0
  110. package/src/reporters/cli-reporter.ts +169 -0
  111. package/src/reporters/index.ts +2 -0
  112. package/src/reporters/json-reporter.ts +15 -0
  113. package/tsconfig.json +20 -0
@@ -0,0 +1,54 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(code .:*)",
5
+ "Bash(npm run:*)",
6
+ "Bash(npm install:*)",
7
+ "Bash(npx tsx:*)",
8
+ "Bash(INFLUX_TOKEN='JFP9pZu3Sp134rkCZ6gT7FtSBmQRWgl8VmVhFMHTXrbkhKQ3LrvrM4FXECR7Lr8MsDGWLIsU7IJFcjL_QHwvqA==' npx tsx src/cli.ts generate --scenario storefront_main_page --start-time '2026-04-02T21:17:28.487Z' --end-time '2026-04-02T21:22:02.858Z' --format cli)",
9
+ "Bash(node /tmp/test-duration.js)",
10
+ "Bash(git add:*)",
11
+ "Bash(git commit -m ':*)",
12
+ "Bash(git push:*)",
13
+ "Bash(ls k6-report-*)",
14
+ "Bash(rm k6-report-*)",
15
+ "Bash(git commit:*)",
16
+ "Read(//tmp/**)",
17
+ "Bash(ls -t k6-report-*.json)",
18
+ "Bash(xargs cat:*)",
19
+ "Bash(INFLUX_TOKEN='JFP9pZu3Sp134rkCZ6gT7FtSBmQRWgl8VmVhFMHTXrbkhKQ3LrvrM4FXECR7Lr8MsDGWLIsU7IJFcjL_QHwvqA==' tsx src/cli.ts generate --scenario storefront_main_page --start-time '2026-04-02T21:17:28.487Z' --end-time '2026-04-02T21:22:02.858Z' --format csv)",
20
+ "Bash(INFLUX_TOKEN='JFP9pZu3Sp134rkCZ6gT7FtSBmQRWgl8VmVhFMHTXrbkhKQ3LrvrM4FXECR7Lr8MsDGWLIsU7IJFcjL_QHwvqA==' tsx src/cli.ts generate --scenario storefront_main_page --start-time '2026-04-02T21:17:28.487Z' --end-time '2026-04-02T21:22:02.858Z' -f csv)",
21
+ "Bash(ls -t k6-report-*.csv)",
22
+ "Bash(ls -t k6-report-*.html)",
23
+ "Bash(INFLUX_TOKEN='JFP9pZu3Sp134rkCZ6gT7FtSBmQRWgl8VmVhFMHTXrbkhKQ3LrvrM4FXECR7Lr8MsDGWLIsU7IJFcjL_QHwvqA==' npx tsx src/explore.ts)",
24
+ "Bash(k6-perf-reporter:*)",
25
+ "Bash(chmod +x .githooks/pre-commit)",
26
+ "Bash(git config:*)",
27
+ "Bash(chmod +x:*)",
28
+ "Bash(ls:*)",
29
+ "Bash(git reset:*)",
30
+ "Bash(grep -n 'r.scenario == \"${scenario}\"' /Users/spirohov/github/k6-reporter/src/influx.ts)",
31
+ "Bash(sed -i '' '/scenario: string,/d' /Users/spirohov/github/k6-reporter/src/influx.ts)",
32
+ "Bash(sed -i '' 's/_scenario: string,//' /Users/spirohov/github/k6-reporter/src/influx.ts)",
33
+ "Bash(git checkout:*)",
34
+ "Bash(python3 /tmp/update_influx.py)",
35
+ "Bash(python3 /tmp/fix_scenario.py)",
36
+ "Bash(grep -B 2 -A 2 'r.runId == \"\\\\${runId}\"')",
37
+ "Bash(python3 /tmp/fix_range.py)",
38
+ "Bash(bash /tmp/test_runid.sh)",
39
+ "Bash(grep:*)",
40
+ "Bash(npm test:*)",
41
+ "Bash(sed -i 's/IInfluxQueryClient/IInfluxDataExtractor/g' /Users/spirohov/github/k6-reporter/src/influx-data-extractor.ts)",
42
+ "Bash(sed -i 's/InfluxQueryClient/InfluxDataExtractor/g' /Users/spirohov/github/k6-reporter/src/influx-data-extractor.ts)",
43
+ "Bash(sed -i 's|from \"./influx-client.interface\"|from \"./influx-data-extractor.interface\"|g' /Users/spirohov/github/k6-reporter/src/influx-data-extractor.ts)",
44
+ "Bash(git status:*)",
45
+ "Bash(git rm:*)",
46
+ "Bash(clear:*)",
47
+ "Bash(npm list:*)",
48
+ "Bash(git:*)",
49
+ "Bash(npm audit:*)",
50
+ "Bash(npm publish:*)",
51
+ "Bash(npm login:*)"
52
+ ]
53
+ }
54
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "influx": {
3
+ "url": "http://localhost:8086",
4
+ "token": "${INFLUX_TOKEN}",
5
+ "org": "my-org",
6
+ "bucket": "k6"
7
+ }
8
+ }
package/.config.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "influx": {
3
+ "url": "https://influx.cmn.monomarket.tech",
4
+ "token": "JFP9pZu3Sp134rkCZ6gT7FtSBmQRWgl8VmVhFMHTXrbkhKQ3LrvrM4FXECR7Lr8MsDGWLIsU7IJFcjL_QHwvqA==",
5
+ "org": "ced1cdfb28534a3e",
6
+ "bucket": "jmeter"
7
+ }
8
+ }
package/.eslintrc.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "parser": "@typescript-eslint/parser",
3
+ "extends": [
4
+ "eslint:recommended",
5
+ "plugin:@typescript-eslint/recommended"
6
+ ],
7
+ "parserOptions": {
8
+ "ecmaVersion": 2020,
9
+ "sourceType": "module"
10
+ },
11
+ "env": {
12
+ "node": true,
13
+ "es2020": true
14
+ },
15
+ "rules": {
16
+ "@typescript-eslint/no-explicit-any": "warn"
17
+ }
18
+ }
@@ -0,0 +1,30 @@
1
+ name: Build and Check
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - uses: actions/setup-node@v4
17
+ with:
18
+ node-version: '20'
19
+
20
+ - name: Install dependencies
21
+ run: npm ci
22
+
23
+ - name: Lint
24
+ run: npm run lint
25
+
26
+ - name: Type check
27
+ run: npm run type-check
28
+
29
+ - name: Build
30
+ run: npm run build
@@ -0,0 +1,44 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+ permissions:
12
+ contents: write
13
+ packages: write
14
+ id-token: write
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - uses: actions/setup-node@v4
20
+ with:
21
+ node-version: '20'
22
+ registry-url: 'https://registry.npmjs.org'
23
+
24
+ - name: Install dependencies
25
+ run: npm ci
26
+
27
+ - name: Run lint
28
+ run: npm run lint
29
+
30
+ - name: Run type check
31
+ run: npm run type-check
32
+
33
+ - name: Build
34
+ run: npm run build
35
+
36
+ - name: Publish to npm
37
+ run: npm publish --provenance
38
+
39
+ - name: Create GitHub Release
40
+ uses: softprops/action-gh-release@v1
41
+ with:
42
+ generate_release_notes: true
43
+ env:
44
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
package/README.md ADDED
@@ -0,0 +1,449 @@
1
+ # k6-perf-reporter
2
+
3
+ A comprehensive reporting tool for k6 performance tests with InfluxDB 2 integration. Generates beautiful HTML, PDF, CSV, and JSON reports with key performance metrics.
4
+
5
+ ## Features
6
+
7
+ - **Multiple Report Formats**: HTML, PDF, CSV, JSON, and CLI output
8
+ - **InfluxDB 2 Integration**: Query test metrics directly from InfluxDB
9
+ - **Key Metrics**: Response time percentiles (p50, p95, p99), throughput, error rates, and error breakdown
10
+ - **Professional Reports**: Beautiful, interactive HTML reports with responsive design
11
+ - **CLI Tool**: Command-line interface for automated report generation
12
+ - **Library Support**: Use as a TypeScript/JavaScript library in your own tools
13
+
14
+ ## Quick Start
15
+
16
+ ```bash
17
+ # Install dependencies
18
+ npm install
19
+
20
+ # Build the project
21
+ npm run build
22
+
23
+ # Generate an HTML report
24
+ npx tsx src/cli.ts generate \
25
+ --scenario api-load-test \
26
+ --start-time "2024-01-01T00:00:00Z" \
27
+ --end-time "2024-01-01T01:00:00Z" \
28
+ --format html
29
+ ```
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ npm install
35
+ npm run build
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ### As a CLI Tool
41
+
42
+ #### HTML Report
43
+ ```bash
44
+ npx tsx src/cli.ts generate \
45
+ --scenario api-load-test \
46
+ --start-time "2024-01-01T00:00:00Z" \
47
+ --end-time "2024-01-01T01:00:00Z" \
48
+ --format html
49
+ ```
50
+
51
+ Generates a beautiful, interactive HTML report with:
52
+ - Color-coded performance metric cards
53
+ - Responsive design that works on all devices
54
+ - Executive summary section
55
+ - Detailed error breakdown table
56
+ - Professional styling with gradient headers
57
+
58
+ #### PDF Report
59
+ ```bash
60
+ npx tsx src/cli.ts generate \
61
+ --scenario api-load-test \
62
+ --start-time "2024-01-01T00:00:00Z" \
63
+ --end-time "2024-01-01T01:00:00Z" \
64
+ --format pdf
65
+ ```
66
+
67
+ Creates a printable PDF version of the HTML report for archival and sharing.
68
+
69
+ #### CSV Report
70
+ ```bash
71
+ npx tsx src/cli.ts generate \
72
+ --scenario api-load-test \
73
+ --start-time "2024-01-01T00:00:00Z" \
74
+ --end-time "2024-01-01T01:00:00Z" \
75
+ --format csv
76
+ ```
77
+
78
+ Exports metrics in CSV format for import into Excel, Google Sheets, or data analysis tools.
79
+
80
+ Example CSV output:
81
+ ```
82
+ k6 Performance Test Report
83
+ Test Name,api-load-test
84
+ Generated,2024-01-01T12:00:00Z
85
+
86
+ RESPONSE TIME METRICS
87
+ Metric,Value (ms)
88
+ P50,125.45
89
+ P95,385.67
90
+ P99,892.34
91
+
92
+ THROUGHPUT & REQUESTS
93
+ Metric,Value
94
+ Throughput (req/s),156.23
95
+ Total Requests,10000
96
+ Successful Requests,9950
97
+ Failed Requests,50
98
+ Error Rate (%),0.50
99
+
100
+ ERROR BREAKDOWN
101
+ Error Type,Count
102
+ ConnectionError,30
103
+ TimeoutError,15
104
+ HTTPError500,5
105
+ ```
106
+
107
+ #### JSON Report
108
+ ```bash
109
+ npx tsx src/cli.ts generate \
110
+ --scenario api-load-test \
111
+ --start-time "2024-01-01T00:00:00Z" \
112
+ --end-time "2024-01-01T01:00:00Z" \
113
+ --format json
114
+ ```
115
+
116
+ Generates machine-readable JSON for programmatic access:
117
+ ```json
118
+ {
119
+ "testName": "api-load-test",
120
+ "generatedAt": "2024-01-01T12:00:00Z",
121
+ "metrics": {
122
+ "responseTime": {
123
+ "p50": 125.45,
124
+ "p95": 385.67,
125
+ "p99": 892.34
126
+ },
127
+ "throughput": {
128
+ "requestsPerSecond": 156.23
129
+ },
130
+ "requests": {
131
+ "total": 10000,
132
+ "successful": 9950,
133
+ "failed": 50,
134
+ "errorRate": 0.50
135
+ },
136
+ "errors": {
137
+ "ConnectionError": 30,
138
+ "TimeoutError": 15,
139
+ "HTTPError500": 5
140
+ }
141
+ }
142
+ }
143
+ ```
144
+
145
+ #### CLI Output
146
+ ```bash
147
+ npx tsx src/cli.ts generate \
148
+ --scenario api-load-test \
149
+ --start-time "2024-01-01T00:00:00Z" \
150
+ --end-time "2024-01-01T01:00:00Z" \
151
+ --format cli
152
+ ```
153
+
154
+ Displays a pretty-printed table in your terminal:
155
+ ```
156
+ ━━━ k6 Performance Test Report ━━━
157
+
158
+ Test: api-load-test
159
+ Generated: 1/1/2024, 12:00:00 PM
160
+
161
+ 📊 Response Times
162
+ ┌────────┬───────────┐
163
+ │ Metric │ Value │
164
+ ├────────┼───────────┤
165
+ │ P50 │ 125.45 ms │
166
+ │ P95 │ 385.67 ms │
167
+ │ P99 │ 892.34 ms │
168
+ └────────┴───────────┘
169
+
170
+ ⚡ Throughput & Requests
171
+ ┌──────────────────────┬──────────┐
172
+ │ Metric │ Value │
173
+ ├──────────────────────┼──────────┤
174
+ │ Throughput │ 156.23 req/s │
175
+ │ Total Requests │ 10000 │
176
+ │ Successful Requests │ 9950 │
177
+ │ Failed Requests │ 50 │
178
+ └──────────────────────┴──────────┘
179
+
180
+ ❌ Error Analysis
181
+ ┌────────────┬─────────┐
182
+ │ Metric │ Value │
183
+ ├────────────┼─────────┤
184
+ │ Error Rate │ 0.50 % │
185
+ └────────────┴─────────┘
186
+
187
+ Overall Status: ✓ PASS
188
+
189
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━
190
+ ```
191
+
192
+ ### As a Library
193
+
194
+ ```typescript
195
+ import {
196
+ InfluxQueryClient,
197
+ ReportGenerator,
198
+ CLIReporter,
199
+ } from "k6-perf-reporter";
200
+
201
+ const influxConfig = {
202
+ url: "http://localhost:8086",
203
+ token: "your-token",
204
+ org: "your-org",
205
+ bucket: "k6",
206
+ };
207
+
208
+ const influxClient = new InfluxQueryClient(influxConfig);
209
+ const reportGenerator = new ReportGenerator(influxClient);
210
+
211
+ // Generate metrics for the last hour
212
+ const metrics = await reportGenerator.generateMetrics(
213
+ "api-load-test",
214
+ "-1h",
215
+ "now()"
216
+ );
217
+
218
+ // Print to CLI
219
+ const cliReporter = new CLIReporter();
220
+ cliReporter.printMetricsTable(metrics, "api-load-test");
221
+
222
+ // Or generate formatted reports
223
+ const htmlReport = reportGenerator.generateHTMLReport(metrics, "api-load-test");
224
+ const jsonReport = reportGenerator.generateJSONReport(metrics, "api-load-test");
225
+ const csvReport = reportGenerator.generateCSVReport(metrics, "api-load-test");
226
+
227
+ // Save to file
228
+ import fs from "fs";
229
+ fs.writeFileSync("report.html", htmlReport);
230
+ fs.writeFileSync("report.json", jsonReport);
231
+ fs.writeFileSync("report.csv", csvReport);
232
+ ```
233
+
234
+ ## Metrics Included
235
+
236
+ - **Response Times**: p50, p95, p99 percentiles (milliseconds)
237
+ - **Throughput**: Requests per second
238
+ - **Requests**: Total, successful, and failed counts
239
+ - **Error Rate**: Percentage of failed requests
240
+ - **Error Breakdown**: Distribution of error types with counts
241
+
242
+ ## Time Format Examples
243
+
244
+ For InfluxDB time queries, use relative or absolute formats:
245
+
246
+ ```bash
247
+ # Last hour
248
+ --start-time "-1h" --end-time "now()"
249
+
250
+ # Last 24 hours
251
+ --start-time "-24h" --end-time "now()"
252
+
253
+ # Specific date range (ISO 8601)
254
+ --start-time "2024-01-01T00:00:00Z" --end-time "2024-01-02T00:00:00Z"
255
+
256
+ # Last 30 minutes
257
+ --start-time "-30m" --end-time "now()"
258
+ ```
259
+
260
+ ## Environment Variables
261
+
262
+ Set these for easier usage:
263
+
264
+ ```bash
265
+ export INFLUX_URL=http://localhost:8086
266
+ export INFLUX_TOKEN=your-influx-token
267
+ export INFLUX_ORG=your-org
268
+ export INFLUX_BUCKET=k6
269
+ ```
270
+
271
+ Then use:
272
+ ```bash
273
+ npx tsx src/cli.ts generate \
274
+ --url $INFLUX_URL \
275
+ --token $INFLUX_TOKEN \
276
+ --org $INFLUX_ORG \
277
+ --bucket $INFLUX_BUCKET \
278
+ --test-name api-load-test \
279
+ --start-time "-1h" \
280
+ --end-time "now()" \
281
+ --format html
282
+ ```
283
+
284
+ ## Prerequisites
285
+
286
+ - Node.js 16+
287
+ - InfluxDB 2.x with k6 test data
288
+ - For PDF generation: Puppeteer (included in dependencies)
289
+
290
+ ## InfluxDB Setup
291
+
292
+ Configure your k6 tests to output to InfluxDB 2:
293
+
294
+ ```javascript
295
+ import http from "k6/http";
296
+ import { check } from "k6";
297
+
298
+ export const options = {
299
+ vus: 10,
300
+ duration: "1m",
301
+ thresholds: {
302
+ http_req_duration: ["p(95)<500", "p(99)<1000"],
303
+ http_req_failed: ["rate<0.1"],
304
+ },
305
+ };
306
+
307
+ export default function () {
308
+ const res = http.get("http://api.example.com/users");
309
+ check(res, {
310
+ "status is 200": (r) => r.status === 200,
311
+ "response time < 500ms": (r) => r.timings.duration < 500,
312
+ });
313
+ }
314
+ ```
315
+
316
+ Run with InfluxDB output:
317
+ ```bash
318
+ k6 run script.js \
319
+ -o xk6-influxdb=http://localhost:8086/testdata \
320
+ --tag testName=api-load-test
321
+ ```
322
+
323
+ ## Full Example Workflow
324
+
325
+ 1. **Run your k6 test with InfluxDB output:**
326
+ ```bash
327
+ k6 run load-test.js \
328
+ -o xk6-influxdb=http://localhost:8086/k6db \
329
+ --tag testName=checkout-flow-test
330
+ ```
331
+
332
+ 2. **Wait for test to complete, then generate reports:**
333
+ ```bash
334
+ # Generate HTML report
335
+ npx tsx src/cli.ts generate \
336
+ --url http://localhost:8086 \
337
+ --token your-token \
338
+ --org your-org \
339
+ --bucket k6db \
340
+ --test-name checkout-flow-test \
341
+ --start-time "-30m" \
342
+ --end-time "now()" \
343
+ --format html \
344
+ --output reports/checkout-flow-test.html
345
+
346
+ # Generate JSON for CI/CD integration
347
+ npx tsx src/cli.ts generate \
348
+ --url http://localhost:8086 \
349
+ --token your-token \
350
+ --org your-org \
351
+ --bucket k6db \
352
+ --test-name checkout-flow-test \
353
+ --start-time "-30m" \
354
+ --end-time "now()" \
355
+ --format json \
356
+ --output reports/checkout-flow-test.json
357
+
358
+ # Generate CSV for spreadsheet analysis
359
+ npx tsx src/cli.ts generate \
360
+ --url http://localhost:8086 \
361
+ --token your-token \
362
+ --org your-org \
363
+ --bucket k6db \
364
+ --test-name checkout-flow-test \
365
+ --start-time "-30m" \
366
+ --end-time "now()" \
367
+ --format csv \
368
+ --output reports/checkout-flow-test.csv
369
+
370
+ # Print summary to terminal
371
+ npx tsx src/cli.ts generate \
372
+ --url http://localhost:8086 \
373
+ --token your-token \
374
+ --org your-org \
375
+ --bucket k6db \
376
+ --test-name checkout-flow-test \
377
+ --start-time "-30m" \
378
+ --end-time "now()" \
379
+ --format cli
380
+ ```
381
+
382
+ 3. **Integrate with CI/CD:**
383
+ ```bash
384
+ #!/bin/bash
385
+ # ci-report.sh
386
+
387
+ TEST_NAME="production-api-test"
388
+ START_TIME="-1h"
389
+ END_TIME="now()"
390
+
391
+ # Generate report
392
+ npx tsx src/cli.ts generate \
393
+ --url $INFLUX_URL \
394
+ --token $INFLUX_TOKEN \
395
+ --org $INFLUX_ORG \
396
+ --bucket $INFLUX_BUCKET \
397
+ --scenario $TEST_NAME \
398
+ --start-time $START_TIME \
399
+ --end-time $END_TIME \
400
+ --format json \
401
+ --output test-results.json
402
+
403
+ # Parse and check thresholds
404
+ ERROR_RATE=$(jq '.metrics.requests.errorRate' test-results.json)
405
+ if (( $(echo "$ERROR_RATE > 5.0" | bc -l) )); then
406
+ echo "Error rate too high: $ERROR_RATE%"
407
+ exit 1
408
+ fi
409
+
410
+ echo "Test passed! Error rate: $ERROR_RATE%"
411
+ ```
412
+
413
+ ## Development
414
+
415
+ ```bash
416
+ # Install dependencies
417
+ npm install
418
+
419
+ # Type checking
420
+ npm run type-check
421
+
422
+ # Linting
423
+ npm run lint
424
+
425
+ # Build
426
+ npm run build
427
+
428
+ # Development mode
429
+ npm run dev
430
+ ```
431
+
432
+ ## Architecture
433
+
434
+ ```
435
+ src/
436
+ ├── influx.ts # InfluxDB client and query logic
437
+ ├── reports.ts # Report generation (HTML, CSV, JSON)
438
+ ├── cli-reporter.ts # CLI table formatting
439
+ ├── cli.ts # Command-line interface
440
+ └── index.ts # Library exports
441
+ ```
442
+
443
+ ## License
444
+
445
+ MIT
446
+
447
+ ## Contributing
448
+
449
+ Contributions are welcome! Please feel free to submit a Pull Request.
@@ -0,0 +1,5 @@
1
+ import { TestMetrics } from "./influx";
2
+ export declare class CLIReporter {
3
+ printMetricsTable(metrics: TestMetrics, testName: string): void;
4
+ }
5
+ //# sourceMappingURL=cli-reporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-reporter.d.ts","sourceRoot":"","sources":["../src/cli-reporter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,qBAAa,WAAW;IACtB,iBAAiB,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;CAkEhE"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CLIReporter = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const table_1 = require("table");
9
+ class CLIReporter {
10
+ printMetricsTable(metrics, testName) {
11
+ console.log("\n" + chalk_1.default.bold.cyan("━━━ k6 Performance Test Report ━━━\n"));
12
+ console.log(chalk_1.default.bold(`Test: ${testName}`));
13
+ console.log(chalk_1.default.gray(`Generated: ${new Date().toLocaleString()}\n`));
14
+ // Response Times
15
+ console.log(chalk_1.default.bold.yellow("📊 Response Times"));
16
+ const responseTimes = [
17
+ ["Metric", "Value"],
18
+ ["P50", `${metrics.responseTimeP50.toFixed(2)} ms`],
19
+ ["P95", `${metrics.responseTimeP95.toFixed(2)} ms`],
20
+ ["P99", `${metrics.responseTimeP99.toFixed(2)} ms`],
21
+ ];
22
+ console.log((0, table_1.table)(responseTimes) + "\n");
23
+ // Throughput & Requests
24
+ console.log(chalk_1.default.bold.yellow("⚡ Throughput & Requests"));
25
+ const throughputData = [
26
+ ["Metric", "Value"],
27
+ ["Throughput", `${metrics.throughput.toFixed(2)} req/s`],
28
+ ["Total Requests", metrics.totalRequests.toString()],
29
+ [
30
+ "Successful Requests",
31
+ chalk_1.default.green(metrics.successfulRequests.toString()),
32
+ ],
33
+ [
34
+ "Failed Requests",
35
+ metrics.failedRequests > 0
36
+ ? chalk_1.default.red(metrics.failedRequests.toString())
37
+ : metrics.failedRequests.toString(),
38
+ ],
39
+ ];
40
+ console.log((0, table_1.table)(throughputData) + "\n");
41
+ // Error Rate
42
+ console.log(chalk_1.default.bold.yellow("❌ Error Analysis"));
43
+ const errorRateColor = metrics.errorRate < 1
44
+ ? chalk_1.default.green
45
+ : metrics.errorRate < 5
46
+ ? chalk_1.default.yellow
47
+ : chalk_1.default.red;
48
+ const errorData = [
49
+ ["Metric", "Value"],
50
+ ["Error Rate", errorRateColor(`${metrics.errorRate.toFixed(2)} %`)],
51
+ ];
52
+ console.log((0, table_1.table)(errorData) + "\n");
53
+ // Error Breakdown
54
+ if (metrics.errors.size > 0) {
55
+ console.log(chalk_1.default.bold.yellow("🔍 Error Breakdown"));
56
+ const errorBreakdown = [["Error Type", "Count"]];
57
+ metrics.errors.forEach((count, error) => {
58
+ errorBreakdown.push([error, count.toString()]);
59
+ });
60
+ console.log((0, table_1.table)(errorBreakdown) + "\n");
61
+ }
62
+ // Status
63
+ const status = metrics.errorRate < 5
64
+ ? chalk_1.default.green.bold("✓ PASS")
65
+ : chalk_1.default.red.bold("✗ FAIL");
66
+ console.log(chalk_1.default.bold(`Overall Status: ${status}`));
67
+ console.log(chalk_1.default.gray("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n"));
68
+ }
69
+ }
70
+ exports.CLIReporter = CLIReporter;
71
+ //# sourceMappingURL=cli-reporter.js.map