# @apideck/postman-to-k6 中文文档

规范地址：https://npmcn.com/package/%40apideck/postman-to-k6/

版本：1\.14\.4
npm 元数据更新时间：2026-10-12T21:17:35.726Z
中文译文更新时间：2026-11-06T10:15:34.165Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40apideck/postman-to-k6
原文对照：https://npmcn.com/package/%40apideck/postman-to-k6/?lang=original
项目主页：https://github.com/apideck-libraries/postman-to-k6#readme
源码仓库：https://github.com/apideck-libraries/postman-to-k6

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：1.5 MB，69 个文件
- 模块格式：CommonJS
- TypeScript 类型：未声明
- Node.js 要求：\>=22\.12\.0
- 运行依赖：20 个
- 首次发布：2021-08-17T09:13:23.760Z
- 最新版本发布：2026-10-12T21:17:35.528Z
- 近 30 天下载量：3756（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：26（近 12 个月 5 个）

## 中文简介

将 Postman 收藏转换为 k6 JavaScript

## 安装

```sh
npm install @apideck/postman-to-k6
```

也可以使用：`pnpm add @apideck/postman-to-k6`、`yarn add @apideck/postman-to-k6`、`bun add @apideck/postman-to-k6`

## README

![postman-to-k6-cover](https://npmcn.com/package/%40apideck/postman-to-k6/assets/postman-to-k6-cover.png)

# 邮递员对k6

转换 a [邮递员收藏](https://www.getpostman.com/docs/collections) 改为 [k6 脚本](https://docs.k6.io/docs)。 。 。 .

人到克6的转换器利用你的邮递员收藏,并转换所有邮递员请求,包括测试, 变量,... 到 K6 可执行的 K6 脚本进行性能测试.

![Github badge](https://github.com/apideck-libraries/postman-to-k6/actions/workflows/build-on-tag.yml/badge.svg) [![npm](https://img.shields.io/npm/v/@apideck/postman-to-k6.svg)](https://www.npmjs.com/package/@apideck/postman-to-k6) [![npm](https://img.shields.io/npm/dw/@apideck/postman-to-k6.svg)](https://www.npmjs.com/package/@apideck/postman-to-k6)

这个项目是原作的友好分叉 [grafana/邮递员对k6](https://github.com/grafana/postman-to-k6) 转换器,积极维护并开放新捐款.

随意贡献或通过任何改进后人对k6的建议.

## 内容

-   [特征](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-features)
-   [安装](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-installation)
    -   [局部安装(建议)](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-local-installation-recommended)
    -   [全球安装](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-global-installation)
-   [使用量](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-usage)
-   [视频介绍](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-video-introduction)
-   [选项](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-options)
    -   [迭代数](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-iterations)
    -   [环境变量](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-environment-variables)
    -   [全球变量](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-global-variables)
    -   [CSV 数据文件](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-csv-data-file)
    -   [JSON 数据文件](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-json-data-file)
    -   [K6 参数选项文件](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-k6-param-options-file)
    -   [K6 作为 JSON 处理摘要](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-k6-handle-summary-as-json)
    -   [K6 请求标签](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-k6-request-tag)
    -   [分开](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-separate)
    -   [跳过预览](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-skip-pre)
    -   [跳过邮件](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-skip-post)
    -   [CLI 选项文件](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-cli-options-file)
-   [实例](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-examples)
-   [测试](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-testing)
-   [不支持的特性](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-unsupported-features)
-   [其他类似工具](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-other-similar-tools)
-   [贷项](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-credits)

## 特征

-   [x] 前所请文.
-   [x] 测试脚本.
-   [x] 变量(在所有范围+动态).
-   [x] 数据文件.
-   [x] 认证方法(霍克除外).
-   [x] 文件上传(实验).
-   [x] `postman.*` 接口( e)[以下例外情况](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-unsupported-features)) (中文(简体) ).
-   [x] `pm.*` 接口( e)[以下例外情况](https://npmcn.com/package/%40apideck/postman-to-k6/#readme-unsupported-features)) (中文(简体) ).
-   [x] 支助 邮差 [动态变量](https://learning.postman.com/docs/writing-scripts/script-references/variables-list/) 打开 [替换](https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#using-variables-in-scripts) 函数.
-   [x] Postman 曝光的全球变量 : `globals` `environment` `data` `iteration`。 。 。 .
-   [x] `xml2Json` 转换.
-   [x] 全体 [邮政员Schema](https://schema.getpostman.com/) 各个版本.

## 安装

### 局部安装(建议)

虽然有可能在全球安装,但我们建议,如果可能的话,将转换器添加到 `node_modules` 您的电话 使用 :

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

或者用纱线...

```shell
$ yarn add @apideck/postman-to-k6
```

请注意,这将需要您用 `npx @apideck/postman-to-k6 your-postman-file` 或者 如果你是的话 使用旧版本 npm, `./node_modules/.bin/postman-to-k6 your-postman-file`。 。 。 .

### 全球安装

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

## 使用量

要将导出收藏转换为 k6 脚本 :

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

然后像往常一样使用 k6 运行脚本 :

```shell
$ k6 run k6-script.js
```

## 视频介绍

与 [尼科尔·范德霍芬](https://twitter.com/n_vanderhoeven) 打开 [保罗·巴洛格](https://twitter.com/javaducky) 从 [K6队](https://www.youtube.com/@k6io)我们谈过了[人对克6](https://github.com/apideck-libraries/postman-to-k6)" 在 [K6 办公小时](http://www.youtube.com/watch?v=Be66Db4wHLA) 播客们 我们讨论了如何将邮递员的集合转换为k6载荷测试,邮递员的优点,以及重新使用自动化测试脚本进行性能测试的好处.

[![Postman for load testing using k6, with Tim Haselaars (k6 Office Hours #43)](https://raw.githubusercontent.com/apideck-libraries/postman-to-k6/main/assets/youtube-still.png)](https://www.youtube.com/watch?v=Be66Db4wHLA "Postman for load testing using k6, with Tim Haselaars (k6 Office Hours #43)")

在Youtube上看着点 [https://www.youtube.com/watch?v=Be66Db4wHLA (中文(简体) )](https://www.youtube.com/watch?v=Be66Db4wHLA)

所涉专题:

-   将大小写用于 [k6 时](https://k6.io/)
-   快速巡视 [邮差](https://www.postman.com/)
-   为什么邮递员不是为装入测试设计的
-   解职 [人对克6](https://github.com/apideck-libraries/postman-to-k6)
-   如何使用 [波特曼语Name](https://blog.apideck.com/announcing-portman) 从 OpenAPI 光谱生成测试

## 选项

### 迭代数

配置完成前要执行多少次脚本 .

| 旗帜 | 声波 | 默认 |
| --- | --- | --- |
| `-i` | `--iterations` | 1个 |

示例

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

### 环境变量

从 JSON 文件提供环境变量 .

| 旗帜 | 声波 | 默认 |
| --- | --- | --- |
| `-e` | `--environment` | 不详 |

示例

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

### 全球变量

从 JSON 文件提供全局变量 .

| 旗帜 | 声波 | 默认 |
| --- | --- | --- |
| `-g` | `--global` | 不详 |

```shell
$ postman-to-k6 collection.json --global globals.json -o k6-script.js
```

### CSV 数据文件

以 CSV 格式提供数据文件.

| 旗帜 | 声波 | 默认 |
| --- | --- | --- |
| `-c` | `--csv` | 不详 |

```shell
$ postman-to-k6 collection.json --csv data.csv -o k6-script.js
```

### JSON 数据文件

用 JSON 格式通过数据文件 .

| 旗帜 | 声波 | 默认 |
| --- | --- | --- |
| `-j` | `--json` | 不详 |

```shell
$ postman-to-k6 collection.json --json data.json -o k6-script.js
```

### K6 参数选项文件

过 [K6 参数选项](https://k6.io/docs/javascript-api/k6-http/params) 作为JSON格式的文件.

| 旗帜 | 声波 | 默认 |
| --- | --- | --- |
|  | `--k6-params` | 不详 |

```shell
$ postman-to-k6 collection.json --k6-params k6-params.json -o k6-script.js
```

### K6 作为 JSON 处理摘要

输出 [K6摘要](https://k6.io/docs/results-visualization/end-of-test-summary/#handlesummary-callback) 作为文件 jSON格式。 这将会增加 K6 `handleSummary(data)` 到生成的脚本,提供 K6 的功能 将在本地存储摘要输出为 JSON 文件.

| 旗帜 | 声波 | 默认 |
| --- | --- | --- |
|  | `--k6-handle-summary-json` | 不详 |

```shell
$ postman-to-k6 collection.json --k6-handle-summary-json summary-report.json -o k6-script.js
```

### K6 请求标签

生成 [K6 请求名称标签](https://k6.io/docs/using-k6/http-requests/#http-request-tags) 基于可用的命名 战略:

-   无:没有自动生成的标签qq默认
-   `request`: 使用请求名称作为标签(例如“ 显示全部账户” )
-   `folder-request`: 使用 Postman 文件夹名和请求名( 例如:“ 账户 - 显示全部账户 ”)

| 旗帜 | 声波 | 默认 |
| --- | --- | --- |
|  | `--k6-request-tagging` | 不详 |

示例 `request` 战略

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

示例 `folder-request` 战略

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

### 分开

将请求拆分为单独的文件, 以便更容易重排逻辑 .

| 旗帜 | 声波 | 默认 |
| --- | --- | --- |
| `-s` | `--separate` | 虚假 |

```shell
$ postman-to-k6 collection.json --separate -o k6-script.js
```

```shell
$ postman-to-k6 collection.json -s -o k6-script.js
```

### 跳过预览

转换时跳过任何预请求脚本

| 旗帜 | 声波 | 默认 |
| --- | --- | --- |
|  | `--skip-pre` | 虚假 |

```shell
$ postman-to-k6 collection.json --skip-pre -o k6-script.js
```

### 跳过邮件

转换时跳过任何后请求脚本

| 旗帜 | 声波 | 默认 |
| --- | --- | --- |
|  | `--skip-post` | 虚假 |

```shell
$ postman-to-k6 collection.json --skip-pre -o k6-script.js
```

### CLI 选项文件

在单独的配置文件中管理所有 CLI 选项, 并将其传递给 postman to- k6 命令 。 来做 比较容易使用CLI,特别是在CI/CD执行中.

所有可用的 CLI 选项都可以在配置文件中使用. 通过通过CLI选项作为参数,可以 覆盖文件中定义的 CLI 选项.

| 旗帜 | 声波 | 默认 |
| --- | --- | --- |
|  | `--cli-options-file` | 虚假 |

```shell
$ postman-to-k6 collection.json --cli-options-file cli-config.json
```

JSON CLI 配置文件示例

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

## 实例

邮递员实例汇编见以下 `example`。要运行其中的一个例子, 只需运行它,因为你会 其他命令 :

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

## 测试

运行测试套件 :

```shell
$ npm run test-jest
```

`npm run test-jest` 包括一名土生土长的警卫 `tests/**` (AVA型API失败或 `mock-require`) (中文(简体) ).

运行默认测试入口 :

```shell
$ npm run test-all
```

运行覆盖并生成一个综合摘要/趋势文物:

```shell
$ npm run coverage-all
```

`npm run coverage-jest-regression` 执行一个 Jest 覆盖回归门对 `scripts/coverage/jest-coverage-baseline.json` 最大滴数 `0.30%` 用于行/报表/功能/空白.

最佳本地测试规则 `tests/**`数字 :

-   使用本地 Jest 断言( E)`expect(...)`仅此而已.
-   不导入 AVA (`import test from 'ava'`(单位:千美元) `tests/**`。 。 。 .
-   不使用 AVA 特定 API(`test.serial`, (中文(简体) ), `t.is`, (中文(简体) ), `t.deepEqual`, (中文(简体) ), `t.throws`(见a/c.5/49/70,附件).
-   不使用 `mock-require` 内 `tests/**`;使用共享的 Jest shim 绑入 `tests/helpers/shimHarness.js`。 。 。 .

警卫司令部是:

```shell
$ npm run test-jest-native-guard
```

## 不支持的特性

-   使用脚本发送请求 `pm.sendRequest`。 。 。 .
-   使用控制请求执行命令 [`postman.setNextRequest`](https://github.com/apideck-libraries/postman-to-k6/discussions/135#discussioncomment-10229573)。 。 。 .
-   Cookie 属性, 比如 `hostOnly`, (中文(简体) ), `session`,以及 `storeId`。 。 。 .
-   邮递员的方法:
    -   `pm.response.reason`
    -   `pm.response.to.have.status(reason)`
    -   `pm.response.to.not.have.status(reason)`
    -   `pm.request.auth`
-   鹰认证方法.
-   折旧 `xmlToJson` 方法.
-   申请身份证明更改。 邮递员在出口中不提供它们,所以我们必须产生出新的.

## 资源

关于邮递至k6的博客文章和资源集

-   [k6 办公时间# 43](https://www.youtube.com/watch?v=Be66Db4wHLA) 播音员: [格拉法纳/K6](https://k6.io/) & Tim Haselaars (维护者) [人对克6](https://github.com/apideck-libraries/postman-to-k6)(中文(简体) )
-   [用 Postman 装入测试您的 API](https://grafana.com/blog/2020/04/19/load-testing-your-api-with-postman/) 以 [摩斯塔法莫拉迪亚语Name](https://grafana.com/author/mostafa-moradian/) 从 [格拉法纳](https://grafana.com/)
-   [解锁 Spec-Driven API 开发的力量](https://www.youtube.com/watch?v=YXRstde1SeA&t) 以 [蒂姆·哈斯拉尔斯](https://github.com/thim81)
-   [API 负载测试: 初学者指南](https://grafana.com/blog/2024/01/30/api-load-testing/) 以 [格拉法纳/K6](https://k6.io/)
-   [充电您的APIs 第 6 卷 : 完善您的APIOps - 利用 k6 的力量进行API测试](https://www.codecentric.de/wissens-hub/blog/charge-your-apis-volume-6-perfecting-your-apiops-harnessing-the-power-of-k6-for-api-testing) 以 [丹尼尔·科科特](https://www.linkedin.com/in/danielkocot/) 从 [代码中心](https://www.codecentric.de/)
-   [装入 Postman 和 Grafana K6 测试](https://medium.com/kpmg-uk-engineering/load-testing-with-postman-and-grafana-k6-48afb4872a6b) 以 [卢克曼·帕特尔](https://medium.com/@patel.s.lukman?source=post_page-----48afb4872a6b--------------------------------)
-   [通过将 Postman API 脚本转换为 K6 并整合到比特巴克特 来移动左侧性能测试](https://icehousecorp.com/shift-left-performance-test-by-converting-postman-api-script-to-k6-and-integrate-it-with-bitbucket/) 由苏克玛·拉吉尔(sukma ragil)
-   [黑客新闻](https://news.ycombinator.com/item?id=36540241)
-   [Transformando 测试 de API com Postman em 测试 de performance com K6](https://dev.to/marlo2222/transformando-testes-de-api-com-postman-em-testes-de-performance-com-k6-3ked) 以 [玛洛·恩里克](https://dev.to/marlo2222)
-   [将 Postman 收藏转换为 K6 脚本](https://blog.nashtechglobal.com/converting-postman-collection-to-k6-script/)
-   [使用带有 k6 的邮递员](https://medium.com/@rianaik/using-postman-with-k6-6cb4c5852990) 以 [里亚·奈克](https://medium.com/@rianaik)
-   [Postman 到 K6 用自动脚本生成自动化性能测试](https://www.youtube.com/watch?v=e0QdBoWS72k) 以 [胡扎伊法·阿西夫](https://www.youtube.com/@huzaifa-io)
-   [邮递员5分钟后到K6](https://medium.com/@t79877005/postman-to-k6-in-under-5-minutes-fb98fabaf468) 编号 : [YouTube (英语)](https://www.youtube.com/watch?v=ddP4HcFfXRw) 以 [索德雷亚贷款](https://www.linkedin.com/in/%F0%9F%95%B5ioan-s-b0928516/)

## 其他类似工具

-   [公尺对克6](https://github.com/loadimpact/jmeter-to-k6/): 将 JMeter JMX 文件转换为 k6 JS.

## 贷项

特别感谢来自 [格拉法纳](https://github.com/grafana) 用于开源和增殖 转换器和贡献给社区。 感谢 [书月](https://github.com/bookmoons) 用于创建此 工具。 还有,多亏了 [波尔贾坎皮纳](https://github.com/borjacampina) 用于创建工具的原始化身.

## 常见问题

### @apideck/postman-to-k6 是什么？

将 Postman 收藏转换为 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 和提交记录判断。

