Refactor tests a bit

Isolate tests into functions. This helps protect reordering, and makes looking at one test hopefully less daunting.
Try to make wrapper.js more readable