Refactor JavaScript test code

Waiting for #54 before merging this.