service.js 797 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import {fork} from 'child_process';
  2. import tape from 'tape';
  3. import _test from 'tape-promise';
  4. import fetch from 'isomorphic-fetch';
  5. const tapetest = _test(tape);
  6. const server = fork('build/service.js'),
  7. connstring = 'http://localhost:8728';
  8. tapetest('service', async function testService(assert) {
  9. try {
  10. await waitPro();
  11. const ret = await fetch(connstring + '/'),
  12. data = await ret.text();
  13. console.log('data', data);
  14. }
  15. catch(e) {
  16. console.log('error somewhere', e);
  17. assert.fail('error somewhere');
  18. }
  19. assert.end();
  20. });
  21. tapetest.onFinish(async function cleanup() {
  22. server.kill();
  23. });
  24. function waitPro(n = 1000) {
  25. return new Promise(function pro(resolve, reject) {
  26. setTimeout(resolve, n);
  27. });
  28. }