Docs IDE Autocomplete (@mockarty/types)

IDE Autocomplete (@mockarty/types)

The Mockarty script types give your editor completion for function names,
parameter hints and inline documentation. Use them in VS Code, WebStorm,
IntelliJ IDEA, Neovim with LSP, or another editor that supports TypeScript.

What you get

  • k6 declarations for imports such as k6, k6/http, k6/ws,
    k6/grpc, k6/data, k6/encoding, k6/crypto, k6/metrics,
    k6/html, k6/execution and k6/timers. Use the standard import
    path for the modules supported by Mockarty when running a load test.

  • Mockarty extensions — additional modules under mockarty/*:

    Module What it provides
    mockarty/http HTTP requests (get/post/…/batch), JSON helpers
    mockarty/grpc gRPC client (unary calls)
    mockarty/soap SOAP request helpers
    mockarty/ws WebSocket client
    mockarty/sse Server-Sent Events client
    mockarty/kafka Kafka producer / consumer
    mockarty/rabbitmq RabbitMQ publish / consume
    mockarty/sql SQL query helpers
    mockarty/redis Redis client
    mockarty/mcp MCP client (connect, listTools, callTool)
    mockarty/data Shared data (SharedArray)
    mockarty/faker Synthetic data generators
    mockarty/encoding base64 / hex encoding
    mockarty/crypto Hashing / HMAC
    mockarty/html HTML parsing / selectors
    mockarty/core check(), sleep(), group()
    mockarty/execution VU / scenario execution context
    mockarty/timers setTimeout / setInterval
    mockarty/metrics Counter, Trend, Rate, Gauge
    mockarty/allure Allure annotations (step, feature, severity)
    mockarty/smtp SMTP email client (send)
    mockarty/dto Mockarty DTO interfaces (Mock, stores)
  • Global helpers — the top-level allure binding is injected
    automatically; standard k6 globals (__VU, __ITER) are also typed.

Installation

Online

npm i --save-dev @mockarty/types
// tsconfig.json
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ESNext",
    "moduleResolution": "node",
    "strict": true,
    "types": ["@mockarty/types"]
  },
  "include": ["scripts/**/*.ts"]
}

mockarty-cli init scaffolds a project skeleton (mockarty.yaml + sample
tests). Add the @mockarty/types dev-dependency and tsconfig.json above to
get autocomplete in that project.

Air-gapped

Get the mockarty-types-*.tgz and types-k6-*.tgz archives for your release.
Copy both into your offline project to enable mockarty/* and k6/* imports in your editor.

npm install --offline --save-dev ./mockarty-types-*.tgz ./types-k6-*.tgz

API Tester request and test scripts

Download the declarations for mk and pm
and include them in the project that contains your functional scripts.
If the project also has load-test dependencies, set compilerOptions.types to
[] in the functional configuration and include the downloaded file explicitly.

If your release provides @mockarty/types 0.2.0 or later, you can use
its functional entry point in the script project’s tsconfig.json or
jsconfig.json in place of the standalone declarations.

{
  "compilerOptions": {
    "types": ["@mockarty/types/functional"]
  }
}

You can write an API Tester test like this.

mk.test("Status is 200", () => {
  mk.expect(mk.response.code).to.equal(200);
});

For TypeScript tooling that needs a named data type, use a type-only import.

import type { MockartySharedProject } from "@mockarty/types/functional";

Keep the functional and load scripts in separate project configurations so
each editor sees its own runtime globals. Mockarty supplies mk and pm
when it runs a functional script.

In Settings → Agent Skills, autocomplete in the custom tool editor inserts
calls such as mk.rabbitmq.publish({url, queue, message}) and
mk.kafka.consume({brokers, topic, groupId, maxMessages, timeout}). Define
the variables you use in the call. The receive timeout is in milliseconds.

Editor setup

VS Code

Just open the project folder. VS Code reads tsconfig.json
automatically; autocomplete starts working immediately. Press
Ctrl+Space to see suggestions, F12 to jump to a type definition.

WebStorm / IntelliJ IDEA

Open the folder containing the scripts and their tsconfig.json or
jsconfig.json. Install the package in that project or include the
downloaded declarations in its configuration. With the TypeScript
language service enabled, press Ctrl+Space to check suggestions for
mk. in a functional script.

Neovim / Helix / Vim

Install typescript-language-server:

npm i -g typescript typescript-language-server

The LSP uses the type entry point selected in your project’s
tsconfig.json or jsconfig.json.

A first script

import * as http from "k6/http";
import { check, sleep } from "k6";
import * as faker from "mockarty/faker";
import * as Allure from "mockarty/allure";

export const options = {
  scenarios: {
    smoke: { executor: "constant-vus", vus: 5, duration: "30s" },
  },
  thresholds: {
    http_req_duration: ["p(95)<500"],
    http_req_failed: ["rate<0.01"],
  },
};

export default function (): void {
  Allure.feature("signup");

  const res = http.post("https://api.example.com/signup", {
    email: faker.email(),
    name: faker.name(),
  });

  check(res, {
    "status is 201": (r) => r.status === 201,
    "is json": (r) => (r.headers["Content-Type"] || "").includes("json"),
  });

  sleep(1);
}

Save as scripts/signup.ts, then run:

mockarty-cli perf run scripts/signup.ts

The CLI transpiles TypeScript to JavaScript on the fly (relative imports
are bundled too); you don’t have to run tsc yourself.

The script’s own export const options drives the run: vus,
duration, iterations, rps, maxVUs, stages, thresholds, and
scenarios are all applied. Every scenario executor is supported
(constant-vus, ramping-vus, per-vu-iterations, shared-iterations,
constant-arrival-rate, ramping-arrival-rate), including several
scenarios at once — they run in parallel, each with its own exec
function, env overlay and startTime offset, and the report merges
their metrics with exact combined percentiles plus a per-scenario
breakdown. With a flat profile explicit CLI flags win; with multiple
scenarios the scenario profiles apply as-is. An exported
handleSummary(data) function is called after the run; every key of the
returned object is written as a file (the keys stdout / stderr print
to the terminal instead). A breached threshold makes the CLI exit with
code 99 (CI-friendly — fail the pipeline on a slow build). Add
--reporter allure to get an allure-results/ directory with
per-iteration results, attachments, the run container and
executor.json.

Updating the types

@mockarty/types tracks the scripting surface of the Mockarty release you
run. Bump it whenever you upgrade the Mockarty CLI:

npm update @mockarty/types

Your package.json should pin a compatible range
("@mockarty/types": "^0.2.0") so minor releases pull in new helpers
automatically. Major versions are bumped only on breaking type changes.

Troubleshooting

  • Autocomplete shows k6 functions but not Mockarty extras. Check
    that @mockarty/types is in tsconfig.json’s compilerOptions.types
    array. Also make sure your editor’s TypeScript version is 5.0+
    (older versions silently ignore the types field for ambient
    modules).
  • Property 'status_text' does not exist on type 'Response'. Your
    @mockarty/types is older than the engine that emitted the response —
    update the package (npm update @mockarty/types).
  • Cannot find module 'mockarty/faker'. TypeScript needs to load
    @mockarty/types for the ambient modules to resolve. Either add it
    to compilerOptions.types or import "@mockarty/types" once at the
    top of any of your .ts files.

License

@mockarty/types is published under the MIT license (same as
@types/k6 that it builds on). The Mockarty product itself is
distributed under the Mockarty Software License Agreement.