|  | @@ -0,0 +1,81 @@
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import child_process from 'child_process';
 | 
	
		
			
				|  |  | +import tape from 'blue-tape';
 | 
	
		
			
				|  |  | +import http from 'http';
 | 
	
		
			
				|  |  | +import socketclient from 'socket.io-client';
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +const serverhost = 'localhost',
 | 
	
		
			
				|  |  | +    serverport = 8084,
 | 
	
		
			
				|  |  | +    server = child_process.fork('build/server.js');
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +tape.test('test server', function testServer(t) {
 | 
	
		
			
				|  |  | +    let client;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    waitPro()
 | 
	
		
			
				|  |  | +    .then(function done(a) {
 | 
	
		
			
				|  |  | +        return requestPro(`http://${serverhost}:${serverport}`)
 | 
	
		
			
				|  |  | +        .then(function done(a) {
 | 
	
		
			
				|  |  | +            t.equal(a, 'yes', 'received message from server');
 | 
	
		
			
				|  |  | +        })
 | 
	
		
			
				|  |  | +    })
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    .catch(function catchall(e) {
 | 
	
		
			
				|  |  | +        console.log('error somewhere', e);
 | 
	
		
			
				|  |  | +        t.fail('error somewhere');
 | 
	
		
			
				|  |  | +    })
 | 
	
		
			
				|  |  | +    .then(function done(a) {
 | 
	
		
			
				|  |  | +        t.end();
 | 
	
		
			
				|  |  | +        server.kill();
 | 
	
		
			
				|  |  | +    })
 | 
	
		
			
				|  |  | +});
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +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);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            req.on('error', function err(ee) {
 | 
	
		
			
				|  |  | +                reject(ee);
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            if( data ) {
 | 
	
		
			
				|  |  | +                req.write(data);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            req.end();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        catch(e) {
 | 
	
		
			
				|  |  | +            reject(e);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +function responsePro(socket, evt, wait = 3000) {
 | 
	
		
			
				|  |  | +    return new Promise(function pro(resolve, reject) {
 | 
	
		
			
				|  |  | +        let to = setTimeout(reject.bind(null, 'socket event TIMEOUT ' + evt), wait);
 | 
	
		
			
				|  |  | +        socket.once(evt, function (a) {
 | 
	
		
			
				|  |  | +            clearTimeout(to);
 | 
	
		
			
				|  |  | +            resolve(a);
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 |