<commit_before><commit_msg>test(mkdirTree): add test cases for mkdirTree<commit_after>import { expect } from 'chai';
import { FS } from '../../src/HunspellAsmModule';
//tslint:disable-next-line:no-require-imports
import mkdirTreeType = require('../../src/mkdirTree');

describe('mkdirTree', () => {
  let mkdirTree: typeof mkdirTreeType.mkdirTree;
  let fsMock: FS;
  let mkdirMock: jest.Mock<any>;

  beforeEach(() => {
    //tslint:disable-next-line:no-require-imports
    mkdirTree = require('../../src/mkdirTree').mkdirTree;
    mkdirMock = jest.fn();
    fsMock = {
      mkdir: mkdirMock
    } as any;
  });

  it('should create single dir', () => {
    mkdirTree(fsMock as any, '/virtual/');

    expect(mkdirMock.mock.calls).to.have.lengthOf(1);
    expect(mkdirMock.mock.calls[0][0]).to.equal('/virtual');
  });

  it('should recursively create nested dir', () => {
    mkdirTree(fsMock as any, '/virtual/test/dir');

    expect(mkdirMock.mock.calls).to.have.lengthOf(3);
    expect(mkdirMock.mock.calls).to.deep.equal([['/virtual'], ['/virtual/test'], ['/virtual/test/dir']]);
  });

  it('should not throw if try to create existing dir', () => {
    mkdirMock.mockImplementationOnce(() => {
      const e = new Error();
      (e as any).errno = 17;
      throw e;
    });

    expect(() => mkdirTree(fsMock as any, '/virtual/')).to.not.throw();
  });

  it('should throw if error occurred while creating dir', () => {
    mkdirMock.mockImplementationOnce(() => {
      throw new Error();
    });

    expect(() => mkdirTree(fsMock as any, '/virtual/')).to.throw();
  });
});
{'fraction_non_alphanumeric': 0.1974763406940063, 'fraction_numerical': 0.0037854889589905363, 'mean_word_length': 3.3933518005540164, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 14, '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': '5983383', 'n_tokens_mistral': 541, 'n_tokens_neox': 517, 'n_words': 104}