Socket
Socket
Sign inDemoInstall

ntf

Package Overview
Dependencies
1
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

ntf


Version published
Maintainers
1
Created

Readme

Source

ntf Build Status

ntf is a network testing framework written in Node.js.

Getting Started

Install ntf

npm install ntf
npm install ntf -g

Create a file named ntfjs.org.js

var ntf = require('ntf')
  , test = ntf.http('http://ntfjs.org')

exports.homepage = test.get('/', function(test) {
  test.statusCode(200)
  test.body('ntf')
  test.done()
})

Run the tests

ntf ntfjs.org.js
## Documentation

DNS

HTTP

Socket

## DNS

Test DNS records.

var ntf = require('ntf')
  , dns = ntf.dns()
### dns.a(name, callback)

Resolve an IPv4 address record.

Arguments

  • name {String} - name to resolve
  • callback(test) {Function} - test callback

Example

exports.a = dns.a('a.dns.ntfjs.org', function(test) {
  test.address('127.0.0.1')
  test.done()
})
### dns.aaaa(name, callback)

Resolve an IPv6 address record.

Arguments

  • name {String} - name to resolve
  • callback(test) {Function} - test callback

Example

exports.aaaa = dns.aaaa('aaaa.dns.ntfjs.org', function(test) {
  test.address('::1')
  test.done()
})
### dns.cname(name, callback)

Resolve a canonical name record.

Arguments

  • name {String} - canonical name to resolve
  • callback(test) {Function} - test callback

Example

exports.cname = dns.cname('cname.dns.ntfjs.org', function(test) {
  test.name('a.dns.ntfjs.org')
  test.done()
})
### dns.mx(name, callback)

Resolve a mail exchange record.

Arguments

  • name {String} - mail exchange to resolve
  • callback(test) {Function} - test callback

Example

exports.mx = dns.mx('mx.dns.ntfjs.org', function(test) {
  test.name('mx1.dns.ntfjs.org')
  test.done()
})
### dns.ns(name, callback)

Resolve a name server record.

Arguments

  • name {String} - name server to resolve
  • callback(test) {Function} - test callback

Example

exports.ns = dns.ns('ns.dns.ntfjs.org', function(test) {
  test.name('ns1.dns.ntfjs.org')
  test.done()
})
### dns.ptr(ip, callback)

Resolve a pointer record.

Arguments

  • name {String} - IP address to resolve
  • callback(test) {Function} - test callback

Example

exports.ptr = dns.ptr('50.116.49.237', function(test) {
  test.name('hub.sewell.org')
  test.done()
})
### dns.srv(name, callback)

Resolve a service location record.

Arguments

  • name {String} - service to resolve
  • callback(test) {Function} - test callback

Example

exports.srv = dns.srv('_ntfjs', function(test) {
  test.name('srv1.dns.ntfjs.org')
  test.done()
})
### dns.txt(name, callback)

Resolve a text record.

Arguments

  • name {String} - text to resolve
  • callback(test) {Function} - test callback

Example

exports.txt = dns.txt('_ntfjs', function(test) {
  test.done()
})
### test.address(ip)

Assert answer contains IP address.

Arguments

  • ip {String} - IP address to check

Example

exports.a = dns.a('a.dns.ntfjs.org', function(test) {
  test.address('127.0.0.1')
  test.done()
})
### test.name(name)

Assert answer contains name.

Arguments

  • name {String} - name to check

Example

exports.cname = dns.cname('cname.dns.ntfjs.org', function(test) {
  test.name('a.dns.ntfjs.org')
  test.done()
})
## HTTP

Test HTTP requests.

var ntf = require('ntf')
  , http = ntf.http('http://http.ntfjs.org')
### http.request(options, callback)

Execute an HTTP request.

__Arguments__
  • options {Object,String} - options or path/URL
    • auth {String} - username and password (ex: "user:pass")
    • body {Object,String} - request body
    • cookie {Object} - cookie names and values (ex: { "sid": "2bf74f" })
    • header {Object} - header names and values (ex: { "content-type": "application/json" })
    • jar {Boolean} - persist cookies in sub-requests
    • method {String} - HTTP method (delete, get, post, put)
    • timeout {Integer} - maximum number of milliseconds request can take before its killed
    • type {String} - encodes body and sets content-type header (form, json)
    • url {String} - path or URL
  • callback(test) {Function} - test callback

