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

vodka

v4.0.0

Published

A functional testing framework for web apps

Downloads

82

Readme

VODKA

A functional testing framework best suit for testing json api servers

Requires

Checkout package.json for dependencies.

Installation

Install through npm

npm install vodka -g

Usage

Command line tools

Usage: vodka [command] [argument(s)]

Commands:
  -v, --version     Display vodka version
  h,  help          Display usage information
  n,  new [project] Create a new test project

Available environment variables:
  BASE_DIR: Test project base directory  Default: `cwd`
  ROOT:     Testing target host and port Default: http://127.0.0.1:4000
  TIMEOUT:  Request timeout              Default: 60000ms

Generate a new test project

$ cd /path/to/the/test/folder/of/your/app
$ vodka new your-project-name

create  shit/
create  shit/actions/
create  shit/fixtures/
create  shit/validators/
create  shit/actions/user.js
create  shit/fixtures/ori_user.json
create  shit/validators/common.js
create  shit/validators/user.js
create  shit/package.json

Run test

# VODKA now come with mocha, in your test root dir call
$ mocha -R spec -t false -b actions

Tutorial

Add your actions in actions dir. ex. user.js

const should      = require('should');
const should_http = require('should-http');
const vodka       = require('../../../index');
const fixture     = vodka.fixture;
const validator   = vodka.validator;

describe('Test CRUD of the users api', () => {
  describe('POST /users', () => {
    it('should res json with status 201 and a user obj', (done) => {
      vodka('POST /users', {
        /* more `request` options -> https://github.com/mikeal/request */
        // headers : {}, // pass any headers to the server
        // form    : {}, // for passing form inputs
        // qs      : {}, // for passing get request params

        /* this is for `vodka` not for `request`;
         * for replace the params in url;
         * check the next test */
        // params : {},

        /* you can hard coded the user obj */
        // json : {
        //   name    : 'ben',
        //   email   : '[email protected]',
        //   website : 'https://popapp.in'
        // }

        /* or use fixture */
        json: fixture('ori_user')
      }, (err, res, body) => {
        /* you can directly inspect res here */
        // should.not.exist( err );
        // res.should.be.json;
        // res.should.have.status( 201 );

        /* but using validator will make the code more reusable */
        validator('create', err, res, body);
        /* this also applies to the user obj */
        // user.should.have.property( '_id' ).with.a.lengthOf( 24 );
        // user.should.have.property( 'name' ).be.a.String.and.eql( 'ben' );
        // user.should.have.property( 'email' ).be.a.String
        //   .and.match( vodka.utils.email );
        // user.should.have.property( 'website' ).be.a.String
        //   .and.eql( 'https://popapp.in' );
        // user.should.have.property( 'created_at' ).be.a.Number;
        // user.should.have.property( 'updated_at' ).be.a.Number;
        // user.created_at.toString().should.have.a.lengthOf( 13 );
        // user.updated_at.toString().should.have.a.lengthOf( 13 );

        /* again validator is helpful when you have a huge code base */
        validator('user', body);
        /* save user obj as fixture for future related test */
        fixture('user', body);
        done();
      });
    }).timeout(100);
  });

  describe('GET /users/:user_id', () => {
    it('should res json with status 200 and a user obj', (done) => {
      vodka('GET /users/:user_id', {
        params: { user_id: fixture('user')._id },
        json  : true
      }, (err, res, body) => {
        validator('ok', err, res, body);
        validator('user', body);

        done();
      });
    }).timeout(100);
  });

  describe('PUT /users/:user_id', () => {
    it('should res json with status 200 and a updated user obj', (done) => {
      const update_user_data = fixture('update_user');

      vodka('PUT /users/:user_id', {
        params: { user_id: fixture('user')._id },
        json  : update_user_data
      }, (err, res, body) => {
        validator('ok', err, res, body);
        validator('user', body);

        fixture('user', body);
        body.website.should.eql('https://woomoo.in');

        done();
      });
    }).timeout(100);
  });

  describe('DELETE /users/:user_id', () => {
    it('should res json with status 204', (done) => {
      vodka('DELETE /users/:user_id', {
        params: { user_id: fixture('user')._id },
        json  : true
      }, (err, res, body) => {
        validator('destroy', err, res, body);

        done();
      });
    }).timeout(100);
  });
});

Please visit Request -- Simplified HTTP request method for detail

Inspect response format with validator in validators/validator_file_name.js

const should      = require('should');
const should_http = require('should-http');
const email       = require('../../../index').utils.regex.email;

module.exports = {
  user: (user) => {
    Object.keys(user).should.have.lengthOf(6);

    user.should.have.property('_id').with.lengthOf(24);
    user.should.have.property('name').which.is.a.String();
    user.should.have.property('email').which.is.a.String().and.match(email);
    user.should.have.property('website').which.is.a.String();
    user.should.have.property('created_at').which.is.a.Number();
    user.should.have.property('updated_at').which.is.a.Number();
    user.created_at.toString().should.have.lengthOf(13);
    user.updated_at.toString().should.have.lengthOf(13);
  }
};

Object Properties

vodka
  - configs
    - BASE_DIR
    - ROOT
    - TIMEOUT
  - fixture
  - utils
      - is
      - merge
      - ranNo
      - regex
        - beginSlash
        - email
        - format
        - jsFile
        - noneCharacters
        - tailSlash
        - url
      - uid
  - validator
  - version

Check the source for detail

License

(The MIT License)

Copyright (c) 2012 dreamerslab <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.