<commit_before>import {defer} from 'q';
import {createServer} from 'restify';
import registerResources from '../src/register';
import {spyOnServer, stopSpyingOnServer} from './serverSpying';

export default async (resource) => {
  const server = await startServer(resource);
  return {
    server,
    async stop() {
      stopSpyingOnServer(server);
      const deferred = defer();
      server.close(() => {
        deferred.resolve();
      });
      return deferred.promise;
    }
  };
};

async function startServer(resource) {
  const server = createServer();

  spyOnServer(server);

  registerResources(server, [resource]);

  const deferred = defer();
  server.listen(8880, () => {
    deferred.resolve(server);
  });

  return deferred.promise;
}<commit_msg>Add body parser to test server<commit_after>import {defer} from 'q';
import {createServer, bodyParser} from 'restify';
import registerResources from '../src/register';
import {spyOnServer, stopSpyingOnServer} from './serverSpying';

export default async (resource) => {
  const server = await startServer(resource);
  return {
    server,
    async stop() {
      stopSpyingOnServer(server);
      const deferred = defer();
      server.close(() => {
        deferred.resolve();
      });
      return deferred.promise;
    }
  };
};

async function startServer(resource) {
  const server = createServer();

  server.use(bodyParser());

  spyOnServer(server);

  registerResources(server, [resource]);

  const deferred = defer();
  server.listen(8880, () => {
    deferred.resolve(server);
  });

  return deferred.promise;
}
{'fraction_non_alphanumeric': 0.1398996235884567, 'fraction_numerical': 0.005018820577164366, 'mean_word_length': 3.6911764705882355, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '324145', 'n_tokens_mistral': 489, 'n_tokens_neox': 458, 'n_words': 113}