When you ran hc init in the previous tutorial, Holochain generated some tests for you.

The tests are written in JavaScript and use the Holochain testing framework Tryorama, along with a popular test harness called Tape. You can run them with Node.JS, a runtime that lets you execute JavaScript in the terminal.

Open up the cc_tuts/test/index.js in your favorite text editor. Have a look through the code.

Imports required to do testing:

/// NB: The tryorama config patterns are still not quite stabilized./// See the tryorama README [https://github.com/holochain/tryorama]/// for a potentially more accurate exampleconstpath=require('path');const{Orchestrator,Config,combine,singleConductor,localOnly,tapeExecutor,}=require('@holochain/tryorama');

This is a catch-all error logger that will let you know if a Promise fails and there’s no error handler to hear it. Promises are a way of simplifying complex asynchronous code, and Tryorama uses a lot of them.

process.on('unhandledRejection',error=>{// Will print "unhandledRejection err is not defined"console.error('got unhandledRejection:',error);});

The path to your compiled DNA:

constdnaPath=path.join(__dirname,'../dist/cc_tuts.dna.json');

Set up a testing scenario.
This creates two agents: Alice and Bob.

constorchestrator=newOrchestrator({middleware:combine(// use the tape harness to run the tests, injects the tape API into each scenario// as the second argumenttapeExecutor(require('tape')),// specify that all "players" in the test are on the local machine, rather than// on remote machineslocalOnly,// squash all instances from all conductors down into a single conductor,// for in-memory testing purposes.// Remove this middleware for other "real" network types which can actually// send messages across conductorssingleConductor,),});constdna=Config.dna(dnaPath,'scaffold-test');constconductorConfig=Config.gen({myInstanceName:dna});

Remove the singleConductor as we are doing real testing with a network:

const orchestrator = new Orchestrator({
middleware: combine(
// use the tape harness to run the tests, injects the tape API into each scenario
// as the second argument
tapeExecutor(require('tape')),
// specify that all "players" in the test are on the local machine, rather than
// on remote machines
localOnly,
-- // squash all instances from all conductors down into a single conductor,- // for in-memory testing purposes.- // Remove this middleware for other "real" network types which can actually- // send messages across conductors- singleConductor,
),
});

- singleConductor,

Throughout this series we are using sim2h as our networking because this will be the most useful setup to most developers.
Add the sim2h networking to the test and update the config to use the correct names for this tutorial series:

You will need to run the sim2h server locally before you can run the tests.
This is the switchboard that does the routing, and will eventually be unneccassary, but is currently useful for development.
To run the server, open up a new nix-shell in a different terminal and run this command:

/// NB: The tryorama config patterns are still not quite stabilized./// See the tryorama README [https://github.com/holochain/tryorama]/// for a potentially more accurate exampleconstpath=require('path');const{Orchestrator,Config,combine,localOnly,tapeExecutor,}=require('@holochain/tryorama');process.on('unhandledRejection',error=>{// Will print "unhandledRejection err is not defined"console.error('got unhandledRejection:',error);});constdnaPath=path.join(__dirname,'../dist/cc_tuts.dna.json');constorchestrator=newOrchestrator({middleware:combine(// use the tape harness to run the tests, injects the tape API into each scenario// as the second argumenttapeExecutor(require('tape')),// specify that all "players" in the test are on the local machine, rather than// on remote machineslocalOnly,),});constdna=Config.dna(dnaPath,'cc_tuts');constconfig=Config.gen({cc_tuts:dna,},{network:{type:'sim2h',sim2h_url:'ws://localhost:9000',},},);orchestrator.registerScenario('Test hello holo',async(s,t)=>{const{alice,bob}=awaits.players({alice:config,bob:config},true);constresult=awaitalice.call('cc_tuts','hello','hello_holo',{});t.ok(result.Ok);t.deepEqual(result,{Ok:'Hello Holo'});});orchestrator.run();

Now, in the cc_tuts directory, run the test like this:

Run in nix-shell https://holochain.love

$ hc test

This will compile and run the test scenario you just wrote. You will see a lot of output.

If everything went okay, then right at the end you will see:

# tests 2
# pass 2
# ok

Congratulations! You have tested your first Holochain app. Look at you go!