Port the "test" lib to CommonJS style

This ports the whole `test` lib to CommonJS style.