Тестирование простое. Вы просто создаете модульный тест, который запускает ваш экспресс-сервер, делает HTTP POST и утверждает, что ваш HTTP-пост работает и возвращает правильный вывод обратно.
Использование vows-is . (Извините, без кофеина)
var is = require("vows-is"),
app = require("../src/app.js");
is.config({
"server": {
"factory": function _factory(cb) { cb(app); }
}
});
is.suite("http request test").batch()
.context("a request to POST /incoming")
// make a POST request
.topic.is.a.request({
"method": "POST",
"uri": "http://localhost:8080/incoming",
// set the request body (req.body)
"json": {
"Body": ...,
"From": ...
}
})
.vow.it.should.have.status(200)
.vow.it.should.have
.header("content-type", "text/xml")
.context("contains a body that")
.topic.is.property('body')
.vow.it.should.be.ok
.vow.it.should.include.string('<?xml version="1.0" encoding="UTF-8" ?>\n<Response>\n<Say>Thanks for your text, we\'ll be in touch.</Say>\n</Response>')
// run the test suite
.suite().run({
reporter: is.reporter
}, function() {
is.end();
});
Сохраните это в файле http-test.js
в папке test
. Тогда просто запустите
$ npm install vows-is
$ node test/http-test.js
См. пример экспорта вашей функции serverSetup