Skip to content

feat: Conver .http load tests to k6.io .js test files #26

Merged
deicon merged 2 commits intodevelopfrom
feat/k6io-converter
Oct 28, 2025
Merged

feat: Conver .http load tests to k6.io .js test files #26
deicon merged 2 commits intodevelopfrom
feat/k6io-converter

Conversation

@deicon
Copy link
Owner

@deicon deicon commented Oct 26, 2025

Description:
This PR introduces a new feature: the ability to convert .http files into Grafana k6 scripts. This enables users to leverage existing .http files for load testing with k6.

Motivation:
Many developers already use .http files to define and test their APIs. Providing a conversion tool allows them to easily reuse these files for load testing with k6, reducing the effort required to set up performance tests.

What was changed:

  • Added a new command-line flag -convert to main.go to trigger the conversion process.
  • Created a new converter/k6 package with a Generate function that takes parsed .http requests and generates a k6 script.
  • The Generate function handles placeholders, environment variables (from .env files), and request details to create a valid k6 script.
  • Added a requireK6Generate helper function to isolate the k6 conversion logic and avoid unnecessary imports when not used.
  • Added new files:
    • cmd/httprunner/convert_k6.go: Contains the requireK6Generate helper function.
    • converter/k6/generator.go: Contains the core logic for converting .http requests to k6 scripts.
    • converter/k6/generator_test.go: Contains unit tests for the k6 script generator.
    • docs/specs/k6-coverter.md: Contains documentation on the k6 converter.
    • examples/k6/loadtest.http: Example .http file to be converted to K6 format.

Tests:
New unit tests have been added in converter/k6/generator_test.go to verify the correct generation of k6 scripts, including placeholder handling, environment variable usage, and basic script structure.

@deicon deicon requested a review from Copilot October 26, 2025 14:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds functionality to convert .http files into Grafana k6 load testing scripts, enabling developers to reuse existing HTTP request definitions for performance testing.

Key changes:

  • Added a -convert k6 command-line flag to trigger conversion to k6 format
  • Implemented a converter that preserves placeholders (converting {{.VAR}} to ${vars.VAR}), handles environment variables from .env files, and generates valid k6 JavaScript with proper options for iterations and delays
  • Included comprehensive documentation and test coverage for the conversion feature

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cmd/httprunner/main.go Added -convert flag and conversion mode logic to handle k6 conversion requests
cmd/httprunner/convert_k6.go Created helper function to isolate k6 converter imports
converter/k6/generator.go Core conversion logic transforming HTTP requests to k6 JavaScript scripts
converter/k6/generator_test.go Unit tests verifying placeholder conversion, environment variable handling, and script generation
docs/specs/k6-coverter.md Documentation explaining conversion feature with examples
examples/k6/loadtest.http Example HTTP file demonstrating conversion capabilities

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,84 @@
# Conversion
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'coverter' to 'converter' in filename.

Copilot uses AI. Check for mistakes.
b.WriteString(fmt.Sprintf(" sleep(%g);\n", float64(delay)/1000.0))
}

_ = respVar
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable respVar is assigned but never used. This appears to be dead code that should either be removed or utilized if it was intended for future functionality.

Copilot uses AI. Check for mistakes.
@deicon deicon force-pushed the feat/k6io-converter branch from 54dd8e0 to b90a750 Compare October 26, 2025 14:59
@deicon deicon force-pushed the feat/k6io-converter branch from b90a750 to d3e5f5e Compare October 28, 2025 06:40
@deicon deicon merged commit 7066c1c into develop Oct 28, 2025
12 checks passed
@deicon deicon deleted the feat/k6io-converter branch October 28, 2025 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant