Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

k6-html-reporter

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

k6-html-reporter - npm Package Compare versions

Comparing version 1.0.0-beta to 1.0.0

dist/index.d.ts

126

dist/reporter.js

@@ -23,6 +23,7 @@ "use strict";

function writeHtmlReport(content, filePath) {
const time = new Date().toLocaleString();
const templatePath = path_1.default.resolve(__dirname, '../templates/template.ejs');
const checkRootGroupData = content["root_group"];
const metricsData = content["metrics"];
const { checkMetric, countMetrics, timeMetrics, vusMetrics, allThresholds, metricThresholdsPassed, failedThresholdsNum } = mapMetrics(metricsData);
const { checkMetric, countMetrics, timeMetrics, vusMetrics, allThresholds, metricThresholdsPassed, totalThresholdResult } = mapMetrics(metricsData);
const checks = getChecks(checkRootGroupData).map((data) => {

@@ -36,3 +37,3 @@ const splitedPath = data.path.split('::');

});
ejs_1.default.renderFile(templatePath, { checks, checkMetric, countMetrics, timeMetrics, vusMetrics, allThresholds, metricThresholdsPassed, failedThresholdsNum }, {}, function (err, str) {
ejs_1.default.renderFile(templatePath, { checks, checkMetric, countMetrics, timeMetrics, vusMetrics, allThresholds, metricThresholdsPassed, totalThresholdResult, time }, {}, function (err, str) {
if (err) {

@@ -42,7 +43,4 @@ console.error(err);

let html = ejs_1.default.render(str);
fs_1.default.writeFile(`${filePath}/report.html`, html, function (err) {
if (err)
throw err;
console.log(`Report is created at ${filePath}`);
});
fs_1.default.writeFileSync(`${filePath}/report.html`, html);
console.log(`Report is created at ${filePath}`);
});

@@ -57,16 +55,23 @@ }

let metricThresholdsPassed = true;
let failedThresholdsNum = 0;
let totalThresholdResult = {
passes: 0,
fails: 0,
failedMetricsNum: 0
};
Object.entries(data).forEach(([key, value]) => {
if (Object.keys(value).includes('count')) {
const thresholdFailed = thresholdResult(value.thresholds);
if (thresholdFailed === true) {
failedThresholdsNum++;
metricThresholdsPassed = false;
}
countMetrics.push({
name: key,
...value,
thresholdFailed
});
if (Object.keys(value).includes('thresholds')) {
const metric = {
name: key,
...value,
thresholdFailed: undefined
};
if (metric.type === 'counter') {
if (value.thresholds) {
const [passes, fails] = thresholdResult(value.thresholds);
if (fails > 0) {
totalThresholdResult.failedMetricsNum++;
metricThresholdsPassed = false;
}
totalThresholdResult.passes += passes;
totalThresholdResult.fails += fails;
metric.thresholdFailed = fails > 0;
allThresholds.push({

@@ -77,15 +82,14 @@ name: key,

}
countMetrics.push(metric);
}
else if (Object.keys(value).includes('avg')) {
const thresholdFailed = thresholdResult(value.thresholds);
if (thresholdFailed === true) {
failedThresholdsNum++;
metricThresholdsPassed = false;
}
timeMetrics.push({
name: key,
...value,
thresholdFailed
});
if (Object.keys(value).includes('thresholds')) {
else if (metric.type === 'trend') {
if (value.thresholds) {
const [passes, fails] = thresholdResult(value.thresholds);
if (fails > 0) {
totalThresholdResult.failedMetricsNum++;
metricThresholdsPassed = false;
}
totalThresholdResult.passes += passes;
totalThresholdResult.fails += fails;
metric.thresholdFailed = fails > 0;
allThresholds.push({

@@ -96,14 +100,13 @@ name: key,

}
timeMetrics.push(metric);
}
else if (Object.keys(value).includes('passes')) {
const thresholdFailed = thresholdResult(value.thresholds);
if (thresholdFailed === true) {
failedThresholdsNum++;
}
checkMetric = {
name: key,
...value,
thresholdFailed
};
if (Object.keys(value).includes('thresholds')) {
else if (metric.name === 'checks') {
if (value.thresholds) {
const [passes, fails] = thresholdResult(value.thresholds);
if (fails > 0) {
totalThresholdResult.failedMetricsNum++;
}
totalThresholdResult.passes += passes;
totalThresholdResult.fails += fails;
metric.thresholdFailed = fails > 0;
allThresholds.push({

@@ -114,15 +117,14 @@ name: key,

}
checkMetric = metric;
}
else if (key.includes('vus')) {
const thresholdFailed = thresholdResult(value.thresholds);
if (thresholdFailed === true) {
failedThresholdsNum++;
metricThresholdsPassed = false;
}
vusMetrics.push({
name: key,
...value,
thresholdFailed
});
if (Object.keys(value).includes('thresholds')) {
else if (metric.type === 'gauge') {
if (value.thresholds) {
const [passes, fails] = thresholdResult(value.thresholds);
if (fails > 0) {
totalThresholdResult.failedMetricsNum++;
metricThresholdsPassed = false;
}
totalThresholdResult.passes += passes;
totalThresholdResult.fails += fails;
metric.thresholdFailed = fails > 0;
allThresholds.push({

@@ -133,19 +135,23 @@ name: key,

}
vusMetrics.push(metric);
}
});
return { checkMetric, countMetrics, timeMetrics, vusMetrics, allThresholds, metricThresholdsPassed, failedThresholdsNum };
return { checkMetric, countMetrics, timeMetrics, vusMetrics, allThresholds, metricThresholdsPassed, totalThresholdResult };
}
function thresholdResult(thresholds) {
if (thresholds) {
return Object.values(thresholds).some(value => value === true);
const thresholdArr = Object.values(thresholds);
const passes = thresholdArr.filter(value => value.ok === true).length;
const fails = thresholdArr.length - passes;
return [passes, fails];
}
}
function getChecks(data) {
const checksOutput = [];
let checksOutput = [];
findChecksRecursively(data);
function findChecksRecursively(data) {
if (data.groups.length === 0) {
if (data.groups.length === 0 && data.checks.length === 0) {
return;
}
if (Object.keys(data.checks).length > 0) {
if (data.checks.length > 0) {
Object.values(data.checks).forEach((value) => {

@@ -152,0 +158,0 @@ checksOutput.push(value);

@@ -0,1 +1,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map
{
"name": "k6-html-reporter",
"version": "1.0.0-beta",
"version": "1.0.0",
"description": "A html reporter for k6",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"dependencies": {

@@ -26,3 +27,4 @@ "ejs": "^3.1.5"

"report",
"k6"
"k6",
"html"
],

@@ -29,0 +31,0 @@ "author": "",

# k6-html-reporter
A html reporter for k6
## Install
NPM:
``` bash
npm install k6-html-reporter --save-dev
```
YARN:
```bash
yarn add k6-html-reporter --dev
```
## Usage
1. Install the package
2. Create a js/ts file and specify the options:
```js
const reporter = require('k6-html-reporter');
const options = {
jsonFile: <path-to-json-report>,
output: <path-to-output-directory>,
};
reporter.generateSummaryReport(options);
```
for typescript
```ts
import {generateSummaryReport} from 'k6-html-reporter';
const options = {
jsonFile: <path-to-json-report>,
output: <path-to-output-directory>,
};
generateSummaryReport(options);
```
3. Output a JSON summary output with the `handleSummary` function provided by k6, [more info](https://k6.io/docs/results-visualization/end-of-test-summary).
```js
export default function () { /** some tests here */}
export function handleSummary(data) {
console.log('Preparing the end-of-test summary...');
return {
<path-to-json-report>: JSON.stringify(data),
}
}
```
> **Note**: The ` --summary-export=path/to/file.json` run option is no longer recomanded after k6 v0.30.0.
4. Run the code in step two as a node.js script after the test execution:
```bash
node xxxx.js
```
### Sample report:
![Alt text](./screenshot/k6.png?raw=true "Optional Title")

@@ -8,5 +8,6 @@ {

"sourceMap": true,
"outDir": "dist"
"outDir": "dist",
"declaration": true
},
"lib": ["es2015"]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc