How benc-uk/k6-reporter works
Main Components
• K6 Test Integration – This is where the test code calls out to the htmlReport function via the handleSummary callback. Show how the user’s K6 script imports the module from dist/bundle.js.
• HTML Report Generator Module – Represent the module’s core logic found in the “src” folder (e.g., html-report.js and template.ejs) that processes the summary data and uses a templating engine (EJS) to generate HTML output.
• Bundler & Build Process – Include a component for the Webpack build process (webpack.config.js, package.json) that converts the source code from “src” into the bundled file in “dist”.
• Testing and Validation – Mark the “tests” folder that contains test cases and protocol files (e.g., hello.proto, grpc.js, simple.js, etc.), which ensure proper functionality.
• Legacy Code Component – Although not active in the current module version, note that there is an “archive” folder with the previous Golang implementation. This can be shown as a deprecated or alternate path for historical context.
Component Relationships and Data Flow
• Data Flow: Start with the K6 test execution where summary data is produced during/after the test run. This data is passed into the handleSummary callback, which then sends the JSON summary data into the htmlReport function.
• Output: The final HTML content is written to the filesystem (as specified via the key in the returned object of handleSummary).
• Optional Multi-output Handling: Represent how the design also accommodates combining HTML report output with other summary formats (like textSummary) for extended usage.
Architectural Patterns & Design Principles
• Modular Design: Emphasize the separation between the report generator logic (conversion and templating) and the bundling/distribution mechanism.
• Template Engine Pattern: Highlight the use of EJS (or similar templating) to dynamically create HTML reports from JSON data.
• Extensibility: The design allows users to extend functionality by combining multiple output generators, as illustrated in the README’s “Multiple outputs” section.
• Legacy Code Segregation: Note that the older Golang implementation is archived and isolated from the current JavaScript-based solution.
Technologies Involved
• JavaScript ES6 modules, Node.js (for running the build/test processes), and NPM (package.json and package-lock.json).
• Webpack for bundling.
• ESLint for code quality (see .eslintrc.json).
• EJS for templating.
• K6 for load testing integration.