<commit_before>import CombatLogParser from 'Parser/Core/CombatLogParser';

class MyModule {}
const myModule = new MyModule();
class MySubModule extends MyModule {}
const mySubModule = new MySubModule();
class EmptyCombatLogParser extends CombatLogParser {
  static defaultModules = {};
  static specModules = {};
}

// This uses `_modules` on the CombatLogParser. I know I shouldn't test private properties! But using the modules property directly throws a deprecation warning for now, and this is probably only temporary. So this is only a temp fix. (lol who am I kidding)

describe('Core.CombatLogParser', () => {
  describe('module defining', () => {
    it('loads default modules', () => {
      class MyCombatLogParser extends EmptyCombatLogParser {
        static defaultModules = {
          myModule: MyModule,
        };
      }
      const parser = new MyCombatLogParser(null, null, null);
      expect(parser._modules.myModule).toBeInstanceOf(MyModule);
      expect(Object.keys(parser._modules).length).toBe(1);
    });
    it('loads spec modules', () => {
      class MyCombatLogParser extends EmptyCombatLogParser {
        static specModules = {
          myModule: MyModule,
        };
      }
      const parser = new MyCombatLogParser(null, null, null);
      expect(parser._modules.myModule).toBeInstanceOf(MyModule);
      expect(Object.keys(parser._modules).length).toBe(1);
    });
    it('spec modules override default modules', () => {
      class MyCombatLogParser extends EmptyCombatLogParser {
        static defaultModules = {
          myModule: MyModule,
        };
        static specModules = {
          myModule: MySubModule,
        };
      }
      const parser = new MyCombatLogParser(null, null, null);
      expect(parser._modules.myModule).toBeInstanceOf(MySubModule);
      expect(Object.keys(parser._modules).length).toBe(1);
    });
    it('only instantiates the overriding module', () => {
      const MyModule = jest.fn();
      const MySubModule = jest.fn();
      class MyCombatLogParser extends EmptyCombatLogParser {
        static defaultModules = {
          myModule: MyModule,
        };
        static specModules = {
          myModule: MySubModule,
        };
      }
      const parser = new MyCombatLogParser(null, null, null);
      expect(parser.error).toBeFalsy();
      expect(MyModule.mock.instances.length).toBe(0);
      expect(MySubModule.mock.instances.length).toBe(1);
    });
    it('allows spec modules to disable default modules', () => {
      class MyCombatLogParser extends EmptyCombatLogParser {
        static defaultModules = {
          myModule: MyModule,
        };
        static specModules = {
          myModule: null,
        };
      }
      const parser = new MyCombatLogParser(null, null, null);
      expect(parser._modules.myModule).toBe(undefined);
      expect(Object.keys(parser._modules).length).toBe(0);
    });
  });
  describe('findModule', () => {
    it('finds a module by type', () => {
      class MyCombatLogParser extends CombatLogParser {
        modules = {
          alternative: {},
          test: myModule,
          another: {},
          onemore: {},
        };
      }
      const parser = new MyCombatLogParser(null, null, null);
      expect(parser.findModule(MyModule)).toBe(parser._modules.test);
      expect(parser.findModule(MyModule)).toBeInstanceOf(MyModule);
      expect(parser.findModule(MyModule)).toBe(myModule);
    });
    it('finds a submodule even when looking for the parent module', () => {
      class MyCombatLogParser extends CombatLogParser {
        modules = {
          alternative: {},
          test: mySubModule,
          another: {},
          onemore: {},
        };
      }
      const parser = new MyCombatLogParser(null, null, null);
      expect(parser.findModule(MyModule)).toBe(parser._modules.test);
      expect(parser.findModule(MyModule)).toBeInstanceOf(MySubModule);
      expect(parser.findModule(MyModule)).toBe(mySubModule);
      expect(parser.findModule(MySubModule)).toBeInstanceOf(MySubModule);
      expect(parser.findModule(MySubModule)).toBe(mySubModule);
    });
    it('returns undefined is module doesn\'t exist', () => {
      class MyCombatLogParser extends CombatLogParser {
        modules = {
          onemore: {},
        };<commit_msg>Fix tests (why does this only fail in travis??)<commit_after>import CombatLogParser from 'Parser/Core/CombatLogParser';

class MyModule {}
const myModule = new MyModule();
class MySubModule extends MyModule {}
const mySubModule = new MySubModule();
class EmptyCombatLogParser extends CombatLogParser {
  static defaultModules = {};
  static specModules = {};
}

// This uses `_modules` on the CombatLogParser. I know I shouldn't test private properties! But using the modules property directly throws a deprecation warning for now, and this is probably only temporary. So this is only a temp fix. (lol who am I kidding)

describe('Core.CombatLogParser', () => {
  describe('module defining', () => {
    it('loads default modules', () => {
      class MyCombatLogParser extends EmptyCombatLogParser {
        static defaultModules = {
          myModule: MyModule,
        };
      }
      const parser = new MyCombatLogParser(null, null, null);
      expect(parser._modules.myModule).toBeInstanceOf(MyModule);
      expect(Object.keys(parser._modules).length).toBe(1);
    });
    it('loads spec modules', () => {
      class MyCombatLogParser extends EmptyCombatLogParser {
        static specModules = {
          myModule: MyModule,
        };
      }
      const parser = new MyCombatLogParser(null, null, null);
      expect(parser._modules.myModule).toBeInstanceOf(MyModule);
      expect(Object.keys(parser._modules).length).toBe(1);
    });
    it('spec modules override default modules', () => {
      class MyCombatLogParser extends EmptyCombatLogParser {
        static defaultModules = {
          myModule: MyModule,
        };
        static specModules = {
          myModule: MySubModule,
        };
      }
      const parser = new MyCombatLogParser(null, null, null);
      expect(parser._modules.myModule).toBeInstanceOf(MySubModule);
      expect(Object.keys(parser._modules).length).toBe(1);
    });
    it('only instantiates the overriding module', () => {
      const MyModule = jest.fn();
      const MySubModule = jest.fn();
      class MyCombatLogParser extends EmptyCombatLogParser {
        static defaultModules = {
          myModule: MyModule,
        };
        static specModules = {
          myModule: MySubModule,
        };
      }
      const parser = new MyCombatLogParser(null, null, null);
      expect(parser.error).toBeFalsy();
      expect(MyModule.mock.instances.length).toBe(0);
      expect(MySubModule.mock.instances.length).toBe(1);
    });
    it('allows spec modules to disable default modules', () => {
      class MyCombatLogParser extends EmptyCombatLogParser {
        static defaultModules = {
          myModule: MyModule,
        };
        static specModules = {
          myModule: null,
        };
      }
      const parser = new MyCombatLogParser(null, null, null);
      expect(parser._modules.myModule).toBe(undefined);
      expect(Object.keys(parser._modules).length).toBe(0);
    });
  });
  describe('findModule', () => {
    it('finds a module by type', () => {
      class MyCombatLogParser extends CombatLogParser {
        _modules = {
          alternative: {},
          test: myModule,
          another: {},
          onemore: {},
        };
      }
      const parser = new MyCombatLogParser(null, null, null);
      expect(parser.findModule(MyModule)).toBe(parser._modules.test);
      expect(parser.findModule(MyModule)).toBeInstanceOf(MyModule);
      expect(parser.findModule(MyModule)).toBe(myModule);
    });
    it('finds a submodule even when looking for the parent module', () => {
      class MyCombatLogParser extends CombatLogParser {
        _modules = {
          alternative: {},
          test: mySubModule,
          another: {},
          onemore: {},
        };
      }
      const parser = new MyCombatLogParser(null, null, null);
      expect(parser.findModule(MyModule)).toBe(parser._modules.test);
      expect(parser.findModule(MyModule)).toBeInstanceOf(MySubModule);
      expect(parser.findModule(MyModule)).toBe(mySubModule);
      expect(parser.findModule(MySubModule)).toBeInstanceOf(MySubModule);
      expect(parser.findModule(MySubModule)).toBe(mySubModule);
    });
    it('returns undefined is module doesn\'t exist', () => {
      class MyCombatLogParser extends CombatLogParser {
        _modules = {
          onemore: {},
        };
{'fraction_non_alphanumeric': 0.11684562983489205, 'fraction_numerical': 0.0013855213023900243, 'mean_word_length': 2.8412416851441242, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '5992102', 'n_tokens_mistral': 2400, 'n_tokens_neox': 2386, 'n_words': 532}