<commit_before>import documentFormatter from 'src/logic/documentPackager/documentFormatter';
import base64OfSimplePdf from './reference/base64OfSimplePdf';

describe('DocumentFormatter', () => {
  it('should returns the same data for \'html viewMode\'', () => {
    const viewMode = 'html';
    const inputData = '<div>This is a HTML content</div>';
    const outputData = documentFormatter.format(inputData, viewMode);

    expect(outputData).to.equal('<div>This is a HTML content</div>');
  });

  it('should returns a pdfBlob for \'pages viewMode\'', () => {
    const expectedOutput = base64OfSimplePdf;
    const inputData = '<div>This is a HTML content</div>';

    const thatPromise = documentFormatter.getPdfBlob(inputData);

    thatPromise.then((outputData) => {
      // pdfJS does not give deterministic outputData
      // around 5 characters will always be different in the output
      // therefore, an approximation method to use content length for
      // testing is used.

      expect(outputData.length).to.equal(expectedOutput.length);
    });
  });
});<commit_msg>Fix documentFormatter to handle failed promise<commit_after>import documentFormatter from 'src/logic/documentPackager/documentFormatter';
import base64OfSimplePdf from './reference/base64OfSimplePdf';

describe('DocumentFormatter', () => {
  it('should returns the same data for \'html viewMode\'', () => {
    const viewMode = 'html';
    const inputData = '<div>This is a HTML content</div>';
    const outputData = documentFormatter.format(inputData, viewMode);

    expect(outputData).to.equal('<div>This is a HTML content</div>');
  });

  it('should returns a pdfBlob for \'pages viewMode\'', (done) => {
    const expectedOutput = base64OfSimplePdf;
    const inputData = '<div>This is a HTML content</div>';

    const thatPromise = documentFormatter.getPdfBlob(inputData);

    thatPromise.then((outputData) => {
      // pdfJS does not give deterministic outputData
      // around 5 characters will always be different in the output
      // therefore, an approximation method to use content length for
      // testing is used.

      expect(outputData.length).to.equal(expectedOutput.length);
      done();
    }).catch((error) => {
      done(error);
    });
  });
});
{'fraction_non_alphanumeric': 0.12742504409171077, 'fraction_numerical': 0.006172839506172839, 'mean_word_length': 3.8276595744680852, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 24, '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': '680728', 'n_tokens_mistral': 632, 'n_tokens_neox': 603, 'n_words': 181}