postmanlabs / newman

Newman is a command-line collection runner for Postman
https://www.postman.com
Apache License 2.0
6.83k stars 1.16k forks source link

Feature Request: Enable references to external JavaScript files as an alternative to embedding arrays of JavaScript containing strings #3141

Open nilvon9wo opened 1 year ago

nilvon9wo commented 1 year ago

This isn't so much an issue with Newman as not finding Postman to be an ideal JavaScript editor, yet finding it worse to edit .json collection files in something else.

In an idea solution, when Newman files a string instead of an array as the value of exec, Newman would check if this is a file path and whether a file can be found at this location. If so, it would run it.

So, for example, instead of:

                    "script": {
                        "exec": [
                            "let response = pm.response.json();\r",
                            "pm.globals.set(\"jwt_for_workday_to_airtable\", response.access_token);\r",
                            "pm.test(\"Status code is 200\", function () {\r",
                            "    pm.response.to.have.status(200);\r",
                            "});"
                        ],
                        "type": "text/javascript"
                    }

I could have

                    "script": {
                        "exec": "./capture_access_token.js",
                        "type": "text/javascript"
                    }
nilvon9wo commented 1 year ago

I thought about trying to make a PR to do something like this, but I won't pretend my JavaScript is good enough to figure out how your solution is working, so I can't modify it.

Instead, since this isn't getting any response, I'm working on a wrapper ( https://github.com/nilvon9wo/impendingman ) which will allow users to do translate a collection.template.json and run it in newman.

Ideally, I'd like to make newman a direct dependency instead of going through the shell, but I couldn't figure out how to turn command line arguments into NewmanOptions, or if that is even necessary or the best way to do this....

If anyone here is interested in helping with this solution, I'm all eyeballs.

nilvon9wo commented 1 year ago

In case anyone is interested in actually using this tool, it is now on npm: https://www.npmjs.com/package/impendingman?activeTab=readme

... Alas, I still haven't figured out how to integrate newman directly instead of going through the shell....