improve promise handling, rewrite tests using writeTest method
change writeTest to defineTest, add mocha test for `defineTest`