Commit
Acceptance tests
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
.travis.yml | ||
^node_modules | ||
^test | ||
^package.json$ | ||
^README.md |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
*.tar.gz | ||
..Rcheck | ||
*.Rcheck | ||
node_modules | ||
npm-debug.log |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# Generated by roxygen2 (4.1.1): do not edit by hand | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(microserver_response) | ||
export(run_server) | ||
import(httpuv) | ||
import(jsonlite) | ||
importFrom(methods,as) | ||
importFrom(stats,setNames) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
list( | ||
"/ping" = function(...) "pong" | ||
, "/parse_query" = function(p, q) { list(query = q) } | ||
, function(...) list(exception = "catch all route") | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
library(methods) | ||
devtools::load_all() | ||
|
||
routes <- source(microserver:::packagefile('inst/routes.R'))$value | ||
cat('listening..\n') | ||
microserver::run_server(routes, 33399) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "microserver", | ||
"version": "0.1.2", | ||
"description": "Acceptance tests for github.com/robertzk/microserver", | ||
"main": "", | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha --delay" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/robertzk/microserver.git" | ||
}, | ||
"author": "Kirill Sevastyanenko <kirillseva@gmail.com> (http://github.com/kirillseva)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/robertzk/microserver/issues" | ||
}, | ||
"homepage": "https://github.com/robertzk/microserver#readme", | ||
"dependencies": { | ||
"chai": "^3.5.0", | ||
"chai-http": "^3.0.0", | ||
"mocha": "^2.5.3" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict'; | ||
|
||
var chai = require('chai') | ||
, chaiHttp = require('chai-http') | ||
, spawn = require('child_process').spawn | ||
, PORT = 33399 | ||
, should = chai.should(); | ||
|
||
chai.use(chaiHttp); | ||
|
||
var base_url = 'http://localhost:' + PORT; | ||
|
||
var microserver = spawn('Rscript', [process.cwd() + '/inst/simple_server.R']); | ||
microserver.on('data', function (data) { | ||
console.log('stdout: ' + data); | ||
}); | ||
microserver.stderr.on('data', function (data) { | ||
console.log('stderr: ' + data); | ||
}); | ||
microserver.on('close', function (code, signal) { | ||
console.log('R process exited with code ' + code + ' by signal ' + signal); | ||
}); | ||
microserver.on('error', function (err) { | ||
console.log('Failed to start child process.'); | ||
}); | ||
|
||
setTimeout( | ||
function() { | ||
describe('microserver', function() { | ||
after(function() { | ||
microserver.kill() | ||
}); | ||
it('should pong on a /ping', function(done) { | ||
chai.request(base_url) | ||
.get('/ping') | ||
.end(function(err, res) { | ||
should.not.exist(err); | ||
res.should.have.status(200); | ||
res.body.should.equal('pong'); | ||
done(); | ||
}); | ||
}); | ||
it('should use a catch all route on other requests', function(done) { | ||
chai.request(base_url) | ||
.get('/foo') | ||
.end(function(err, res) { | ||
should.not.exist(err); | ||
res.should.have.status(200); | ||
res.type.should.equal('application/json'); | ||
res.body.exception.should.equal('catch all route'); | ||
done(); | ||
}); | ||
}); | ||
it('can parse query parameters', function(done) { | ||
var query = { name: 'foo', limit: 1 } | ||
chai.request(base_url) | ||
.get('/parse_query') | ||
.query(query) | ||
.end(function(err, res) { | ||
should.not.exist(err); | ||
res.should.have.status(200); | ||
res.body.query.name.should.equal(query.name); | ||
console.log(res.body); | ||
res.body.query.limit.should.equal(query.limit.toString()); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
run(); | ||
}, | ||
2000 // allow R server to start | ||
); |