Comparing version 0.1.1 to 0.1.2
{ | ||
"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" | ||
} | ||
} |
@@ -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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6051
10
117
21
1
2
2
+ Addedcatchment@1.0.0
+ Addedcatchment@1.0.0(transitive)