Skip to content

Instantly share code, notes, and snippets.

@toopay
Created October 22, 2018 14:22
Show Gist options
  • Save toopay/de0d5f34e31cdf58ae81191aeac0ea20 to your computer and use it in GitHub Desktop.
Save toopay/de0d5f34e31cdf58ae81191aeac0ea20 to your computer and use it in GitHub Desktop.
newman-reporter-curl.js
var CurlReporter;
/**
* Simple reporter that generates a curl statement
*
* @param {Object} newman - A run object with event handler specification methods.
* @param {Function} newman.on - An event setter method that provides hooks for reporting collection run progress.
* @param {Object} reporterOptions - A set of reporter specific run options.
* @param {Object} options - A set of generic collection run options.
* @returns {*}
*/
CurlReporter = function (newman, reporterOptions, options) {
if (options.silent || reporterOptions.silent) {
return;
}
newman.on('start', function (err, o) {
if (err) { return; }
// Can start opening a file here
});
newman.on('beforeRequest', function (err, o) {
if (err || !o.request) { return; }
console.log('curl -X %s %s ', o.request.method, o.request.url.toString());
});
newman.on('done', function () {
// Can closing the file here
});
};
CurlReporter.prototype.dominant = true;
module.exports = CurlReporter;
@renatovieiradesouza
Copy link

How to install this js file with npm?

@Mumeii
Copy link

Mumeii commented Oct 6, 2022

@renatovieiradesouza : Hi

For having to deal with the awkwardness of the way to install a newman-reporter, here is a a small advise about how to do it :

to use a newman reporter called newman-reporter-XXXX you have to :

  • install this reporter globally, I.E. -g option while installing it with npm
  • reference to it on the newman command line with the -r XXXX option

Here are the usual suspects of troubles you could encounter. For example, with the previous example :

  • if the package name is not starting with newman-reporter (for exemple simply XXXX without the required prefix), newman will fail to find the module called newman-reporter-XXXX, as the one installed globally simply be XXXX
  • on the other hand, if you specify the full package name with the -r option, such as -r newman-reporter-XXXX, newman will fail to find the module called newman-reporter-newman-reporter-XXXX ...

Hope this will help someone 😋

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment