Good testing practises with Undum?

Being in the throes of developing a game from Undum (A project that started on Twine 2, did a random walk through the various choice game systems including “I’ll just implement my own”, and ended up on Undum), I’m running into the issue that Undum doesn’t seem to have any testing functionality built into it. In Twine, you can jump to a passage to test it immediately; in Undum, I don’t think any of that is available. So, if you’ve developed a game of any significant size in Undum: How do you build good testing systems/practises to make sure you’re not breaking one of the many branches? Do you just periodically walk the whole tree by hand in an end-to-end test?

There are no built-in testing features but they’re not that hard to make. You can change the starting situation simply by changing the value of undum.game.start, or if you want to get fancy you can add a feature that lets you jump around manually in the story itself. Add this somewhere to the main HTML (either of the sidebars should work well):

<form id="debug-go">
    <input type="text">
    <button type="submit">Go</button>
</form>

Then add this inside the undum.game.init function:

$('#debug-go').on('submit', function(e) {
    e.preventDefault();
    system.doLink( $(this).find('input').val() );
});

Now you can type the situation’s name to the input field and click “go” to get there instantly.

For testing scripts you could do something like this. Add buttons like this to the HTML file:

<button type="button" class="debug-replay" data-sequence="foobar">Test "foobar"</button>

…and the following again to the undum.game.init function:

var replaySequences = {
    'foobar': [ 'all', 'your', 'situations', 'here', 'one', 'per', 'array', 'element' ],
    'barfoo': [ 'contents', 'of', another', 'test', 'script' ]  // and so on
};

$('.debug-replay').on('click', function(e) {
    e.preventDefault();
    var sequence = replaySequences[ $(this).data('sequence') ];
    
    for( var i = 0; i < sequence.length; ++i ) {
        system.doLink( sequence[ i ] );
    }
});

The data-sequence attribute should of course match the name of the testing sequence.

My impression is that walking through the whole tree is generally just not done; in anything more complex than a strictly tree-like structure that never rejoins paths the combinatorial explosion makes it quickly impossible, and in a strictly branching structure the risk of breaking something while tinkering with something else is much lower. If you want to write regression tests it’s better to identify some key points and target them specifically.

That’s helpful, thank you. What are some things in Undum that you found tend to be problematic/cause issues?

Well, it’s such a loose framework that it doesn’t really have much room for problems of its own outside JavaScript.

True, though as we know that’s already more than enough room for problems.