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-auto

v1.0.0

Published

a CLI to auto generate postman collection to test script

Downloads

66

Readme

Postman Auto

a CLI to auto generate postman tests from json response

Noted

Before use this app, you need to have knowledge about postman test Postman Test Script

Also have litle knowlage about unittest

Setup Postman Collection

This app use postman response to create auto test. So you need to include postman response into postman collections. Postman Response

See Postman Example.postman_collection.json

Getting started

Install

Open the terminal, then

$ npm install -g postman-auto

Usage

cd to postman colections, then

$ pm-auto sample-collection.json

Test Result

By default, this app will create directory structure

pm-auto-output
  |- postman
  |- javascript
  |- python

cd to output directory and read README.md

Postman Test

Javascript Test

Python Test

Testing Test Result

For example--test postman result

$ cd pm-auto-output/postman && npm install && npm run test

or

$ cd pm-auto-output/postman && yarn install && yarn test

or

$ cd pm-auto-output/postman && npm install

Command Line Options

postman-auto [options]

  • --help Show command line help

  • --version Displays the current version

postman-auto <postman-collection> [options]

  • --skipType <source> This skip create test. Default ["Null"], Example skip Null and Array, --skipType Null,Array

  • --skipKeys <source> This skip create test spesific json key, default null Example: skip data.name, --skipType data.name

  • --output <source> Default will create 3 outputs, postman collection, javascript with mocha & chai and pyton with unittest.

How it works?

Simple, its just read the postman response then create script test, example

Postman response


{
    "args": {},
    "data": {
        "name": "indaam",
        "hobbies": [
            {
                "id": 0,
                "name": "anything"
            }
        ],
        "arr": [
            0,
            "1"
        ],
        "_boolean": true
    },
    "files": {},
}

Script test result


var jsonData = pm.response.json();

pm.test(
  "Should response must be object and have keys 'args','data','files','form','headers','json','url' ",
  function () {
    pm.expect(jsonData).to.have.property("args");
    pm.expect(jsonData).to.have.property("data");
    pm.expect(jsonData).to.have.property("files");
  }
);

pm.test("Should args must be object ", function () {
  pm.expect(jsonData.args).to.be.an("object");
});

pm.test("Should data.name to be String", function () {
  pm.expect(jsonData.data.name).to.be.a("string");
});

pm.test("Should data.hobbies to be Array", function () {
  pm.expect(jsonData.data.hobbies).to.be.a("array");
});

pm.test("Should data.hobbies[0].id to be Number", function () {
  pm.expect(jsonData.data.hobbies[0].id).to.be.a("number");
});

pm.test("Should data.hobbies[0].name to be String", function () {
  pm.expect(jsonData.data.hobbies[0].name).to.be.a("string");
});

pm.test("Should data.arr to be Array", function () {
  pm.expect(jsonData.data.arr).to.be.a("array");
});

pm.test("Should data.arr[0] to be Number", function () {
  pm.expect(jsonData.data.arr[0]).to.be.a("number");
});

Application Flow

  • read postman collection
  • get the sample response
  • convert to object
  • create object keys
  • define test list base on key & type data
  • convert postman item to HAR
  • create http snippet from har
  • write unittest

Limitation

On this first release, just create very simple test--only check type data on json response

  • string
  • number
  • boolean
  • null
  • bject
  • array

But on reality test, sometimes we need to create specific test like is valid date format, valid lat long. It not enough when only check type data.

For example case, when you have response latitude with value -90.679436 is valid or not? by value check is valid. But on reality, where is -90.679436 point? So is better when check max value for latitude.

Use as library

install

$ npm i postman-auto

usage

const pma = require('postman-auto');
const postmanCollections = require('Postman Example.postman_collection.json');

// or
/*
const {
  PostmanTest,
  PostmanSplit,
  NodeJsTest,
  PythonTest,
  Main,
  func,
  utils
} = require('postman-auto');
*/

const options = {
  skipKeys: [],
  skipType: ['Null'],
  mergeTestFile: false,
  mixTestObject: false,
  output: [],
  showLog: true
};

const result = pma(postmanCollections, options);
console.log('result', result);

// Basic Docs

/*
{
  PostmanTest: [class PostmanTest extends BaseTest],
  PostmanSplit: [class PostmanSplit extends BaseTest],
  NodeJsTest: [class NodeJsTest extends BaseTest],
  PythonTest: [class PythonTest extends BaseTest],
  Main: [class Main extends BaseClass] {
    writeFile: [Function: writeFile],
    writeResults: [Function: writeResults],
    createPostmanSplit: [Function: createPostmanSplit],
    createPostmanTest: [AsyncFunction: createPostmanTest],
    createPythonTest: [AsyncFunction: createPythonTest],
    createNodeJsTest: [AsyncFunction: createNodeJsTest]
  },
  func: {
    getLastArray: [Function: getLastArray],
    camelCaseToDash: [Function: camelCaseToDash],
    toCamelCase: [Function: toCamelCase],
    toSnakeCase: [Function: toSnakeCase],
    cleanName: [Function: cleanName],
    removeSpace: [Function: removeSpace],
    replaceString: [Function: replaceString],
    typeOf: [Function: typeOf],
    toJson: [Function: toJson],
    getDeepKeys: [Function: getDeepKeys],
    cleanKey: [Function: cleanKey],
    refSubKey: [Function: refSubKey],
    getObjectKeys: [Function: getObjectKeys],
    validateJsKey: [Function: validateJsKey],
    validatePyKey: [Function: validatePyKey],
    inArray: [Function: inArray],
    isArray: [Function],
    isObject: [Function],
    isString: [Function],
    isBoolean: [Function]
  },
  utils: {
    readFile: [AsyncFunction: readFile],
    writeFile: [Function: writeFile]
  }
}
*/

Becarefull

Its better to use this CLI on staging env

Todos

  • Migrate to typescript
  • Add more options
  • Add more languange
  • Add specific type
  • Complated the docs
  • Complated comment script