Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

censeo

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

censeo - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

index.js

36

package.json
{
"name": "censeo",
"version": "0.1.0",
"version": "0.2.0",
"description": "Run arbitrary JavaScript or PogoScript on a server",
"author": "Derek Ekins <derek@spathi.com>",
"repository": {
"type": "git",
"url": "https://github.com/dereke/censeo.git"
},
"scripts": {
"test": "node_modules/karma/bin/karma start"
},
"bugs": {
"url": "https://github.com/dereke/censeo/issues"
},
"keywords": [
"eval",
"runtime",
"test",
"mocha",
"pogo"
],
"main": "index.js",
"files": [
"server.js",
"client.js"
"index.js",
"lib/server.js",
"lib/client.js"
],

@@ -17,16 +33,16 @@ "license": "ISC",

"socket.io": "^1.0.6",
"express": "^4.4.5",
"socket.io-client": "^1.0.6",
"bluebird": "^2.1.3"
"bluebird": "2.1.1"
},
"devDependencies": {
"browserify": "^4.2.0",
"karma": "^0.12.16",
"karma-browserify": "^0.2.1",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^0.1.4",
"karma-mocha": "^0.1.4",
"mocha": "^1.20.1",
"karma-mocha": "^0.1.4",
"browserify": "^4.2.0",
"karma-chai": "^0.1.0",
"karma-browserify": "^0.2.1",
"pogoify": "^0.1.0"
"pogoify": "^0.1.0",
"reqwest": "^1.1.0"
}
}

@@ -7,2 +7,127 @@ # censeo

Preferable only in test code
Preferable only in test code
# Insructions
First of all you need to start up the server specifying a port number to use.
If you are using karma you may want to put this in your `karma.conf.js` file.
```
require('censeo').server(3001)
```
Next you want to create a client:
```
client = require('censeo').client(3001)
```
Then in your test (you should only use this for tests!).
```
client
.run(function() {
return 1 + 1;
}).then(function(result){
expect(result).to.equal(2)
})
```
You can also run async code on the server
```
client
.run(function(callback) {
var fs = require("fs");
fs.readdir(process.cwd(), callback);
}).then(function(result) {
expect(result).to.include("node_modules");
});
```
Where censeo can come in really handy is if you need to spool up a webserver to test against:
```
client
.run(function() {
var http, app, server;
http = require("http");
app = http.createServer(function(req, res) {
var headers;
headers = {
"Content-Type": "text/plain",
Connection: "Close",
"Access-Control-Allow-Headers": "accept, x-requested-with, content-type",
"Access-Control-Allow-Methods": "GET, OPTIONS",
"Access-Control-Allow-Origin": req.headers.origin
};
if (req.method === "OPTIONS") {
res.writeHead(204, headers);
return res.end("OK");
} else {
res.writeHead(200, headers);
return res.end("ALIVE");
}
});
server = app.listen(8555);
console.log("listening on 8555");
return {
stop: function(done) {
var self = this;
return server.close(done);
}
};
}, {
task: true
}).then(function(task){
// make some http requests to the server
// then stop the server
task.stop(function(){
console.log('stopped')
})
})
```
# [PogoScript](http://pogoscript.org)
PogoScript makes using censeo even better:
```
result = client.run! @{1+1}
expect(result).to.equal(2)
```
or to run a web server
```
task = client.run!(task: true)
http = require 'http'
app = http.createServer @(req, res)
headers = {
'Content-Type' = 'text/plain'
'Connection' = 'Close'
'Access-Control-Allow-Headers' = 'accept, x-requested-with, content-type'
'Access-Control-Allow-Methods' = 'GET, OPTIONS'
'Access-Control-Allow-Origin' = req.headers.origin
}
if (req.method == 'OPTIONS')
res.writeHead(204, headers)
res.end('OK')
else
res.writeHead(200, headers)
res.end('ALIVE')
server = app.listen(8555)
console.log "listening on 8555"
{
stop(done)=
server.close(done)
}
server url = 'http://localhost:8555'
response = request!({url = server url})
expect(response).to.equal('ALIVE')
task.stop!()
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc