npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

postman_loadtest

v1.0.0

Published

Parses Postman collections into an array of options that can be ran through the Load Test module (https://www.npmjs.com/package/loadtest)

Downloads

3

Readme

POSTMAN to Load Tests

Parses Postman collections into an array of options that can be ran through the Load Test module (https://www.npmjs.com/package/loadtest)

Installing

Using npm:

npm install postman-to-load

Using bower:

bower install postman-to-load

Postman To Load API:

Collection Parser Methods:

  • buildHeaderObject
  • buildPostBodyObject
  • buildLoadTestOptions
  • parseCollection
  • path: path to the postman json collection to parse
  • dataObj: object that contains properties whose keys match the postman collection parameters {{}}. Will map the dataObj values to the collections parameters.
  • Main function that leverages the above functions to create headers, post body, load options and map them to an array of objects that represent the options for executing each load test.

Controller Methods:

  • statusCallback
  • resultHandler
  • loadTest
  • loadTestViaIteration
  • parallelLoadExecution

Load Test Options:

Below is an example of how to configure the load test:

  const load = require(esl
  function resultHandler(results) {
    return results;
  }

  function statusCallback(error, result, latency){
    const status = result.statusCode;
    const body = JSON.parse(result.body);
    const statusObj = {
      data: body.data, 
      status, 
      latency,
      duration: result.requestElapsed,
      index: result.requestIndex,
      instance: result.instanceIndex,
    };

    if (error) {
      statusObj.error = error
    }
    
    return statusObj;
  };

  const loadTestOptions = {
    concurrency: 1,
    maxRequests: 20,
    contentType: 'application/json',
    requestsPerSecond: 1,
    maxSeconds: 20,
    quiet: true,
    resultHandler,
    statusCallBack,
  };
  • concurrency: How many clients running in parallel.
  • maxRequests: Maximum number of requests the load test will execute. Once reached test will end.
  • requestsPerSecond: How many requests each client sends per second. IE: if you have a concurrency of 2 and rps of 5 you will send 10 requests sent each second.
  • maxSeconds: Maximum number of seconds the test will run. After this duration requests will cease.
  • resultHandler: callback function that can be used to enhance how the test results are handled. Set this property if you want custom result handling.
  • statusCallBack: callback function that is defined by default, but can be overridden if user sets this property as a custom callback function.

After requiring the module and configuring the load test options we can parse our Postman Json collections:

  const parseCollections = new Index.CollectionParser(null, null, props);
  const jsonPath = path.resolve(__dirname, 'EXHWorkingCollection.postman_collection.json');
  const options = parseCollections.parseCollection(jsonPath, dataObj);

parseCollection:

Function that takes a path to the Postman collection and a js object that maps out the postman parameters that need to be resolved. It will return an array of options in a format that can be used to execute the load tests.

Collection mapping:

  const dataObj = {
    'my-api-key': process.env.MY_KEY_DEV,
    username: 'LoadTestMe',
    password: 'Crashed',
  };

Running a single load test from the option array created from the postman collection

  const postLoad = new Index.Controller(props);
  const result = await load.loadTest(options[1]);

Running the array of options created by the postman collection

  const result = await load.loadTestViaIteration(options);

Running an array of load tests stored as promises concurrently

  const result = await load.parallelLoadExecution(promiseArray);