happn tests
we have a standard test that we inject a bunch of different contexts through, so if you happn to build a plugin for happn - you would use this test suite to ensure your code is up to standard.
getting started:
npm install happn-tests
the create a tests directory, in that directory create a "happn_test.js" file and a "context" folder - the happn_test.js file sets up the happn-tests suite and call's its run method, in the example below, a TEST_GLOBALS object is also created, so that contexts are able to use properties on the TEST_GLOBALS later:
happn_test.js:
//this is specific to the project you are testing - this code is borrowed from the mongo plugin for happnTEST_GLOBALS = {}; var service = ;var serviceInstance = ; var config = url:'mongodb://127.0.0.1:27017/happn' serviceInstance;
contexts
the contexts are little modules that supply the tests with configurations that are being tested against, here is an example context file for the 01-vanilla test:
var happn = var happn_client = happnclient; moduleexports = //the test needs a required happn module happnDependancy: //some additional information if you want - just used to console.log out description:"eventemitter embedded functional tests" //the happn service configuration - we are going for default vanilla here serviceConfig:{} //this specific test needs a happn client in a specific configuration - in this case in EventEmitter mode { var config = plugin: happnclient_pluginsintra_process context: happnInstance happn_client; } //this specific test needs a happn client in a specific configuration - in this case in EventEmitter mode { var config = plugin: happnclient_pluginsintra_process context: happnInstance happn_client; }
you save your context file as 01-vanilla-[my context name].js in the context folder. you are now A for away and can test, using node like so:
node run
*NB: if you are already running mocha tests, it is fine to locate your happn_test file elsewhere - so you dont get instances where the tests are automatically run causing issues, you can also update your package.json to run mocha tests and then the happn_test file, as follows: *
this was again borrowed from the happn mongo service's package.json.