New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dummy

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dummy - npm Package Compare versions

Comparing version

to
0.1.6

dist/index.d.ts

56

package.json
{
"author": "Matt Egan <matt.matt.egan@gmail.com>",
"name": "dummy",
"description": "a tcp/tls dummy client for server testing",
"version": "0.1.5",
"homepage": "http://www.github.com/mattegan/Dummy.js",
"version": "0.1.6",
"description": "Performant and lightweight dummy data generation.",
"author": "Patrick Gerstacker",
"license": "MIT",
"exports": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
},
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsup src/index.ts",
"dev": "tsup src/index.ts --watch",
"test": "jest --runInBand",
"format": "prettier --write ."
},
"keywords": [
"dummy"
],
"repository": {
"type": "git",
"url": "git://github.com/mattegan/Dummy.js.git"
"url": "git+https://github.com/gxrsti/dummy.git"
},
"scripts": {
"test": "mocha -R spec"
"bugs": {
"url": "https://github.com/gxrsti/dummy/issues"
},
"engines": {
"node": "~0.6.10"
"prettier": {
"printWidth": 120,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"tabWidth": 2
},
"main": "./lib/dummy",
"dependencies": {},
"devDependencies": {},
"optionalDependencies": {}
"devDependencies": {
"@testing-library/jest-dom": "^6.6.3",
"@types/jest": "^29.5.14",
"@types/node": "^18.11.13",
"@types/react": "^18.0.26",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"prettier": "^2.8.4",
"ts-jest": "^29.2.5",
"tsup": "^6.4.0",
"typescript": "^4.8.4"
}
}

@@ -1,103 +0,27 @@

#Dummy.js
* * *
Simple testing of node tcp/tls servers.
# Dummy
Useful with testing libraries such as [Mocha](http://visionmedia.github.com/mocha/) and [Should.js](https://github.com/visionmedia/should.js/).
Performant and lightweight dummy data generation.
###I Want.
---
Getting it:
npm install dummy
## Installation
Using it:
To start using the library, install it in your project:
var Dummy = require('dummy');
```bash
npm install dummy
```
###Why?
---
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.
After that, you can import `dummy` and use its data generation functions from anywhere in your app.
//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;
}
});
});
});
```jsx
import { dummy } from 'dummy';
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.
// ...
###Dummy.js
---
This is where Dummy.js comes in handy. Let's look at the same problem again, but use Dummy.js.
var randomId = dummy.string.uuid(); // d02e9296-7063-450c-9dfc-9edd73076c8d
var randomUsername = dummy.number.float(); // 14.21
var randomRegisteredAt = dummy.date.past(); // 2021-05-07T01:30:54.348Z
```
//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();
});
});
});
});
});
## Documentation
This makes a lot more sense, and is pretty easy to follow.
###Reference
---
#####*+ Dummy*(secure, port, hostname, delimiter, connectionCallback)
* **secure** : either an object or something else - if object, dummy uses it as a settings object for a tls connection - this can cause an error if the tls library doesn't enjoy your object, pass *false* if not using a secure connection
* **port** : pretty self explanatory
* **hostname** : really?
* **delimiter** : how is the server separating messages
* **connectionCallback** : a function to call when the client has connected to the server
#####*- send*(data, response, responseCallback(expected, data))
* **data** : the data to write to the server
* **response** : the response to be expecting from the server
* **responseCallback** : the callback to call when the server has (or has not) received data in response to sending data, the callback will have two arguments, a boolean that is true or false depending on the server's response matching the response expected, and a data object, that contains the data the server actually received
###Important Things
---
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!*
You can find out more about the API and implementation soon.