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
Enables debug logging. The logger produces nice, colorful output of the internal workings of Holochain.
Default { debugLog: false }
Example¶
const dna = Config.dna("path/to/happ.dna.json") const instanceAlice = Config.instance(Config.agent("alice"), dna) const instanceBob = Config.instance(Config.agent("bob"), dna) const scenario = new Scenario([instanceAlice])
With conductorOptions Example¶
const dna = Config.dna("path/to/happ.dna.json") const instanceAlice = Config.instance(Config.agent("alice"), dna) const instanceBob = Config.instance(Config.agent("bob"), dna) const scenario = new Scenario([instanceAlice], { debugLog: true })
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.dna.json") // ...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])