Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setup('1.4', (err, child, stdout) => {
if (err) {
throw err;
}
Wreck.get('http://localhost:4000/', (err, res, payload) => {
expect(err).to.not.exist();
expect(payload.toString()).to.equal('Hello World!');
Wreck.get('http://localhost:4000/json', (err, res, payload) => {
expect(err).to.not.exist();
expect(JSON.parse(payload)).to.deep.equal({ hello: 'World' });
// Check logging output
expect(getStreamBuffer(stdout)).to.include('[response]');
cleanup(child, done);
});
});
});
async function runPagespeed(urlString, strategy) {
const url = new URL(urlString);
if(!url.hash) {
// bust PSI cache but not your CDN's cache
url.hash = `#${Date.now().toString().substring(6)}`
}
const queryOptions = {
url: url.toString(),
strategy: strategy || 'mobile',
}
const query = new URLSearchParams(queryOptions)
const apiUrl = `${baseUrl}/?${query.toString()}`;
const {payload} = await wreck.get(apiUrl, {json: true});
return {result: payload.lighthouseResult};
}
module.exports = function stargazers (url, callback) {
if(!url || url.length === 0 || typeof url === 'undefined'){
return callback(400);
}
if(url.indexOf('page=') === -1) { // e.g: /tj/followers?page=2
url = 'https://github.com' + '/' + url + '/stargazers'; // becomes https://github.com/{username}/followers
}
wreck.get(url, function (error, response, html) {
if (error || response.statusCode !== 200) {
callback(response.statusCode);
}
else {
var data = { entries : [] }, u;
var $ = cheerio.load(html);
$('.follow-list-item').each(function () {
u = $(this).find('a').attr('href').replace("/", "")
data.entries.push(u);
});
var next = $('.pagination > a').filter(function () {
return $(this).text() === "Next";
});
if(next.length > 0) {
data.next = next['0'].attribs.href;
}
module.exports = function following (url, callback) {
if(!url || url.length === 0 || typeof url === 'undefined'){
return callback(400);
}
if(url.indexOf('page=') === -1) { // e.g: /tj/followers?page=2
url = 'https://github.com' + '/' + url + '/following'; // becomes https://github.com/{username}/followers
}
wreck.get(url, function (error, response, html) {
if (error || response.statusCode !== 200) {
callback(response.statusCode);
}
else {
var data = { entries : [] };
var $ = cheerio.load(html);
$('.follow-list-item').each(function () {
data.entries.push($(this).find('a').attr('href').replace("/", ""));
});
var next = $('.pagination > a').filter(function () {
return $(this).text() === "Next";
});
if(next.length > 0) {
data.next = next['0'].attribs.href;
}
callback(error, data)
it('returns a gzip response on a get request when accept-encoding: gzip is requested', function (done) {
Wreck.get(uri, { headers: { 'accept-encoding': 'gzip' } }, function (err, res, body) {
expect(err).to.not.exist;
expect(body).to.equal(zdata);
done();
});
});
setup('3.2.1', (err, child) => {
if (err) {
throw err;
}
Wreck.get('http://localhost:4000/', (err, res, payload) => {
expect(err).to.not.exist();
expect(payload.toString()).to.include('DinDin Mobile Website');
cleanup(child, done);
});
});
});
setup('5.1.3', (err, child, stdout, stderr) => {
if (err) {
throw err;
}
Wreck.get('http://localhost:4000/', (err, res, payload) => {
expect(err).to.not.exist();
expect(res.statusCode).to.equal(403);
expect(getStreamBuffer(stdout)).to.include('Blocking request from 127.0.0.1. Within blocked subnet 127.0.0.0/8');
cleanup(child, done);
});
});
});
return new Bluebird(function (resolve, reject) {
Wreck.get(uri, options, function (err, res, payload) {
if (err) return reject(Boom.serverTimeout(MISSING_SCHEMA_ERROR))
return resolve([
res,
payload,
])
})
})
}
return new Promise(function (resolve, reject) {
Wreck.get(url, options, function (err, resp, payload) {
if (err) return reject(err);
resolve(payload);
});
});
};
var searchReviews = function (query, callback) {
var baseUrl = 'http://api.nytimes.com/svc/movies/v2/reviews/search.json';
var queryObj = {
'api-key': '2d07d4c26378607c5e104ae3164327ff:18:72077307',
query: query
};
var queryUrl = baseUrl + '?' + Qs.stringify(queryObj);
var options = { json: true };
Wreck.get(queryUrl, options, function (err, res, payload) {
callback(err, payload);
});
};