<commit_before>import * as fs from 'fs'
import { Unidirectional } from '../../../contracts/lib'
import ChannelContract from '../ChannelContract'
import IEngine from './IEngine'
import IExec from './IExec'
import Migrator from './Migrator'
import EnginePostgres from './postgresql/EnginePostgres'
import EngineSqlite from './sqlite/EngineSqlite'
import Storage from '../Storage'
import * as expect from 'expect'
import * as Web3 from 'web3'
import * as sinon from 'sinon'
import * as support from '../support'
import * as DBMigrate from 'db-migrate'

describe('Main', () => {
  let engine: IEngine & IExec<any>
  let dbmigrate: DBMigrate.DBMigrate
  let storage: Storage
  let web3: Web3
  let deployed: any
  let contractStub: sinon.SinonStub
  let channelContract: ChannelContract
  let runSqlAll: any

  function retrieveInFolderMigrationList (): Promise<string[]> {
    return new Promise(async (resolve) => {
      let result: string[] = []
      let pathToRead = `${__dirname}/../../migrations/${process.env.DB_URL!.split('://')[0]}`
      const listOfFiles: string[] = fs.readdirSync(pathToRead)
      for (let filename of listOfFiles) {
        let pathToStat = `${__dirname}/../../migrations/${process.env.DB_URL!.split('://')[0]}/${filename}`
        const isDir = fs.statSync(pathToStat).isDirectory()
        if (!isDir) {
          result.push(filename.slice(0, -3))
        }
      }
      result.sort()
      return resolve(result)
    })
  }

  function retrieveUpMigrationList (): Promise<string[]> {
    return new Promise((resolve) => {
      // tslint:disable-next-line:no-floating-promises
      engine.exec((client: any) => {
        return runSqlAll('SELECT name FROM migrations ORDER BY name ASC')
      }).then((res: any) => {
        switch (process.env.DB_URL!.split('://')[0]) {
          case 'postgresql': {
            res = res.rows
            break
          }
        }
        const names: string[] = res.map((element: any) => element['name'])
        let result: string[] = []
        for (let migrationName of names) {
          result.push(migrationName.substring(1))
        }
        return resolve(result)
      })
    })
  }

  beforeEach(async () => {
    return new Promise(async (resolve) => {
      web3 = {
        currentProvider: {}
      } as Web3
<commit_msg>Move function retrieveInFolderMigrationList out of test. Remove not needed Promise constructors.<commit_after>import * as fs from 'fs'
import { Unidirectional } from '../../../contracts/lib'
import ChannelContract from '../ChannelContract'
import IEngine from './IEngine'
import IExec from './IExec'
import Migrator from './Migrator'
import EnginePostgres from './postgresql/EnginePostgres'
import EngineSqlite from './sqlite/EngineSqlite'
import Storage from '../Storage'
import * as expect from 'expect'
import * as Web3 from 'web3'
import * as sinon from 'sinon'
import * as support from '../support'
import * as DBMigrate from 'db-migrate'

async function retrieveInFolderMigrationList (): Promise<string[]> {
  let result: string[] = []
  let pathToRead = `${__dirname}/../../migrations/${process.env.DB_URL!.split('://')[0]}`
  const listOfFiles: string[] = fs.readdirSync(pathToRead)
  for (let filename of listOfFiles) {
    let pathToStat = `${__dirname}/../../migrations/${process.env.DB_URL!.split('://')[0]}/${filename}`
    const isDir = fs.statSync(pathToStat).isDirectory()
    if (!isDir) {
      result.push(filename.slice(0, -3))
    }
  }
  result.sort()
  return result
}

describe('Main', () => {
  let engine: IEngine & IExec<any>
  let dbmigrate: DBMigrate.DBMigrate
  let storage: Storage
  let web3: Web3
  let deployed: any
  let contractStub: sinon.SinonStub
  let channelContract: ChannelContract
  let runSqlAll: any

  function retrieveUpMigrationList (): Promise<string[]> {
    // tslint:disable-next-line:no-floating-promises
    return engine.exec((client: any) => {
      return runSqlAll('SELECT name FROM migrations ORDER BY name ASC')
    }).then((res: any) => {
      switch (process.env.DB_URL!.split('://')[0]) {
        case 'postgresql': {
          res = res.rows
          break
        }
      }
      const names: string[] = res.map((element: any) => element['name'])
      let result: string[] = []
      for (let migrationName of names) {
        result.push(migrationName.substring(1))
      }
      return result
    })
  }

  beforeEach(async () => {
    return new Promise(async (resolve) => {
      web3 = {
        currentProvider: {}
      } as Web3

{'fraction_non_alphanumeric': 0.1470327723649247, 'fraction_numerical': 0.005314437555358724, 'mean_word_length': 2.9832451499118164, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, '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': '1782029', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1392, 'n_words': 357}