# happn-tests

> test templates for happn

Latest version **1.0.3** (published 2016-08-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install happn-tests
pnpm add happn-tests
yarn add happn-tests
bun add happn-tests
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2016-08-24 |
| First published | 2016-02-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 18 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | smc-tenacious |

## Links

- npm: https://www.npmjs.com/package/happn-tests
- Repository: https://github.com/happner/happn-tests
- Homepage: https://github.com/happner/happn-tests#readme
- Issues: https://github.com/happner/happn-tests/issues
- npm.io page: https://npm.io/package/happn-tests

## Dependencies (18)

- [chai](https://npm.io/package/chai.md) ^3.2.0
- [gulp](https://npm.io/package/gulp.md) ^3.9.0
- [async](https://npm.io/package/async.md) ^1.5.2
- [happn](https://npm.io/package/happn.md) *
- [mocha](https://npm.io/package/mocha.md) *
- [byline](https://npm.io/package/byline.md) ^4.2.1
- [request](https://npm.io/package/request.md) ^2.69.0
- [shortid](https://npm.io/package/shortid.md) ^2.2.4
- [fs-extra](https://npm.io/package/fs-extra.md) ^0.26.5
- [istanbul](https://npm.io/package/istanbul.md) ^0.4.1
- [commander](https://npm.io/package/commander.md) ^2.9.0
- [coveralls](https://npm.io/package/coveralls.md) ^2.11.6
- [expect.js](https://npm.io/package/expect.js.md) *
- [benchmarket](https://npm.io/package/benchmarket.md) *
- [bitcore-lib](https://npm.io/package/bitcore-lib.md) 0.13.17
- [happn-logger](https://npm.io/package/happn-logger.md) 0.0.2
- [happn-util-crypto](https://npm.io/package/happn-util-crypto.md) 0.1.1
- [happn-random-activity-generator](https://npm.io/package/happn-random-activity-generator.md) *

## Recent versions

- 1.0.3 (latest) — 2016-08-24
- 1.0.2 — 2016-08-24
- 1.0.1 — 2016-08-24
- 1.0.0 — 2016-08-23
- 0.1.0 — 2016-03-07
- 0.0.8 — 2016-03-02
- 0.0.7 — 2016-03-02
- 0.0.6 — 2016-03-01
- 0.0.5 — 2016-03-01
- 0.0.4 — 2016-03-01
- 0.0.3 — 2016-03-01
- 0.0.2 — 2016-03-01
- 0.0.1 — 2016-02-29

## README

[![npm](https://img.shields.io/npm/v/happn-tests.svg)](https://www.npmjs.com/package/happn-tests) [![Build Status](https://travis-ci.org/happner/happn-tests.svg?branch=master)](https://travis-ci.org/happner/happn-tests) [![Coverage Status](https://coveralls.io/repos/happner/happn-tests/badge.svg?branch=master&service=github)](https://coveralls.io/github/happner/happn-tests?branch=master) [![David](https://img.shields.io/david/happner/happn-tests.svg)]()

<img src="https://raw.githubusercontent.com/happner/happner-website/master/images/HAPPN%20Logo%20B.png" width="300"></img>

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:
----------------

```bash
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:
--------------

```javascript

//this is specific to the project you are testing - this code is borrowed from the mongo plugin for happn
TEST_GLOBALS = {};

var service = require('../tests.js');
var serviceInstance = new service();

var config = {
	url:'mongodb://127.0.0.1:27017/happn'
}

serviceInstance.initialize(config, function(e){

	if (e) throw e;

	TEST_GLOBALS.mongoService = serviceInstance;

	//we have initialised some global objects, now time to run our test:

	var happn_tests = require('happn-tests').instantiate(__dirname + '/context');//the __dirname + context - is where our test context files will be found, this can be left blank if your context file is in [app root]/test/context

	//we run the tests - the contexts are iterated through and injected into our tests, the tests are designed to pick up contexts that have filenames that start with the filenames of the tests (without extensions), so the context 01-vanilla_test.js matches the 01-vanilla.js test

	happn_tests.run(function(e){
		if (e) {
			console.log('tests ran with failures', e);
			process.exit(1);
		}
		else{
			console.log('tests passed ok');
			process.exit(0);
		}
	});

});

```

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:*

```javascript

var happn = require('happn')
var happn_client = happn.client;

module.exports = {
  //the test needs a required happn module
  happnDependancy:require('happn'),
  //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
  publisherClient:function(happnInstance, callback){

    var config =  {
		plugin: happn.client_plugins.intra_process,
		context: happnInstance
	}

	happn_client.create(config, callback);
  },
  //this specific test needs a happn client in a specific configuration - in this case in EventEmitter mode
  listenerClient:function(happnInstance, callback){

  	var config =  {
		plugin: happn.client_plugins.intra_process,
		context: happnInstance
	}

	happn_client.create(config, callback);
  }
}

```

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:

```bash
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: *

```json

{
  "name": "happn-tests",
  "description": "service plugin for running happn on a mongo database",
  "version": "0.0.3",
  "main": "./lib/index",
  "scripts": {
    "test": "mocha silence.js test/functional && node test/happn-test",
    "test-cover": "istanbul cover _mocha -- silence.js test"
  },

```

this was again borrowed from the [happn mongo service's](https://github.com/happner/happn-tests) package.json.

---
_Source: https://npm.io/package/happn-tests · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
