![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
#Dummy.js
Simple testing of node tcp/tls servers.
Useful with testing libraries such as Mocha and Should.js.
Getting it:
npm install dummy
Using it:
var Dummy = require('dummy');
Imagine a server that responds with the data you sent it, prepended with 'you sent : ', if we send the server 'hey' it should respond with 'you sent : hey'. Pretty simple, right?. Let's say you wanted to write some tests for your nifty server that verified it's behavior, even when multiple things are sent to the server. Using Mocha and Should.js, let us examine what this code might look like without Dummy.js.
//leaving the requires out to keep it short
describe('awesome server', function() {
//before any tests are run, get an instance of AwesomeServer up and
// listening for connections
var awesomeServer;
before(function(done) {
awesomeServer = new AwesomeServer();
awesomeServer.listen(1234, function() {
done();
});
});
it('should respond correctly', function(done) {
//connect to the AwesomeServer
var client = net.connect(1234, function() {
client.write('hey\n');
});
//we got some data, let's look at it
client.on('data', function(data) {
data = data.toString();
if(data === 'you sent : hey) {
client.write('haha\n');
} if(data === 'you sent : haha') {
done;
}
});
});
});
This test ignores a lot of things. The server could incorrectly be sending two pieces of data to the client, and they happened to fit into one packet. The server could be sending one very long message that did not fit into one packet of data. We need to delimit our data and work accordingly. Secondly, without adding some sort of count, we cannot be sure that the response received is associated with the first write, or the second write.
This is where Dummy.js comes in handy. Let's look at the same problem again, but use Dummy.js.
//leaving the requires out to keep it short
describe('awesome server', function() {
//before any tests are run, get an instance of AwesomeServer up and
// listening for connections
var awesomeServer;
before(function(done) {
awesomeServer = new AwesomeServer();
awesomeServer.listen(1234, function() {
done();
});
});
it('should respond correctly', function(done) {
var dummy = new Dummy(false, 1234, '127.0.0.1', '\n', function() {
dummy.send('hey\n', 'you sent : hey', function(expected, data) {
expected.should.equal.true;
dummy.send('haha\n', 'you sent : haha', function(expected, data) {
expected.should.equal.true;
done();
});
});
});
});
});
This makes a lot more sense, and is pretty easy to follow.
#####+ Dummy(secure, port, hostname, delimiter, connectionCallback)
#####- send(data, response, responseCallback(expected, data))
Right now, only send more data to the server in callbacks that the Dummy calls. This keeps weird conditions from happening. I am working on an implementation around this issue.
This project is very short and sweet, however, I will be making changes to it frequently. Feel free to fork me. Also, feel free to comment on my coding style, I'm new to Javascript, and I'm not sure if I'm doing it right.
Thanks!
FAQs
a tcp/tls dummy client for server testing
The npm package dummy receives a total of 70 weekly downloads. As such, dummy popularity was classified as not popular.
We found that dummy 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.