Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[Testing] How to set up automated tests that execute outside of roll20 environment

1383108431

Edited 1383109101
John M.'s debugging post inspired me to post what I've been using for the past couple months. Here is a sample of how you can set up automated tests to execute your scripts outside of roll20. This assumes you are familiar with writing automated tests with mock objects. Creating automated tests is large topic beyond the scope of this post. I'm using the javascript test framework Jasmine <a href="http://pivotal.github.io/jasmine/" rel="nofollow">http://pivotal.github.io/jasmine/</a> version 1.3.0 (download here ) along with an extension jasmine-stealth <a href="https://github.com/searls/jasmine-stealth" rel="nofollow">https://github.com/searls/jasmine-stealth</a> version 0.0.12 First you'll need to acquire Jasmine and the extension mention jasmine-stealth. If you use underscore commands in you scripts you'll also need to get that at <a href="http://underscorejs.org/" rel="nofollow">http://underscorejs.org/</a> I'm using version 1.5.2. I'm not sure which version roll20 is actually using. Next you need to set up a html spec file. Example: <a href="https://github.com/davout1806/roll20/blob/master/SpecRunner.html" rel="nofollow">https://github.com/davout1806/roll20/blob/master/SpecRunner.html</a> My directory structure it might help you understand the relative directories in the HTML file project\main project\main\prod - where my scripts are located project\main\testing - where Roll20Mock is located project\tests - where test scripts and HTML spec files are located project\tests\lib - where jasmine and underscore files are located Then you'll need to set up your tests in javascript file(s). Example file (one of my test files): <a href="https://github.com/davout1806/roll20/blob/master/ConditionsTest.js" rel="nofollow">https://github.com/davout1806/roll20/blob/master/ConditionsTest.js</a> Finally, just load your html spec file in a browser and your tests will run. FWIW when I need to debug my code I use firebug, which allows breakpoints and inspection of variable values. If you have questions I'll try to answer as best I can. Please note I consider myself lower-intermediate level javascript developer. So if anyone has suggestions on improvement please feel free to drop a line. Contents of Roll20Mock.js Add function declarations as needed. <a href="https://github.com/davout1806/roll20/blob/master/Roll20Mock.js" rel="nofollow">https://github.com/davout1806/roll20/blob/master/Roll20Mock.js</a>
This is great stuff, Davout! Although the browser seems like the obvious choice for running JS, I've been avoiding it simply because I'm used to programming on the command line. I'm not exactly a JS noob, having used it in spurts over the past ~18 years (oh man, that hurts to type), but I've done little with it beyond some basic webdev until getting interested in Roll20. My day-to-day scripting needs are usually satisfied by Ruby, though not for webdev, and it just seems more natural to me to work in a console. It looks like Jasmine is perfectly compatible with Node, so I'll have to give that a try for some test-driven development. Node has a built in debugger, though its not nearly as user-friendly as firebug or web developer tools in the browser would be. Thanks for sharing your set up. I hope this inspires other R20 API script authors to share their offline tips and tricks!