Example

exports.request = http.request('/', function(test) {
  test.statusCode(200)
  test.done()
})
### http.del(options, callback)

Execute an HTTP delete request.

Arguments

Example

exports.del = http.del('/delete', function(test) {
  test.statusCode(200)
  test.done()
})
### http.get(options, callback)

Execute an HTTP get request.

Arguments

Example

exports.get = http.get('/get', function(test) {
  test.statusCode(200)
  test.done()
})
### http.head(options, callback)

Execute an HTTP head request.

Arguments

Example

exports.head = http.head('/head', function(test) {
  test.statusCode(200)
  test.done()
})
### http.options(options, callback)

Execute an HTTP options request.

Arguments

Example

exports.options = http.options('/options', function(test) {
  test.statusCode(200)
  test.done()
})
### http.patch(options, callback)

Execute an HTTP patch request.

Arguments

Example

exports.patch = http.patch('/patch', function(test) {
  test.statusCode(200)
  test.done()
})
### http.post(options, callback)

Execute an HTTP post request.

Arguments

  • options {Object} - see request arguments
    • body {Object,String} - should be object by default (see type below)
    • method {String} - always set to post
    • type {String} - defaults to form
  • callback(test) {Function} - test callback

Example

exports.post = http.post({ url: '/post', body: { 'q': 'test' } }), function(test) {
  test.statusCode(201)
  test.done()
})
### http.put(options, callback)

Execute an HTTP put request.

Arguments

Example

exports.put = http.put({ url: '/put', body: 'put' }), function(test) {
  test.statusCode(201)
  test.done()
})
### test.body([match[, compare...]])

Tests match against body and returns result.

Arguments

  • match
    • RegExp - asserts body matches RegExp
      • compare {String} - compare against match results
      • return {Array,null} - RegExp match result
    • String - asserts body contains match
      • return {Integer} - first position of matched result
    • undefined
      • return {String,undefined} - body String

Example

exports.get = http.get('/', function(test) {
  test.body(/<title>(.*)<\/title>/, 'ntf')
  test.done()
})
### test.cookie([name[, match]])

Tests cookie existence/value and returns match.

Arguments

  • name {String} - cookie name
  • match
    • RegExp - asserts value matches RegExp
      • return {Array,null} - RegExp match result
    • String - asserts value matches String
    • undefined
      • return {Object,undefined} - cookie object

Example

exports.get = http.get('/', function(test) {
  test.cookie('sid', /^[a-f0-9]+$/)
  test.done()
})
### test.header([name[, match]])

Tests header existence/value and returns match.

Arguments

  • name {String} - header name
  • match
    • RegExp - asserts value matches RegExp
      • return {Array,null} - RegExp match result
    • String - asserts value matches String
    • undefined
      • return {Object,undefined} - header object

Example

exports.get = http.get('/', function(test) {
  test.header('Content-Type', 'text/html')
  test.done()
})
### test.json([match])

Tests body against match and returns parsed JSON.

Arguments

  • match - deep equal assert against match
  • return - parsed JSON object

Example

exports.get = http.get('/', function(test) {
  test.json({ one: 'two' })
  test.done()
})
### test.jsonPath([path[, compare...]])

Tests json path against compares and returns result.

Arguments

Example

exports.get = http.get('/', function(test) {
  test.jsonPath('$.book.title', 'Second Foundation', "The Wise Man's Fear")
  test.done()
})
### test.statusCode(code)

Tests response status code.

Arguments

  • code {Integer} - status code

Example

exports.get = http.get('/', function(test) {
  test.statusCode(200)
  test.done()
})
## Socket

Test socket connections.

var ntf = require('ntf')
  , socket = ntf.socket('ntfjs.org')
### socket.tcp(port, callback)

Open TCP connection to host and port.

Arguments

  • options {Integer,Object} - port or options
    • port {Integer} - port
    • timeout {Integer} - maximum number of milliseconds before connection is killed
  • callback(test) {Function} - test callback

Example

exports.tcp = socket.tcp(25, function(test) {
  test.connect()
  test.done()
})
### test.connect(code)

Tests connection was opened.

Example

exports.tcp = socket.tcp(25, function(test) {
  test.connect()
  test.done()
})

License

This work is licensed under the MIT License (see the LICENSE file).

Keywords

FAQs

Last updated on 11 May 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc