diff --git a/CHANGELOG.md b/CHANGELOG.md index d3860a5..0fd6283 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased](https://github.com/apideck-libraries/postman-to-k6/compare/v1.8.7...HEAD) + +- Implement Atob via K6 encoding (#86) - Extended pm.request with support for headers, url, method, name, id, body, body.raw ## [1.12.0] - 2024-07-31 diff --git a/lib/common/feature.js b/lib/common/feature.js index a9cf107..31f26b3 100644 --- a/lib/common/feature.js +++ b/lib/common/feature.js @@ -67,6 +67,15 @@ function detectFeature(logic, result) { result.polyfills.add('spo-gpo'); result.effectImports.add(xml2JsonPath); } + + if (/\batob\b/.test(logic)) { + let atobPath = './libs/shim/atob.js'; + if (result?.setting?.separate === true) { + const pathDepth = renderDirectoryPathGroup(result.group); + atobPath = `${pathDepth}libs/shim/atob.js`; + } + result.effectImports.add(atobPath); + } } function renderDirectoryPathGroup(group) { diff --git a/lib/shim/atob.js b/lib/shim/atob.js new file mode 100644 index 0000000..5bf9faa --- /dev/null +++ b/lib/shim/atob.js @@ -0,0 +1,6 @@ +import { b64decode } from 'k6/encoding'; +function atob(str) { + return b64decode(str, 'std', 's'); +} + +global.atob = atob;