Giter VIP home page Giter VIP logo

newman-debug's Introduction

newman-debug

A guide on how to debug Postman collection scripts with newman.

Feel free to clone this repository to walk through an example:

git clone https://github.com/kevinswiber/newman-debug.git

Be sure to run npm install in the newman-debug directory before getting started.

Usage

In a Postman pre-request or test script, add a debugger statement to set a breakpoint.

Breakpoint example

pm.test('query params are returned in the response body', () => {
    const subject = {
        foo: 'hello',
        bar: 'world'
    };

    debugger;
    const response = pm.response.json();

    pm.expect(response.args).to.eql(subject);
});

Note: The debugger statement will have no effect during normal operation of Postman, the Postman Collection Runner, and newman. It only fires a breakpoint when executing inside a debug session.

Once a debugger statement is added to the script, save the request, and access the collection how you would with newman today: either by exporting the collection or using the Postman API.

Debugging in Visual Studio Code

The launch.json file provided here (.vscode/launch.json) presents different configurations for launching newman.

Configurations

  • Launch newman (npm test)
    • Runs npm test and attaches the debugger. The test script in this Node.js package executes a locally-installed newman instance.
  • Launch newman (bin)
    • Runs a locally-installed newman and attaches the debugger
  • Launch newman (global)
    • Runs a globally-installed newman instance and attaches the debugger.
  • Launch newman (global, prompt)
    • Runs a globally-installed newman after prompting for the path to the Postman collection JSON file and attaches the debugger.

See Debugging in Visual Studio Code for more information.

Debugging with the Node.js debugging client

To debug directly in your terminal, run:

node inspect ./node_modules/.bin/newman run collection.json --timeout-script 1800000

Example debug session:

$ node inspect ./node_modules/.bin/newman run collection.json --timeout-script 1800000
< Debugger listening on ws://127.0.0.1:9229/e7249c52-c382-42d3-b79e-66f391f3e2c3
< For help, see: https://nodejs.org/en/docs/inspector
< Debugger attached.
Break on start in node_modules/newman/bin/newman.js:3
  1 #!/usr/bin/env node
  2
> 3 require('../lib/node-version-check'); // @note that this should not respect CLI --silent
  4
  5 const _ = require('lodash'),
debug> c
< newman
< newman-debug
< → GET /get
<   GET https://postman-echo.com/get?foo=hello&bar=world
< [200 OK, 755B, 478ms]
<   ✓  response status is 200 OK
break in [unknown]:12
 10         foo: 'hello',
 11         bar: 'world'
>12     };
 13
 14     debugger;
debug> n
break in [unknown]:13
 11         bar: 'world'
 12     };
>13
 14     debugger;
 15     const response = pm.response.json();
debug> n
break in [unknown]:15
 13
 14     debugger;
>15     const response = pm.response.json();
 16
 17     pm.expect(response.args).to.eql(subject);
debug> exec response.args
{ foo: 'hello', bar: 'world' }
debug> .exit

Questions?

Feel free to post to the issues list.

License

MIT

Copyright © 2020 Kevin Swiber [email protected]

newman-debug's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.