# Full JavaScript lifecycle: setup() fetches an auth token once, every
# iteration runs an exported function, beforeRequest/afterRequest hooks fire
# around YAML requests, teardown() cleans up.
name: javascript-lifecycle
description: setup/teardown, scenario exec functions and hooks

defaults:
  http:
    base_url: https://api.example.com

js:
  file: scripts/helpers.js
  timeout: 5s          # per-call wall clock limit
  memory_limit_mb: 64  # per-VU JS heap

scenarios:
  scripted:
    executor: constant-vus
    vus: 5
    duration: 2m
    exec: scriptedIteration       # exported from helpers.js
  mixed:
    executor: constant-vus
    vus: 2
    duration: 2m
    flow:
      - request:
          name: listing
          url: /items
          # ${js: ...} runs in the VU's JS runtime during interpolation
          params:
            page: "${js: Math.ceil(Math.random() * 10)}"
      - js: "session.trendAdd('page_render_budget', 16.6)"

metrics:
  page_render_budget: { kind: trend, time: true }

thresholds:
  checks: [ "rate>0.98" ]
