docparse-api
Version:
api server for the docparse project
67 lines (62 loc) • 2.09 kB
JavaScript
var assert = require('assert');
var fs = require('fs');
var path = require('path');
var spawn = require('child_process').spawn;
var request = require('request');
var should = require('should');
var inspect = require('eyespect').inspector({maxLength: 9999999});
var seaport = require('seaport');
var configFilePath = path.join(__dirname, 'testConfig.json');
assert.ok(fs.existsSync(configFilePath) ,'config file not found at path: ' + configFilePath);
var config = require('docparse-config')(configFilePath);
var child;
describe('Spinup scraper server', function () {
var sandbox;
var seaportServer;
beforeEach(function () {
seaportServer = seaport.createServer();
var seaportPort = config.get('seaport:port');
inspect(seaportPort, 'seaport listening on port');
seaportServer.listen(seaportPort);
// sandbox = sinon.sandbox.create();
});
afterEach(function () {
if (child) {
child.kill();
}
seaportServer.close();
});
it('should spinup server and respond to ping requests', function (done) {
this.timeout('10s');
this.slow('4s');
var data = {
config: config,
logger: {}
};
var filePath = path.join(__dirname, '..', 'spinUpServer.js');
inspect(filePath, 'starting up server at path');
child = spawn('node', [filePath, '--config', configFilePath]);
child.stdout.setEncoding('utf8');
child.stdout.on('data', function (data) {
console.log('stdout data', data);
});
child.stderr.pipe(process.stderr);
seaportServer.on('register', function (service) {
var servers = seaportServer.query('api');
should.exist(servers);
servers.length.should.be.above(0);
var server = servers[0];
var port = server.port;
var host = server.host;
var url = 'http://' + host + ':' + String(port) + '/ping';
inspect(url,'url');
request(url, function (err, res, body) {
should.not.exist(err);
inspect(body,'body');
res.statusCode.should.eql(200);
body.should.eql('"PONG"');
done();
});
});
});
});