UNPKG

k6-node

Version:

CLI tool that enables k6 installation via npm packages

95 lines (94 loc) 3.6 kB
import { Step } from '../types/request-types'; import { Scenario } from '../types/scenario-types'; import { Options } from '../types/test-types'; /** * Builder class for creating and executing k6 load tests * This class generates k6 JavaScript code and executes it using the k6 binary */ export declare class K6TestBuilder { private config; private imports; /** * Add imports to the k6 test script * In k6, imports bring in modules like http, websockets, or custom metrics * * @param imports - Array of import statements for k6 modules * @returns This builder instance for method chaining */ addImports(...imports: string[]): this; /** * Set global options for the k6 test * These options configure test-wide settings like VUs, duration, and thresholds * * @param options - k6 options object defining test execution parameters * @returns This builder instance for method chaining */ setOptions(options: Options): this; /** * Add a scenario to the k6 test * Scenarios in k6 allow different execution patterns and workload models * * @param scenario - Scenario configuration with steps and executor * @returns This builder instance for method chaining */ addScenario(scenario: Scenario): this; /** * Create a simple scenario with steps for k6 execution * * @param name - Unique name for the scenario * @param steps - Array of steps to execute in k6 * @param executor - k6 executor type defining how VUs execute iterations * @returns This builder instance for method chaining */ createScenario(name: string, steps: Step[], executor?: string): this; /** * Set raw JavaScript code for k6 setup function * In k6, setup runs once at test start and can return data to the main function * * @param setupCode - JavaScript code string for k6 setup function * @returns This builder instance for method chaining */ setRawSetupCode(setupCode: string): this; /** * Set raw JavaScript code for k6 teardown function * In k6, teardown runs once at test end for cleanup operations * * @param teardownCode - JavaScript code string for k6 teardown function * @returns This builder instance for method chaining */ setRawTeardownCode(teardownCode: string): this; /** * Generate the complete k6 test script as JavaScript code * This creates executable k6 code with imports, options, and scenario functions * * @returns Complete k6 test script as a string */ generateScript(): string; /** * Generate k6 JavaScript code for a single scenario * This creates the actual HTTP requests and checks that k6 will execute * * @param scenario - Scenario configuration to generate code for * @returns JavaScript code string for the scenario */ private generateScenarioCode; /** * Execute the k6 test using the k6 binary * This method generates the script, runs it with k6, and handles cleanup * * @param options - Execution options for k6 including output and environment * @returns Promise that resolves when k6 execution completes */ run(options?: { output?: string; quiet?: boolean; verbose?: boolean; environment?: Record<string, string>; }): Promise<void>; /** * Save the generated k6 script to a file for later use * * @param filePath - Path where to save the k6 script file */ saveScript(filePath: string): void; }