Socket
Socket
Sign inDemoInstall

ntf

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ntf - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

examples/basic.js

6

examples/basic/http.js
var ntf = require('../../lib/ntf')
, test = ntf.http.test(exports, 'http://silas.sewell.org')
, test = ntf.http.test(exports, 'https://github.com')
test.get('homepage', '/', function(test, res) {
test.get('ntf project page', '/silas/ntf', function(test, res) {
test.statusCode(res, 200)
test.hasContent(res, 'Silas Sewell')
test.hasContent(res, 'ntf')
test.done()
})
var ntf = require('../../lib/ntf')
, test = ntf.socket.test(exports, 'silas.sewell.org')
, test = ntf.socket.test(exports, 'github.com')
test.tcp('http', 80, function(test, socket) {
test.tcp('github http', 80, function(test, socket) {
test.connectionEstablished(socket)
test.done()
})
var http = require('http')
, https = require('https')
, uri = require('url')
, utils = require('./utils')

@@ -12,8 +13,11 @@ var asserts = {

},
json: function(res) {
var json = null
json: function(res, data) {
var json = undefined
try {
json = JSON.parse(res.data)
} catch(err) {}
this.ok(json, 'Content is JSON')
this.ok(json !== undefined, 'Content is JSON')
if (data !== undefined) {
this.deepEqual(json, data)
}
return json

@@ -25,10 +29,12 @@ },

return function() {
var args = Array.prototype.slice.call(arguments)
var baseArgs = Array.prototype.slice.call(arguments)
, name = [url + baseArgs[1], type.toUpperCase(), baseArgs[0]].join(utils.SEP)
// url can be a function
if (typeof(args[1]) === 'function') args[1] = args[1]()
if (typeof(baseArgs[1]) === 'function') baseArgs[1] = baseArgs[1]()
// add test to module
e[url + args[1] + ' :: ' + args[0]] = function(test) {
args.shift()
e[name] = function(test) {
var args = Array.prototype.slice.call(baseArgs)
args.shift() // remove description
test.url = url

@@ -35,0 +41,0 @@ args.unshift(test)

var net = require('net')
, utils = require('./utils')
var asserts = {
connectionEstablished: function(socket) {
if (!socket || !socket._ntf || socket._ntf.connected !== true) {
this.fail(true, false, '', '==', 'Failed to established connection')
}
this.ok(!socket || !socket._ntf || socket._ntf.connected == true, 'Established connection')
},

@@ -14,4 +13,9 @@ }

tcp: function() {
var args = Array.prototype.slice.call(arguments)
e['tcp://' + host + ':' + args[1] + ' :: ' + args[0]] = function(test) {
var baseArgs = Array.prototype.slice.call(arguments)
, name = ['tcp://' + host + ':' + baseArgs[1], baseArgs[0]].join(utils.SEP)
// add test to module
e[name] = function(test) {
var args = Array.prototype.slice.call(baseArgs)
args.shift() // remove description
args.unshift(host)

@@ -28,11 +32,11 @@ args.unshift(test)

, host = arguments[1]
, port = arguments[3]
, port = arguments[2]
, opts = {}
, callback = null
if (arguments.length == 6) {
opts = arguments[4]
callback = arguments[5]
if (arguments.length == 5) {
opts = arguments[3]
callback = arguments[4]
} else {
callback = arguments[4]
callback = arguments[3]
}

@@ -48,3 +52,3 @@

, start = new Date().getTime()
, timedOut = false
, done = false

@@ -58,16 +62,24 @@ socket._ntf = {}

socket.on('error', function() {
// TODO: handle error
socket.on('error', function(err) {
if (!done) {
done = true
test.ok(false, err)
test.done()
}
})
socket.on('close', function() {
if (!timedOut) callback(test, socket)
if (!done) {
done = true
callback(test, socket)
}
})
socket.setTimeout(opts.timeout, function() {
timedOut = true
test.fail(new Date().getTime() - start, opts.timeout, '', '>=', 'Connection timed out')
socket.destroy()
test.done()
if (!done) {
socket.destroy()
test.done()
}
})
}
{
"name": "ntf",
"description": "A network testing framework",
"version": "0.0.1",
"version": "0.0.2",
"engines": { "node": ">= 0.4" },

@@ -6,0 +6,0 @@ "dependencies": {

@@ -13,10 +13,25 @@ ntf

# install dependencies
npm install
# install library
npm install ntf
# run basic examples
bin/ntf examples/basic
# add node_modules bin to path
export PATH="./node_modules/.bin:$PATH"
# create test file
cat << EOF > silas.sewell.org.js
var ntf = require('ntf')
, test = ntf.http.test(exports, 'http://silas.sewell.org')
test.get('homepage', '/', function(test, res) {
test.statusCode(res, 200)
test.hasContent(res, 'Silas Sewell')
test.done()
})
EOF
# run tests
ntf silas.sewell.org.js
### License
This work is licensed under the MIT License (see the LICENSE file).

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc