Refactor JS testing logic to be a bit cleaner.