# npm-test-helpers

> Useful shared test helpers for writing apps that interact with npm.

Latest version **0.0.4** (published 2014-07-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install npm-test-helpers
pnpm add npm-test-helpers
yarn add npm-test-helpers
bun add npm-test-helpers
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2014-07-18 |
| First published | 2014-06-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+12 in 3 direct dependencies) |
| Install scripts | no |
| Author | Benjamin Coe |
| Maintainers | bcoe |

## Links

- npm: https://www.npmjs.com/package/npm-test-helpers
- Repository: https://github.com/npm/npm-test-helpers
- Issues: https://github.com/npm/npm-test-helpers/issues
- npm.io page: https://npm.io/package/npm-test-helpers

## Dependencies (5)

- [npm](https://npm.io/package/npm.md) ^1.4.21
- [lodash](https://npm.io/package/lodash.md) ^2.4.1
- [restify](https://npm.io/package/restify.md) ^2.8.1
- [bluebird](https://npm.io/package/bluebird.md) ^2.0.2
- [npm-registry-couchapp](https://npm.io/package/npm-registry-couchapp.md) ^2.2.0

## Recent versions

- 0.0.4 (latest) — 2014-07-18
- 0.0.3 — 2014-06-10
- 0.0.2 — 2014-06-09
- 0.0.1 — 2014-06-09
- 0.0.0 — 2014-06-09

## README

# npm-test-helpers

Useful shared test helpers for writing apps that interact with npm.

## Registry-Couch-App Integration Testing

It can be useful to test against a fully-functional Registry-Couch-App.
*npm-test-helpers* provides a useful set of helpers for doing this.

**setting up your local environment**

1. Edit your `local.ini` to have the settings outlined in https://github.com/npm/npm-registry-couchapp.
2. Create a `test-config.json` that has appropriate settings for your CouchDB configuration:

```json
{
  "testRegistryName": "npm-test-registry",
  "host": "localhost",
  "port": 5984,
  "scheme": "http",
  "cache": "/tmp",
  "couchUser": "admin",
  "couchPass": "admin",
  "populateDesign": true
}
```

**initializing a testing registry**

```javascript
Couch = require('../lib').Couch;

couch.setup().then(function() {
  // a registry is now available with the
  // design documents populated.
});
```

**tearing down the testing registry**

```javascript
var Couch = require('npm-test-helpers').Couch;

couch.teardown().then(function() {
  // the testing registry has been destroyed.
});
```

**publishing a package**

1. make sure that you have an npm user available locally (*npm-test-helpers* simply executes npm).
2. create a testing registry.
3. for testing purposes, the following packages are available:
  * **request@1.9.0**
  * **request@2.36.0**
  * **tap@0.3.0**
  * **thumbd@2.7.0**
  * **thumbd@2.8.1**

```javascript
var Couch = require('npm-test-helpers').Couch,
 Registry = require('npm-test-helpers').Registry;

couch.setup().then(function() {
  var registry = new Registry();
  registry.publish('request@2.36.0').then(function(stdout) {
    // the package is now published.
  });
});
```

**unpublish a package**

```javascript
var Couch = require('npm-test-helpers').Couch,
 Registry = require('npm-test-helpers').Registry;

couch.setup().then(function() {
  var registry = new Registry();
  registry.publish('request@2.36.0').then(function(stdout) {
    return registry.unpublish('request');
  }).then(function(stdout) {
    // the package was unpublished.
  });
});
```

**delete a package**

```javascript
var Couch = require('npm-test-helpers').Couch,
 Registry = require('npm-test-helpers').Registry;

couch.setup().then(function() {
  var registry = new Registry();
  registry.publish('request@2.36.0').then(function(stdout) {
    return registry.delete('request');
  }).then(function(stdout) {
    // the package was unpublished.
  });
});
```

**testing a follower feed**

We use followers all over the place, for different pieces of npm's architecture,
*npm-test-helpers* makes it easy to perform inegration tests on followers.

*listening for a publication event*

```javascript
var Couch = require('npm-test-helpers').Couch,
 Registry = require('npm-test-helpers').Registry;

couch.setup().then(function() {

  var feed = follow({
    db: url + '/' + config.testRegistryName,
    include_docs: true,
    since: 'now'
  }, function(err, change) {
    // change.doc.time.unpublished will be
    // an object.
  });

  feed.on('catchup', function() {
    (new Registry()).unpublish('request@1.9.0').done();
  })
});
```

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