added isDefined method
made tests more robust and added NPM script