Factor out some UTs code in test-utils.js