Useful shared test helpers for writing apps that interact with npm.
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
local.ini to have the settings outlined in https://github.com/npm/npm-registry-couchapp.test-config.json that has appropriate settings for your CouchDB configuration:{
"testRegistryName": "npm-test-registry",
"host": "localhost",
"port": 5984,
"scheme": "http",
"cache": "/tmp",
"couchUser": "admin",
"couchPass": "admin",
"populateDesign": true
}
initializing a testing registry
Couch = require('../lib').Couch;
couch.setup().then(function() {
// a registry is now available with the
// design documents populated.
});
tearing down the testing registry
var Couch = require('npm-test-helpers').Couch;
couch.teardown().then(function() {
// the testing registry has been destroyed.
});
publishing a package
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
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
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
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();
})
});