<commit_before>import 'mocha'; // tslint:disable-line
import Service from '../../serviceFactory/Service';

const migrateService = async (service: Service) => {
  await service.rollback();
  await service.migrate();
};

export default <ConcreteService extends Service>(service: ConcreteService) => {
  const migrations = migrateService(service);

  return (): ConcreteService => {
    before(async () => {
      await migrations;
    });

    beforeEach(async () => {
      await service.clearService();
    });

    return service;
  };
};
<commit_msg>fix(mocha): Ensures that the migrations only run when required.<commit_after>import { once } from 'lodash';
import 'mocha'; // tslint:disable-line
import Service from '../../serviceFactory/Service';

export default <ConcreteService extends Service>(service: ConcreteService) => {
  const migrateService = once(async () => {
    await service.rollback();
    await service.migrate();
  });

  return (): ConcreteService => {
    before(async () => {
      await migrateService();
    });

    beforeEach(async () => {
      await service.clearService();
    });

    return service;
  };
};

{'fraction_non_alphanumeric': 0.15236427320490367, 'fraction_numerical': 0.0, 'mean_word_length': 3.6088709677419355, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '4128949', 'n_tokens_mistral': 327, 'n_tokens_neox': 326, 'n_words': 77}