@apideck/postman-to-k6

中文文档
1.14.4发布于 2026/10/13Apache-2.0CommonJS近 30 天下载 3756

Convert a Postman collection to k6 JavaScript

原始使用文档
文档目录26 节
  1. Content
  2. Features
  3. Installation
  4. Local Installation (recommended)
  5. Global Installation
  6. Usage
  7. Video Introduction
  8. Options
  9. Iterations
  10. Environment Variables
  11. Global Variables
  12. CSV Data File
  13. JSON Data File
  14. K6 Param Options File
  15. K6 Handle Summary as JSON
  16. K6 Request tag
  17. Separate
  18. Skip Pre
  19. Skip Post
  20. CLI options file
  21. Examples
  22. Testing
  23. Unsupported Features
  24. Resources
  25. Other similar tools
  26. Credits

postman-to-k6-cover

Postman-to-k6

Converts a Postman collection to a k6 script.

The postman-to-k6 converter utilizes your Postman collection and converts all the Postman requests, including tests, variables, ... to K6 scripts that can be executed by K6 to run performance tests.

Github badge npm npm

This project is a friendly fork of the original grafana/postman-to-k6 converter, actively maintained and open for new contributions.

Feel free to contribute or pass any suggestion to improve postman-to-k6.

Content

Features

  • Pre-request scripts.
  • Test scripts.
  • Variables (at all scopes + dynamic).
  • Data files.
  • Authentication methods (except Hawk).
  • File uploads (experimental).
  • postman.* interface (exceptions below).
  • pm.* interface (exceptions below).
  • Support for Postman Dynamic Variables & ReplaceIn function.
  • Global variables exposed by Postman: globals environment data iteration.
  • xml2Json conversion.
  • All Postman Schema versions.

Installation

While possible to install globally, we recommend that you, if possible, add the converter to the node_modules of your test project using:

$ npm install -D @apideck/postman-to-k6

or using yarn...

$ yarn add @apideck/postman-to-k6

Note that this will require you to run the converter with npx @apideck/postman-to-k6 your-postman-file or, if you are using an older versions of npm, ./node_modules/.bin/postman-to-k6 your-postman-file.

Global Installation

$ npm install -g @apideck/postman-to-k6

Usage

To convert an exported collection to a k6 script:

$ postman-to-k6 collection.json -o k6-script.js

Then run the script in k6, as usual, using:

$ k6 run k6-script.js

Video Introduction

Together with Nicole van der Hoeven & Paul Balogh from the K6 team, we talked about "postman-to-k6" in the K6 Office Hours podcast. We talked about how to convert a Postman collection to a k6 load test, the advantages of Postman, and the benefits of reusing automation testing scripts for performance.

