@apideck/postman-to-k6
Advanced tools
Comparing version
@@ -8,4 +8,15 @@ # Changelog | ||
## [Unreleased](https://github.com/apideck-libraries/postman-to-k6/compare/v1.8.5...HEAD) | ||
## [Unreleased](https://github.com/apideck-libraries/postman-to-k6/compare/v1.8.7...HEAD) | ||
## [1.8.7] - 2023-01-14 | ||
### Added | ||
- Support for Postman files upload (experimental)(#93, #28, #83) | ||
- Build postman-to-k6 as a Docker image | ||
### Security | ||
- Bump json5 from 2.1.3 to 2.2.3 | ||
## [1.8.6] - 2022-11-12 | ||
@@ -12,0 +23,0 @@ |
const aid = require('../../aid'); | ||
const Auth = require('../../auth'); | ||
const dataForm = require('./form'); | ||
const URI = require('urijs'); | ||
@@ -8,2 +7,3 @@ const { InheritAuth } = require('../../sym'); | ||
const { BodyItemType, BodyMode } = require('../../enum'); | ||
const { formDataForm, formDataFile } = require('./form'); | ||
@@ -86,3 +86,3 @@ function analyze(request, result, block) { | ||
case BodyMode.formdata: | ||
dataForm(body, feature, result); | ||
formDataForm(body, feature, result); | ||
return; | ||
@@ -95,2 +95,5 @@ case BodyMode.urlencoded: | ||
return; | ||
case BodyMode.file: | ||
formDataFile(body, feature, result); | ||
return; | ||
default: | ||
@@ -97,0 +100,0 @@ throw new Error(`Unrecognized body mode: ${mode}`); |
@@ -13,6 +13,15 @@ const aid = require('../../aid'); | ||
function dataFile(body, feature, result) { | ||
const data = {}; | ||
const item = body.file; | ||
item.type = 'file'; | ||
convertItem(item, data, result); | ||
feature.data = data; | ||
} | ||
function convertItem(item, data, result) { | ||
if (!item.key) { | ||
throw new Error('Form item missing key'); | ||
} | ||
// if (!item.key) { | ||
// throw new Error('Form item missing key'); | ||
// } | ||
switch (item.type) { | ||
@@ -40,3 +49,4 @@ case 'text': | ||
result.imports.set('http', 'k6/http'); | ||
const { key } = item; | ||
// const { key } = item; | ||
const key = 'file'; | ||
const path = extractPath(item); | ||
@@ -60,2 +70,7 @@ result.files.add(path); | ||
module.exports = dataForm; | ||
// Module export for multiple functions | ||
module.exports = { | ||
formDataForm: dataForm, | ||
formDataFile: dataFile | ||
}; |
@@ -7,2 +7,3 @@ const aid = require('../../aid'); | ||
const { Auth } = require('./sym'); | ||
const { basename } = require('path'); | ||
@@ -62,2 +63,3 @@ function render(mapped, result) { | ||
imports: result.imports, | ||
files: result.files, | ||
effectImports: result.effectImports, | ||
@@ -74,2 +76,3 @@ declares: block.declares, | ||
declares(result), | ||
files(result), | ||
result.logic | ||
@@ -88,2 +91,23 @@ ].filter(item => item).join('\n\n'); | ||
function files(result) { | ||
if (result.files.size) { | ||
const items = []; | ||
for (const path of result.files) { | ||
items.push(fileLoad(path)); | ||
} | ||
return `const files = {}; | ||
${items.join('\n')}`; | ||
} else { | ||
return null; | ||
} | ||
} | ||
function fileLoad(path) { | ||
const name = basename(path); | ||
return `files[${JSON.stringify(path)}] = http.file( | ||
open(${JSON.stringify(path)}, "b"), | ||
${JSON.stringify(name)} | ||
);`; | ||
} | ||
module.exports = render; |
{ | ||
"name": "@apideck/postman-to-k6", | ||
"version": "1.8.6", | ||
"version": "1.8.7", | ||
"description": "Convert a Postman collection to k6 JavaScript", | ||
@@ -69,3 +69,2 @@ "keywords": [ | ||
"postman-collection-transformer": "^4.1.3", | ||
"prettier": "^1.19.1", | ||
"spo-gpo": "^1.0.0", | ||
@@ -87,3 +86,5 @@ "strip-json-comments": "^3.1.1", | ||
"mock-require": "^3.0.3", | ||
"np": "^7.6.2", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^1.19.1", | ||
"sinon": "^7.5.0", | ||
@@ -90,0 +91,0 @@ "snazzy": "^8.0.0", |
@@ -28,2 +28,3 @@ <div align="center"> | ||
- [Usage](#usage) | ||
- [Video introduction](#video-introduction) | ||
- [Options](#options) | ||
@@ -54,3 +55,3 @@ - [Iterations](#iterations) | ||
- [x] Authentication methods (except Hawk). | ||
- [x] File uploads. | ||
- [x] File uploads (experimental). | ||
- [x] `postman.*` interface ([exceptions below](#unsupported-features)). | ||
@@ -107,2 +108,18 @@ - [x] `pm.*` interface ([exceptions below](#unsupported-features)). | ||
## Video Introduction | ||
Together with [Nicole van der Hoeven](https://twitter.com/n_vanderhoeven) & [Paul Balogh](https://twitter.com/javaducky) from the [K6 team](https://www.youtube.com/@k6io), we talked about "[postman-to-k6](https://github.com/apideck-libraries/postman-to-k6)" in the [K6 Office Hours](http://www.youtube.com/watch?v=Be66Db4wHLA) 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. | ||
<a href="https://www.youtube.com/watch?v=Be66Db4wHLA" target="_blank" title="Postman for load testing using k6, with Tim Haselaars (k6 Office Hours #43)" rel="nofollow"> | ||
<img src="https://camo.githubusercontent.com/fe8d65ea79fcdb60c7e541d75259871d9846f96348feda261093ea2b20fa4299/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f4265363644623477484c412f6d617872657364656661756c742e6a7067" alt="Postman for load testing using k6, with Tim Haselaars (k6 Office Hours #43)" width="50%"></a> | ||
Watch it on Youtube >> https://www.youtube.com/watch?v=Be66Db4wHLA | ||
Topics covered: | ||
* Use cases for [k6](https://k6.io/) | ||
* Quick tour of [Postman](https://www.postman.com/) | ||
* Why Postman is not designed for load testing | ||
* Demo of [postman-to-k6](https://github.com/apideck-libraries/postman-to-k6) | ||
* How to use [Portman](https://blog.apideck.com/announcing-portman) to generate tests from an OpenAPI spec | ||
## Options | ||
@@ -109,0 +126,0 @@ |
1466206
0.18%22
-4.35%9732
0.38%342
5.23%14
16.67%- Removed
- Removed