Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
mock-req
Advanced tools
Readme
Mocks node.js http.IncomingMessage
(a request). See also mock-res
.
Being a readable/writable stream, you can pipe the request body to and from it.
See test.js
for further usage.
var MockReq = require('mock-req');
// Basic usage
var req = new MockReq();
// With options
var req = new MockReq({
method: 'PUT',
url: '/stuff?q=thing',
headers: {
'Accept': 'text/plain'
},
// arbitrary properties:
search: 'thing'
});
// Write body
req.write('hello');
req.write('world');
// Or stringify to JSON
req.write({
val: 5
});
// Or even buffers
req.write(new Buffer('buf'));
// End body
req.end();
// NOTE req.end() is automatically called if
// method is set to GET/HEAD/DELETE.
var assert = require('assert');
var ping = require('./ping-handler');
var MockReq = require('mock-req');
function test(done) {
/* Arrange */
var req = new MockReq({
method: 'GET',
url: '/stuff',
headers: {
'Accept': 'text/plain'
}
});
// NOTE: `req.end()` is automatically called for GET/HEAD/DELETE methods
// Use `mock-res` for a better mock
var res = {
end: end
};
/* Act */
ping(req, res);
/* Assert */
function end(data) {
assert.equal(data, 'okay');
done(); // this is an async test
}
}
The options parameter is optional.
method
: The request's method, defaults to 'GET'url
: The request's URL, defaults to ''headers
: A case insensitive name/value objectAll other values will be copied to the request.
req._fail(error)
Causes the request to emit an error
when written to.FAQs
Mocks node.js `http.IncomingMessage` (a request). See also `mock-res`.
The npm package mock-req receives a total of 54,662 weekly downloads. As such, mock-req popularity was classified as popular.
We found that mock-req demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.