Postman for load testing using k6, with Tim Haselaars (k6 Office Hours #43)

Watch it on Youtube >> https://www.youtube.com/watch?v=Be66Db4wHLA

Topics covered:

  • Use cases for k6
  • Quick tour of Postman
  • Why Postman is not designed for load testing
  • Demo of postman-to-k6
  • How to use Portman to generate tests from an OpenAPI spec

Options

Iterations

Configures how many times the script will be executed before completion.

FlagVerboseDefault
-i--iterations1

Example:

$ postman-to-k6 collection.json --iterations 25 -o k6-script.js

Environment Variables

Provide environment variables from a JSON file.

FlagVerboseDefault
-e--environmentN/A

Example:

$ postman-to-k6 collection.json --environment environment.json -o k6-script.js

Global Variables

Provide global variables from a JSON file.

FlagVerboseDefault
-g--globalN/A
$ postman-to-k6 collection.json --global globals.json -o k6-script.js

CSV Data File

Provide a data file in the CSV format.

FlagVerboseDefault
-c--csvN/A
$ postman-to-k6 collection.json --csv data.csv -o k6-script.js

JSON Data File

Pass in a data file in the JSON format.

FlagVerboseDefault
-j--jsonN/A
$ postman-to-k6 collection.json --json data.json -o k6-script.js

K6 Param Options File

Pass K6 parameter options as a file in JSON format.

FlagVerboseDefault
--k6-paramsN/A
$ postman-to-k6 collection.json --k6-params k6-params.json -o k6-script.js

K6 Handle Summary as JSON

Output the K6 summary as a file in JSON format. This will add the K6 handleSummary(data) to the generated script, providing the functionality that K6 will store the summary output as JSON file locally.

FlagVerboseDefault
--k6-handle-summary-jsonN/A
$ postman-to-k6 collection.json --k6-handle-summary-json summary-report.json -o k6-script.js

K6 Request tag

Generate K6 request name tags based on available naming strategies:

  • none: no automatic generated tags | default
  • request: uses the request name as tag (example "Show all accounts")
  • folder-request: uses Postman folder name and the request name (example: "Accounts - Show all accounts")
FlagVerboseDefault
--k6-request-taggingN/A

Example for request strategy

$ postman-to-k6 collection.json --k6-request-tagging=request -o k6-script.js

Example for folder-request strategy

$ postman-to-k6 collection.json --k6-request-tagging=folder-request -o k6-script.js

Separate

Split requests into separate files, for easier rearrangement of the logic.

FlagVerboseDefault
-s--separatefalse
$ postman-to-k6 collection.json --separate -o k6-script.js
$ postman-to-k6 collection.json -s -o k6-script.js

Skip Pre

Skips any pre-request scripts during conversion

FlagVerboseDefault
--skip-prefalse
$ postman-to-k6 collection.json --skip-pre -o k6-script.js

Skip Post

Skips any post-request scripts during conversion

FlagVerboseDefault
--skip-postfalse
$ postman-to-k6 collection.json --skip-pre -o k6-script.js

CLI options file

Manage all the CLI options in a separate configuration file and pass them along to the postman-to-k6 command. To make the CLI usage easier, especially in CI/CD implementations.

All the available CLI options can be used in the config file. By passing the CLI options as parameters, you can overwrite the defined CLI options defined in the file.

FlagVerboseDefault
--cli-options-filefalse
$ postman-to-k6 collection.json --cli-options-file cli-config.json

Example of JSON CLI config file

{
    "output": "k6-script.js",
    "k6-params": "config/k6-params.json",
    "environment": "config/envs/team.env.json",
    "separate": true
}

Examples

A collection of Postman examples are located under example. To run one of the examples, just run it as you would any other command:

$ postman-to-k6 example/v2/echo.json -o k6-script.js

Testing

Run the test suite:

$ npm run test-jest

npm run test-jest includes a native-Jest guard for tests/** (fails on AVA-style APIs or mock-require).

Run the default test entrypoint:

$ npm run test-all

Run coverage and generate a combined summary/trend artifact:

$ npm run coverage-all

npm run coverage-jest-regression enforces a Jest coverage regression gate against scripts/coverage/jest-coverage-baseline.json with a max drop of 0.30% for lines/statements/functions/branches.

Jest-native testing rules for tests/**:

  • Use native Jest assertions (expect(...)) only.
  • Do not import AVA (import test from 'ava') in tests/**.
  • Do not use AVA-specific APIs (test.serial, t.is, t.deepEqual, t.throws, etc.).
  • Do not use mock-require in tests/**; use the shared Jest shim harness in tests/helpers/shimHarness.js.

The guard command is:

$ npm run test-jest-native-guard

Unsupported Features

  • Sending requests from scripts using pm.sendRequest.
  • Controlling request execution order using postman.setNextRequest.
  • Cookie properties, like hostOnly, session, and storeId.
  • Postman methods:
    • pm.response.reason
    • pm.response.to.have.status(reason)
    • pm.response.to.not.have.status(reason)
    • pm.request.auth
  • The Hawk authentication method.
  • Deprecated xmlToJson method.
  • Request IDs are changed. Postman doesn't provide them in the export, so we have to generate new ones.

Resources

A collection of blog posts and resources about postman-to-k6

Other similar tools

Credits

Special thanks to the K6 team from Grafana for open-sourcing & growing the converter and contributing it to the community. Thanks to bookmoons for creating this tool. Also, thanks to borjacampina for creating the original incarnation of the tool.

版本与发布记录

@apideck/postman-to-k6 共发布 26 个版本,首次发布于 2021/08/17;过去 12 个月发布了 5 个版本。

版本发布日期距今
1.14.4latest2026/10/1325 天前
1.14.32026/10/1326 天前
1.14.22026/05/235 个月前
1.14.12026/03/157 个月前
1.14.02026/03/147 个月前
1.13.02024/08/192 年前

关于 @apideck/postman-to-k6 的常见问题

@apideck/postman-to-k6 是什么?

Convert a Postman collection to k6 JavaScript

如何安装 @apideck/postman-to-k6?

在项目目录运行 npm install @apideck/postman-to-k6,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 postman-to-k6,可以用 npx postman-to-k6 直接运行。

@apideck/postman-to-k6 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/apideck__postman-to-k6 是否存在。

@apideck/postman-to-k6 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@apideck/postman-to-k6 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.12.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@apideck/postman-to-k6 可以商用吗?

@apideck/postman-to-k6 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@apideck/postman-to-k6 的下载量有多少?

根据 npm 官方下载统计,@apideck/postman-to-k6 在 2026/10/06 – 2026/11/04 这 30 天内被下载 3,756 次,日均约 125 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@apideck/postman-to-k6 还在维护吗?

最新版本 1.14.4 发布于 2026/10/13(25 天前);至今共发布 26 个版本,其中过去 12 个月发布了 5 个;首次发布于 2021/08/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。