Scenario Testing Setup

constructor(instancesArray, conductorOptions) => Scenario

Instantiate a Scenario with an array of instance configurations and some optional configuration overrides. Note that this function has the same signature as Config.conductor.


Name instancesArray

Type array

Description Pass in an array of instance configuration objects generated by Config.instance to have them within the final configuration to be instantiated by the Conductor


Name conductorOptions Optional

Type object

Description conductorOptions.debugLog boolean Which logger type to use. There are two options:

  • debugLog = true: Use the "debug" logger. This one has nicer, colorful output.
  • debugLog = false: Use the "simple" logger. This one has less interesting output, but can be silenced with the env variable HC_SIMPLE_LOGGER_MUTE=1

Default { debugLog: true }


Example

const dna = Config.dna("path/to/happ.hcpkg")
const instanceAlice = Config.instance(Config.agent("alice"), dna)
const instanceBob = Config.instance(Config.agent("bob"), dna)
const scenario = new Scenario([instanceAlice])

With Config Example

const dna = Config.dna("path/to/happ.hcpkg")
const instanceAlice = Config.instance(Config.agent("alice"), dna)
const instanceBob = Config.instance(Config.agent("bob"), dna)
const scenario = new Scenario([instanceAlice], { debugLog: false })

Inject Tape Version

Scenario.setTape(tape) => null

setTape should be called prior to usage of the Scenario class, if you intend to use tape as your testing framework. It sets a reference internally to the version of tape, since there are many variations, that you wish to use. It is used in conjunction with Scenario.runTape.


Name tape

Type object

Description A reference to the imported tape package you wish to use as your test framework.


Example

const { Config, Scenario } = require('@holochain/holochain-nodejs')

Scenario.setTape(require('tape'))

Full Multiple Instances Example

The following example shows the simplest, most convenient way to start writing scenario tests with this module. We'll set up an environment for running tests against two instances of one DNA, using the tape test harness:

const { Config, Scenario } = require('@holochain/holochain-nodejs')

Scenario.setTape(require('tape'))

// specify two agents...
const agentAlice = Config.agent("alice")
const agentBob = Config.agent("bob")
// ...and one DNA...
const dna = Config.dna("path/to/happ.hcpkg")
// ...then make instances out of them...
const instanceAlice = Config.instance(agentAlice, dna)
const instanceBob = Config.instance(agentBob, dna)

// Now we can construct a `scenario` object which lets us run as many scenario tests as we want involving the two instances we set up:
const scenario = new Scenario([instanceAlice, instanceBob])

suggest an edit