jasmine-flow
Flow testing for Jasmine.
Usage
;
Why?
So you are writing automated tests, ensuring that your edge cases are covered and the test suite is running fast, like under 5 seconds. Things are humming along smoothly. Your progress in adding features and business logic is accelerating and everybody is happy. But then there is this one feature with tons of edge cases that needs to be added. Before you know it, the test suite takes 30 seconds to run. It would be great to get the test suite back down to a more reasonable time, however the project needs to move forward and features need to get done.
Using the traditional setup and teardown structure and one expectation per example, one can notice repetition of the setup for each test case.
;
Assuming the assertion time is negligible compared to the setup, the result is the test suite increases with n log n, where n is the context setup to the expectations. The deeper the context, the more logic needed to create the context, in a n log n fashion.
jasmine-flow is a library which reduces the context setup duplication by restructuring the tests into a linear flow. This, of course reduces the time needed to execute the test suite, without needing to parallelize the tests.
The above example would look like:
In this case, the /login page is loaded only once and the invalid as well as the valid login cases are tested. The number of test cases is reduced from 5 to 1 and the repeating execution of loading the /login page is avoided. Since less tests are run and less unnecessary context setup is executed, the test suite can have dramatic performance gains. On one of my projects, I have seen nearly a 10x gain of performance (~ 400 seconds to 40 seconds), without having to resort to parallelization.
Useful Methods
info
info will log to console.info. This is useful when you need to log a particular step.
stop
Stop the test immediately. This is useful in cutting out log message noise, when the test is very long and fails in an intermediate section.