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

assert-responselike

v0.6.4

Published

An ultra simple all-test-framework friendly utility, meant to be used with the test framework of your choice, decorates the built-in assert object with a new method responseLike(res,exp,msg)

Downloads

19

Readme

assert-responseLike Build Status

Overview

This is an ultra simple all-test-framework friendly utility, meant to be used with the test framework of your choice, decorates the built-in assert object with a new method responseLike(res,exp,msg)


Usage

usage :

    var assert = require("assert");
      , request = require('your favorite http request lib')
      , test  = require('your favorite test function of your favorite framework')
      ;
     
    require("assert-responselike"); 

    test( "foo", function() {
      request(url, function(response){
          assert.responseLike( response
           , { status : 200 //throws 'Invalid response code - expected ... got ...'
             , statusCode : 200 //same like status, for the explicitness lovers..
             , headers :                      
               { "Content-Type" : "text/plain" //throws 'response-header - expected ... got ...' 
               }
             , body : "run vows for full spec" //throws 'Invalid response body - expected ... got ...'
             }
          );
      });
    });

Installation

using NPM

npm install assert-responselike

esample of output:

D:\work\mymodule>npm install assert-responselike
npm http GET https://registry.npmjs.org/assert-responselike
npm http 304 https://registry.npmjs.org/assert-responselike
[email protected] ./node_modules/assert-responselike

Do it yourself

download the zip from github, and extract it to your ./node_modules/ directory.

example of structure Either way - expect the following:

└───node_modules
    └───assert-responselike
        │   .npmignore
        │   index.js
        │   package.json
        │   README.md
        │
        └───test
                assert-response-test.js

Testing

after extracting first you have to :

npm install

esample of output:

D:\work\assert-responseLike>npm install
npm http GET https://registry.npmjs.org/vows
npm http 304 https://registry.npmjs.org/vows
npm http GET https://registry.npmjs.org/eyes
npm http 304 https://registry.npmjs.org/eyes
npm WARN [email protected] dependencies field should be hash of <name>:<version-range> pairs
[email protected] ./node_modules/vows
└── [email protected]

and then vows --spec

  • if you're a windows user - you'll want to add to your PATH variable '.\node_modules.bin'
  • alternatively - just run node ./node_modules/vows/bin/vows --spec

Specifications

  ? assert response

  API
    √ assert should be decorated with the method:

        assert.responseLike ( oActualResponse, oExpectedDescr, sCustomMessage )

  check status code with attribute 'status'
    √ providing correct numner should work
    √ providing wrong number should throw

  check status code with attribute 'statusCode'
    √ providing correct number should work
    √ providing wrong number should throw

  check response headers
    √ providing existing headers should work - case insensitive
    √ providing wrong headers throw on the first mismatch
    √ providing missing headers throw on the first misfound

  check response body
    √ regexp body descriptor that matches should not throw
    √ regexp body descriptor that does not match should throw
    √ when descriptor is not a RegExp, and body is object - deep equal match should not throw
    √ when descriptor is not a RegExp, and body is object - deep equal difference should throw

  check response headers - provide expected content
    √ equal string - should pass
    √ different string - should throw
    √ matching regexp - should pass
    √ non-matching regexp - should throw

  thrown errors - when providing a message
    √ should trail status-code error messages
    √ should trail response-header error messages
    √ should trail response-body error messages

  thrown errors - a status-code check error message
    √ should start with 'Invalid response status code'
    √ should contain the expected response code
    √ should contain the actual response code

  thrown errors - a missing response-header check error message
    √ should start with 'response header'
    √ should contain the expected response header name
    √ should contain the expected response header value
    √ should contain the actual response value

  thrown errors - a mismatching response-header check error message
    √ should start with 'response header'
    √ should contain the expected response header name
    √ should contain the expected response header value
    √ should contain the actual response value

√ OK » 30 honored (0.183s)

Misc

It's not the most genious utility or anything, it is meant to be my first git hub project. I use it to test responses of web-requests to web projects, with vows.

The basis of the implementation is taken from from expresso, that did not work well for me on windows, and the implementation there is coupled with the request firing itself - and I did not like that. so now I can use the same assert description language with any test-framework i like, and use whatever request tools I want.

Lisence

I don't know what i need to do to make it officual under whatever lisence is up there... I took from 'the community' so I give back. Take it, as is, I give no warantee. Do with it whatever you want on your own responsibility.