{"_id":"@cronn/k6-scenario-builder","name":"@cronn/k6-scenario-builder","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@cronn/k6-scenario-builder","version":"1.0.0","description":"Create k6 scenarios using a builder","keywords":["k6"],"bugs":{"url":"https://github.com/cronn/k6-scenario-builder/issues"},"author":{"name":"cronn"},"license":"Apache-2.0","repository":{"type":"git","url":"git+https://github.com/cronn/k6-scenario-builder.git"},"homepage":"https://github.com/cronn/k6-scenario-builder","engines":{"node":">=22","pnpm":">=10"},"type":"module","exports":{"./package.json":"./package.json",".":{"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"},"default":{"types":"./dist/index.d.ts","default":"./dist/index.js"}}},"types":"./dist/index.d.ts","devDependencies":{"@biomejs/biome":"1.9.4","@changesets/cli":"2.29.4","@cronn/vitest-file-snapshots":"0.4.0","@types/k6":"1.0.2","@types/node":"22.15.23","@vitest/coverage-istanbul":"3.1.4","@vitest/expect":"3.1.4","tsup":"8.4.0","typescript":"5.8.3","vitest":"3.1.4"},"scripts":{"check":"biome check .","check:fix":"biome check --write .","test":"vitest run","test:coverage":"vitest run --coverage","compile":"tsc","build":"tsup src/index.ts","ci":"biome ci . && pnpm run compile & pnpm run test:coverage","version":"pnpm changeset version && pnpm biome format --write package.json","release":"pnpm run build && pnpm changeset publish"},"_id":"@cronn/k6-scenario-builder@1.0.0","_integrity":"sha512-LxEoOpNQwpanfplnyGtYRGuH9r4A0YecTkURUvbDYNcAb2g9ER2OQfjGNdpWE27uObrXUpATSYhljgTQ/TCRsA==","_resolved":"/tmp/3385495b4087d85e9df11112cf21dc8f/cronn-k6-scenario-builder-1.0.0.tgz","_from":"file:cronn-k6-scenario-builder-1.0.0.tgz","_nodeVersion":"22.15.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-LxEoOpNQwpanfplnyGtYRGuH9r4A0YecTkURUvbDYNcAb2g9ER2OQfjGNdpWE27uObrXUpATSYhljgTQ/TCRsA==","shasum":"f773624e957111a1ba1f12a4bfde180b5977ddda","tarball":"https://registry.npmjs.org/@cronn/k6-scenario-builder/-/k6-scenario-builder-1.0.0.tgz","fileCount":7,"unpackedSize":41122,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDQQ2Xr45JboA/6kyETUdigRHHjisxGZlH6aH+6kpt+jQIhAI9DexQWaugE2PNuo+K+wibG+ISqfsZtllgWbxyw1WYO"}]},"_npmUser":{"name":"cronn","email":"network-admins@cronn.de"},"directories":{},"maintainers":[{"name":"cronn","email":"network-admins@cronn.de"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/k6-scenario-builder_1.0.0_1748436046236_0.1856790570171507"},"_hasShrinkwrap":false}},"time":{"created":"2025-05-28T12:40:46.154Z","1.0.0":"2025-05-28T12:40:46.414Z","modified":"2025-05-28T12:40:46.675Z"},"maintainers":[{"name":"cronn","email":"network-admins@cronn.de"}],"description":"Create k6 scenarios using a builder","homepage":"https://github.com/cronn/k6-scenario-builder","keywords":["k6"],"repository":{"type":"git","url":"git+https://github.com/cronn/k6-scenario-builder.git"},"author":{"name":"cronn"},"bugs":{"url":"https://github.com/cronn/k6-scenario-builder/issues"},"license":"Apache-2.0","readme":"# k6 Scenario Builder\n\nThis library provides a builder for k6 scenario configurations. How scenarios in k6 are defined is explained in their [documentation](https://grafana.com/docs/k6/latest/using-k6/scenarios/).\n\n## Motivation\n\nIf your k6 setup grows bigger, and you want to run multiple scenarios the scenario configuration can become very long and tedious.\nIn particular, making changes to adjust scenarios for test runs is tedious and can easily lead to errors in the configuration, costing time.\nThis library tries to make the configuration and customisation of k6 scenarios easier and less error-prone.\n\n## Currently supported executor types\n\nIn the current version are scenario builders for three k6 executor types implemented.\n- constant-vus\n- ramping-vus\n- constant-arrival-rate\nIf other executor types are desired we will integrate them or gladly accept pull requests.\n\n## Getting Started\n\n### Adding the library to your project\n\n```shell\nnpm install -D @cronn/k6-scenario-builder\n```\n\n```shell\nyarn add -D @cronn/k6-scenario-builder\n```\n\n```shell\npnpm add -D @cronn/k6-scenario-builder\n```\n\n### Create a scenario configuration\n\nFor creating a new set of scenarios, consisting of one or more scenarios create a new instance of the `ScenarioSetBuilder` class. Individual scenarios can be added with `addScenario`, `addShortScenario` or `addDefaultScenario` to the current scenario list. A full set of scenarios can be added using `defaultScenarioSet` or `shortDefaultScenarioSet`.\n\nTo create a single scenario which can be passed to `addScenario` use the builder for your desired executor type. These builders can be accessed by the `ScenarioBuilderProvider`. Currently, only the `ConstantVUsScenario`, `RampingVUsScenario` and `ConstantArrivalRateScenario` are implemented!\n\nTo create a scenario with one of these builders you need to describe your scenario as a `ScenarioExecutable`, which currently only contains a reference to the function which shall be executed by the scenario and a toggle whether a browser is necessary or not (optional, default is `false`).\n\nExample:\n\n```typescript\nexport function myScenarioFunction() {\n  console.log(\"My fancy scenario\");\n}\n\nconst scenarioExecutable: ScenarioExecutable = {\n  exec: myScenarioFunction,\n  browser: false,\n};\n\nnew ScenarioSetBuilder()\n  .addScenario(\n    ScenarioBuilderProvider.constantScenario(scenarioExecutable)\n      .withVus(5)\n      .withDuration(\"2m\")\n      .buildScenario(),\n  )\n  .buildScenarioSet();\n```\n\nThis builder call creates a 2-minute scenario which executes `myScenarioFunction` with constant 5 VUs.\nTo make this scenario executable for k6, you need to export the `myScenarioFunction` function from the file which is run by k6.\n\nIf you have multiple scenarios you want to execute, an approach is to create a list of `ScenarioExecutable`s from which you can choose your desired scenario when calling a ScenarioBuilder.\n\n### Browser based scenarios\n\nIf your `ScenarioExecutable` contains `browser: true` the ScenarioBuilder will add\n\n```json\n{ \"browser\": { \"type\": \"chromium\" } }\n```\n\nas an option to your scenario and k6 will use a browser when executing.\n\n### Callback\n\nThe `ScenarioSetBuilder` provides `withCallback` which allows you to set a function which is executed every time a scenario is added.\nThe function gets passed a reference to the new scenario object, so you can do some final adjustments if necessary and you can keep the state of your test framework in sync with the created scenarios.\nWhen calling `withCallback` multiple times for one ScenarioSetBuilder object the callback function will be overridden and the latest function will be used.\n\n### Default scenarios\n\nEach ScenarioBuilder has a default configuration for mandatory values which will be used if `buildScenario` is called without configuring the scenario.\nThese default values can be modified by using `setDefaultScenario` for the desired builder. Be aware that when adding stages to the default scenario \nfor the `RampingVUsScenarioBuilder` they will be used in the customized scenarios as well. `withStage` will only add stages but not override the default ones.\nThus, recommended is to use `setDefaultStages` to modify default stages and keep the stages in the default scenario an empty list. \nAdditionally `ScenarioSetBuilder` has functions for default sets which accept `ScenarioExecutables` to be run with default values.\n","readmeFilename":"README.md","_rev":"1-d0a6042948f687cfe913e070a9b50c04"}