|
@@ -0,0 +1,67 @@
|
|
|
|
+
|
|
|
|
+import {fork} from 'child_process';
|
|
|
|
+import tape from 'blue-tape';
|
|
|
|
+import http from 'http';
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+tape.test('service', function testService(t) {
|
|
|
|
+ const server = fork('build/service.js'),
|
|
|
|
+ connstring = 'http://localhost:8080';
|
|
|
|
+ waitPro()
|
|
|
|
+ .then(function done(a) {
|
|
|
|
+ return requestPro(connstring + '/')
|
|
|
|
+ .then(function done(data) {
|
|
|
|
+ console.log('data', data);
|
|
|
|
+ return JSON.parse(data);
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ .catch(function (e) {
|
|
|
|
+ console.log('error somewhere', e);
|
|
|
|
+ t.fail('error somewhere');
|
|
|
|
+ })
|
|
|
|
+ .then(function done(a) {
|
|
|
|
+ server.kill();
|
|
|
|
+ DB.disconnect();
|
|
|
|
+ t.end();
|
|
|
|
+ });
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+function waitPro(n = 1000) {
|
|
|
|
+ return new Promise(function pro(resolve, reject) {
|
|
|
|
+ setTimeout(resolve, n);
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+function requestPro(reqopts, data) {
|
|
|
|
+ return new Promise(function prot(resolve, reject) {
|
|
|
|
+ try {
|
|
|
|
+ let req = http.request(reqopts, function received(resp) {
|
|
|
|
+ let str = '';
|
|
|
|
+ resp.on('data', function p(part) {
|
|
|
|
+ str += part;
|
|
|
|
+ });
|
|
|
|
+ resp.on('end', function done() {
|
|
|
|
+ if( resp.statusCode >= 400 && resp.statusCode <= 599 ) {
|
|
|
|
+ reject(str);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ resolve(str);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ if( data ) {
|
|
|
|
+ req.write(data);
|
|
|
|
+ }
|
|
|
|
+ req.end();
|
|
|
|
+ }
|
|
|
|
+ catch(e) {
|
|
|
|
+ reject(e);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|