This is the 2nd post in a series of technical updates, focusing on the new testing suite for ARK Core v2, the challenges encountered, and a glimpse into the developmental process.

Test suites are an important part of any serious development environment, more so with blockchain technologies where each mistake can end up being very costly. Some would argue that test suites usurp unnecessary time, but in the long run it alleviates the headaches of small potential problems turning into big ones, and provides a means to easily spot mistakes and test your code. It is very important when writing code to focus on the long term vision and not be shortsighted. Spending extra time creating the necessary tools to help new developers quickly focus on innovation is far better time spent than finding and patching bugs. Good test cases can be much more valuable than final code as main code can be safely replaced/refactored when new technologies arise.

Development of Core v2 started with Mocha, the first testing suite (same as v1), however better options for our specific needs arose. The pros and cons of differing solutions were weighed, and in the end Jest was chosen over Mocha. There are many reasons why the dev team decided to adopt Jest.

With the growth of our team we are establishing a common base for developers, delivering the best possible tools (powerful mocking, snapshot testing, built-in code coverage, zero configuration) and making cross team collaboration smooth with testing appearing uniform across different sections of code.

Jest was developed and is used by Facebook to test all of their JavaScript code including React applications. Jest is also used by Airbnb, Twitter, Pinterest, Instagram, and Oculus.

One of Jest’s philosophies is to provide an integrated “zero-configuration” experience. Because ARK has access to use these tools, we were able to focus more on writing tests, resulting in a much more stable and healthy code base.

Migration from Mocha to Jest was a breeze because the Jest API and Mocha API are quite similar with only slight differences in function names. The major improvement being that Jest provides increased performance.

As stated by Airbnb:

“Airbnb migrated from Mocha to Jest. Running our test suite with Mocha took 12+ minutes. In CI with our beefy build machines (32 cores) we’re able to run the entire Jest suite in 4 minutes 30 seconds.”

Jest runs tests in parallel across workers for maximum performance. Giving you all the power of parallelization without any of the complexities that come with it. Console messages are buffered and printed together with test results. Sand boxed test files and automatic global states reset for every test, preventing two tests from conflicting with each other.

Examples

Starting Tests