Socket
Socket
Sign inDemoInstall

rqt

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rqt - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

test/context/index.js

6

package.json
{
"name": "rqt",
"version": "0.1.1",
"version": "0.1.2",
"description": "request library",

@@ -24,4 +24,8 @@ "main": "src/index.js",

"devDependencies": {
"server-destroy": "1.0.1",
"zoroaster": "0.4.6"
},
"dependencies": {
"catchment": "1.0.0"
}
}

9

README.md

@@ -5,5 +5,5 @@ # rqt

## `rqt():void`
## `rqt(url):Promise.<string>`
Call this function to get a result you want.
Call this function to request a web page.

@@ -13,3 +13,6 @@ ```js

rqt()
rqt('http://rqt.sobes.io')
.then((res) => {
console.log(res) // web page
})
```

@@ -16,0 +19,0 @@

@@ -0,8 +1,22 @@

const http = require('http')
const debuglog = require('util').debuglog('rqt')
const Catchment = require('catchment')
/**
* Invoke package's main function
* Request an HTTP page.
* @param {string} url Url such as http://example.com/api
*/
function rqt() {
console.log('rqt called')
function rqt(url) {
debuglog('rqt %s', url)
return new Promise((resolve, reject) => {
const request = http.request(url, (res) => {
const catchment = new Catchment()
res.pipe(catchment)
catchment._promise.then(resolve)
})
request.on('error', reject)
request.end()
})
}
module.exports = rqt
const assert = require('assert')
const rqt = require('../../src/')
const context = require('../context/')
const rqtTestSuite = {
context,
'should be a function': () => {
assert.equal(typeof rqt, 'function')
},
'should call package without error': () => {
assert.doesNotThrow(() => {
rqt()
})
'should request data from server': (ctx) => {
const testData = 'test-data'
ctx.data = testData
return rqt(ctx.url)
.then((res) => {
assert(ctx.called)
assert.equal(res, testData)
})
},
'should fail': () => {
const url = `http://not-a-valid-web-page-${Math.floor(Math.random() * 10000)}.io`
return rqt(url)
.then(() => {
throw new Error('Should have thrown an error')
}, (err) => {
assert.equal(err.code, 'ENOTFOUND')
})
},
}
module.exports = rqtTestSuite
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