npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pouchdb-plugin-helper

v5.0.1

Published

A helper tool for PouchDB plugins to run tests and more

Downloads

66

Readme

pouchdb-plugin-helper

Build Status Dependency Status devDependency Status

A helper tool for PouchDB plugins to run tests and more

For an example, see the pouchdb-auth project.

Installation

npm install --save-dev pouchdb-plugin-helper

Update your package.json script section:

  "scripts": {
    "helper": "./node_modules/.bin/pouchdb-plugin-helper",
    "test": "npm run helper -- test",
    // optional. The argument is the name of the browserify object on window
    "build": "npm run helper -- build Auth"
  }

Commands

npm run helper -- build # builds a browserified version of the package
npm run helper -- coverage # run js tests with coverage
npm run helper -- js-test # run js tests
npm run helper -- lint # run linter against source files
npm run helper -- test # shortcut for lint & coverage
npm run helper -- badges # generate badges for use in README.md
npm run helper -- travis # generate a relevant .travis.yml file
npm run helper -- gitignore # generate a relevant .gitignore file
npm run helper -- test # runs lint and coverage

Notes

  • The build command will generate both a minified and an unminified file in the dist/ subdirectory. It gets an argument: a name as used for on the window object.
  • The coverage command will put coverage info in the coverage subdirectory. It has a non-zero exit code if coverage isn't 100%.
  • The js-tests command runs all tests in the test subdirectory. It uses mocha to do so. Files in this directory (and in this directory only!) can use ES6, with as a bonus ES7's async & await.

require() helpers

import {/* e.g.*/ PouchDB, should} from 'pouchdb-plugin-helper/testutils');

PouchDB

A PouchDB object that by default makes a memdown backed database.

should

A chai object used to make assertions. E.g.:

should.exist(undefined) // error
true.should.be.ok // no problem

setup()

Makes a PouchDB database and returns it to you. Handy for use in mocha's beforeEach.

setupWithDoc()

setup(), with the following document in the database:

{
  _id: 'mytest',
  test: true
}

Returns a promise which resolves to the following object:

{
  db: '<the pouchdb db>',
  rev: '1-xxx'
}

setupWithDocAndAttachment

setupWithDoc, with the following attachment added to the database:

{
  _id: 'attachment_test',
  _attachments: {
    'text': {
      data: new Buffer('abcd', 'ascii'),
      type: 'text/plain'
    }
  }
}

setupHTTP()

Similar to setup(), but then on the database specified by BASE_URL and HTTP_AUTH (see below). Don't use at the same time as setup().

teardown()

Cleans up the database created by setup() or setupHTTP. Handy for use in mocha's afterEach. Returns a Promise.

shouldThrowError(func)

func should be a promise, and this function returns a promise too.

This function runs func, and catches any error that's thrown by it. The function resolves into this error. If no error is thrown, it fails. An example of how it can be used:

const error = await shouldThrowError(async () =>
  await db.get('unexisting-doc')
);
error.status.should.equal(404);

Configuration constants

Some properties of the tests can be configured. These values are available under the names:

BASE_URL: defaults to 'http://localhost:5984' HTTP_AUTH: defaults to null

You can change these values to your own development setup by making a file ~/.pouchdb-plugin-helper-conf.json, with context like this:

{
  base_url: 'http://localhost:5985',
  username: 'test',
  password: 'test'
}

All keys are optional.