# couchdb-ddoc-test

> CouchDB Design Doc Testing Tool

Latest version **1.0.0** (published 2015-05-11) · Apache 2.0 License license · 0 weekly downloads

## Install

```sh
npm install couchdb-ddoc-test
pnpm add couchdb-ddoc-test
yarn add couchdb-ddoc-test
bun add couchdb-ddoc-test
```

## 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.0 |
| Published | 2015-05-11 |
| First published | 2015-05-11 |
| Weekly downloads | 0 |
| License | Apache 2.0 License |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Jan Lehnardt |
| Maintainers | jo |
| Keywords | couchdb, design doc, test |

## Links

- npm: https://www.npmjs.com/package/couchdb-ddoc-test
- Repository: https://github.com/eHealthAfrica/couchdb-ddoc-test
- Homepage: https://github.com/eHealthAfrica/couchdb-ddoc-test#readme
- Issues: https://github.com/eHealthAfrica/couchdb-ddoc-test/issues
- npm.io page: https://npm.io/package/couchdb-ddoc-test

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2015-05-11

## README

This is a simple CouchDB design doc testing tool.

Usage:

```javascript
var DDocTest = require('couchdb-ddoc-test');
var test = new DDocTest({
  fixture: {a: 1},
  src: 'path/to/map.js'
});
var result = test.runMap();

assert.equals(result, fixture);

```

### `require()`

CouchDB supports `require()` within design doc functions. It works slightly
different from `require()` in e.g. Node.js (in which these tests are run).
Instead of relying on CouchDB’s `require()` we will be using a couchapp
specific pre-processing directive. To make everything work, we have to
jump through a small hoop:

Say you want to `var foo = require('foo');` within a map function. Do this:

```javascript
function(doc) {
  // prepare for require
  var module = module || {};

  // This next line is a `couchapp` preprocessor line, that copy and pastes the
  // contents of `path/to/foo.js` into this function. It should define the
  // variable `foo`. That is how this code is run within CouchDB. !code
  // path/to/foo.js

  // This next line makes sure that we only run the Node.js `require()` when the
  // `!code` macro is not expanded. This is why !code path/to/foo.js should
  // create the `foo` variable. If it doesn’t exist, we run a regular Node.js
  // `require()`. With *one* caveat: since `map.js` will be run within `eval()`
  // in another module than your tests, we need to put the full module path into
  // `require()`, otherwise, the foo package would have to be a dependency of
  // the couchdb-ddoc-test package, which wouldn’t work out. Anyhoo!
  var foo = foo || require(process.cwd() + '/different/path/to/foo'
}
```

### Test

`npm test`

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