1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import {fork} from 'child_process';
- import tape from 'tape';
- import _test from 'tape-promise';
- import fetch from 'isomorphic-fetch';
- const tapetest = _test(tape);
- const randomPort = Math.floor(Math.random() * 10000) + 20000,
- server = fork('build/service.js', [], {env: {port: randomPort}}),
- connstring = `http://localhost:${randomPort}`;
- tapetest('service', async function testService(assert) {
- try {
- await waitPro();
- const ret = await fetch(connstring + '/'),
- data = await ret.text();
- console.log('data', data);
- assert.equal(ret.status, 200, 'root should work');
- }
- catch(e) {
- console.log('error in', assert.name, e);
- assert.fail(`error in ${assert.name}`);
- }
- assert.end();
- });
- tapetest.onFinish(async function cleanup() {
- server.kill();
- });
- function waitPro(n = 1000) {
- return new Promise(function pro(resolve, reject) {
- setTimeout(resolve, n);
- });
- }
|