How go-automate/k6-typescript-framework works
Project Type and Purpose
• This is a performance testing framework using k6, focused on simulating user actions (such as creating a user, querying crocodiles, and performing CRUD operations on crocodiles).
• Its structure is modular, separating testing actions, role definitions, helper utilities, and test scripts. It also integrates monitoring with Grafana and InfluxDB through a docker-compose setup.
Main Components (Nodes)
a. Test Runner Environment:
• k6 Load Testing Tool: Represents the core engine running your TypeScript scripts.
• Docker Environment: When running tests with docker (via docker-compose), k6 runs inside a container with results output to InfluxDB.
b. Core Modules within the Source Code:
• Actions Module:
• Contains user actions (e.g., crocodile-management, session-management, user-management).
• Further segmented into roles (public-user, crocodile-owner, admin), defining what each type of user can do.
• Library Module:
• Helpers and Types: Contains helper functions (like request helpers, sleep helpers) and type definitions (interface contracts for API interactions).
• Tests Module:
• Contains performance tests (e.g., the soak.test.ts) and seed scripts (create-crocs.seed.ts) that orchestrate load test scenarios.
c. Build and Configuration:
• Build Tools: Babel (.babelrc) and Webpack (webpack.config.js) for transpiling and bundling the code.
• Type Checking: tsconfig.json for TypeScript configuration and type safety.
• Dependency Management: package.json holds project dependencies and script commands.
d. Monitoring and CI/CD Integration:
• Grafana: Visualizes performance metrics, with a pre-configured dashboard (Grafana datasources and dashboards, as described in grafana-datasource.yaml and README instructions).
• Docker-compose: Coordinates the runtime environment for tests and monitoring tools.
Relationships and Data Flow
• The test scripts (in tests) invoke user actions defined in the actions modules. These actions simulate interactions (e.g., API requests) using helpers from the lib directory.
• The build process transforms TypeScript sources (src folder) using Babel and Webpack, ensuring that the test scripts run correctly in the target environment.
• When executed, k6 uses the defined test scenarios to load test the API. Test results either output directly to the console (local execution) or are sent to InfluxDB (when run inside Docker), which Grafana then visualizes.
• Docker-compose ties together the services (k6 container, InfluxDB, Grafana) for a cohesive monitoring setup.
Architectural Patterns
• Modular Design: Clear separation of responsibilities (actions, helpers, tests) for maintainability and scalability.
• Layered Architecture: Test scripts (presentation) rely on action modules (business logic simulation) which in turn rely on helper functions (utility and type safety).
• Containerization: Use of Docker-compose encapsulates the monitoring and test execution environments.