<commit_before>const assert = require('assert');
const divert = require('../');
const fs = require('fs');
const util = require('util');

if (!util.promisify) {
   require('util.promisify').shim();
}

describe('divert integrates with promises', () => {
   const doAsync = (x) => {
      setImmediate(() => {
         x(undefined, 'async value');
      });
   }

   it('divert returns promise which resolves with value of return statement', (done) => {
      divert(function* (sync) {
         yield doAsync(sync);
         return 'value';
      }).then((result) => {
         assert.equal('value', result, 'promise resolves to return value');
         done();
      });
   });

   it('divert returns promise which rejects with value of exception', (done) => {
      divert(function* (sync) {
         yield doAsync(sync);
         throw new Error('message');
      }).then(() => {
         assert.fail('divert promise is resolved instead been rejected');
      }).catch((err) => {
         assert.equal('message', err.message, 'promise is rejected with correct error information');<commit_msg>Run unit tests on Node 6.x environment<commit_after>const assert = require('assert');
const divert = require('../');
const fs = require('fs');
const util = require('util');
util.promisify = util.promisify || require('util.promisify').shim();

describe('divert integrates with promises', () => {
   const doAsync = (x) => {
      setImmediate(() => {
         x(undefined, 'async value');
      });
   }

   it('divert returns promise which resolves with value of return statement', (done) => {
      divert(function* (sync) {
         yield doAsync(sync);
         return 'value';
      }).then((result) => {
         assert.equal('value', result, 'promise resolves to return value');
         done();
      });
   });

   it('divert returns promise which rejects with value of exception', (done) => {
      divert(function* (sync) {
         yield doAsync(sync);
         throw new Error('message');
      }).then(() => {
         assert.fail('divert promise is resolved instead been rejected');
      }).catch((err) => {
         assert.equal('message', err.message, 'promise is rejected with correct error information');
{'fraction_non_alphanumeric': 0.16343115124153498, 'fraction_numerical': 0.0004514672686230248, 'mean_word_length': 2.92212389380531, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '4589329', 'n_tokens_mistral': 624, 'n_tokens_neox': 602, 'n_words': 179}