All files / src/tests/integrationTests build.js

100% Statements 37/37
50% Branches 1/2
100% Functions 2/2
100% Lines 37/37
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 861x 1x 1x 1x   1x 1x   1x 1x 1x 1x       1x 1x             1x   1x   1x 1x   1x     1x         1x   1x   1x 1x 1x 2x       2x   2x           1x   1x         1x   1x 1x   1x           1x     1x   1x 1x     1x  
const assert = require('assert')
const fs = require('fs-extra')
const path = require('path')
const interbit = require('../../')
 
const prepareTestLocation = require('./prepareTestLocation')
const log = require('../../log')
 
const testBuild = async () => {
  const dbCleanup = async dbPath => {
    Eif (dbPath) {
      await fs.remove(dbPath)
    }
  }
 
  const { location, cleanup } = prepareTestLocation('build')
  const options = {
    // eslint-disable-next-line
    config: require('./interbit.config'),
    artifacts: path.join(location, 'dist'),
    dbPath: `./db-${Date.now()}`
  }
 
  await interbit.build(options)
 
  log.info('Done building...')
 
  const isBuildComplete = await fs.exists(options.artifacts)
  assert.ok(isBuildComplete, 'Build dir does not exist')
 
  log.success('Build was build in correct location')
 
  // eslint-disable-next-line
  const manifest = require(path.join(
    process.cwd(),
    options.artifacts,
    'interbit.manifest.json'
  ))
  log.info(manifest)
 
  assert.deepStrictEqual(manifest.peers, options.config.peers)
 
  const configuredCovenants = Object.keys(options.config.covenants)
  const builtCovenants = Object.keys(manifest.covenants)
  for (const covenantAlias of builtCovenants) {
    const covenantFilename = path.join(
      options.artifacts,
      manifest.covenants[covenantAlias].filename
    )
    const doesCovenantExist = await fs.exists(covenantFilename)
 
    assert.ok(
      doesCovenantExist,
      `${covenantAlias} was not packed at specified filepath`
    )
  }
 
  log.success('Covenants were packed in manifest locations')
 
  assert.deepStrictEqual(builtCovenants, [
    ...configuredCovenants,
    'interbitRoot'
  ])
 
  log.success('All configured covenants and root were packed')
 
  const configuredChains = Object.keys(options.config.staticChains)
  const builtChains = Object.keys(manifest.manifest.interbitRoot.chains)
 
  assert.deepStrictEqual(
    builtChains,
    configuredChains,
    'Chains in manifest were not correctly configured'
  )
 
  log.success(
    'All configured chains were added to manifest as children of the root'
  )
  log.success('Build was successful')
 
  cleanup()
  dbCleanup(options.dbPath)
}
 
module.exports = testBuild