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

testosterone

v1.3.1

Published

Virile testing for http servers or any nodejs application

Downloads

15

Readme

✿ Testosterone

Virile testing for http servers or any nodejs application.

Installation

npm install testosterone

WhateverDrivenDevelopment

Testosterone allows you to follow BDD or TDD on any of your projects using the same testing library.

Options

  • host: Host to do the http calls. localhost
  • port: Port to do the http calls. 80
  • output: Configure the amount of verbosity you want for your tests
    • specs: Print the specs true
    • ticks: Print the ✓ and ✗ ticks true
    • summary: Prints the summary true
    • title: Prints the title true
  • title: Test title, it will be printed out. Testosterone
  • sync: If set to true, you don't need to call done to specify when your tests are done. false

API

testosterone API is simple and flexible.

  • get|post|head|put|delete...(url, req, response, cb): Does a http call with the given request. If a response is given, testosterone will assert that the real response matches.
  • add(spec, function(done)): Adds a test. The test is considered executed when done function is called.
  • before(function): Runs before each test.
  • after(function): Runs after each test.
  • run([cb]): Runs the tests in serial. cb will be called once all the tests are executed.
  • assert: You must use this assert object instead of the native one.

All the functions are chainable.

Show me the code

You have more examples on the test folder:

HTTP testing example:

var testosterone = require('testosterone')({port: 3000})
  , assert = testosterone.assert;

testosterone
  .get('/', function (res) {
    assert.equal(res.statusCode, 200)
  })

  .get('/hi', function (res) {
    assert.equal(res.statusCode, 500);
    assert.equal(res.body, 'use post instead');
  })

  .post('/hi', {data: {message: 'hola'}}, {
    status: 200
  , body: 'hola'
  });

// Output

$ node test.js

✿ Testosterone : ✓ ✓ ✓ ✓ ✓
» 3 responses, 5 asserts

Asynchronous example:

var testosterone = require('testosterone')({post: 3000, title: 'Testing async'})
  , assert = testosterone.assert;

testosterone

  .before(function () {
    console.log('test about to run!');
  })

  // using done to tell testosterone when the test is done
  .add('First test', function (done) {
    setTimeout(function () {
      assert.ok(true);
      done();
    }, 999);
  })

  // same but currying
  .add('Second test', function (spec) {
    assert.ok(true);

    setTimeout(done(function () {
      assert.ok(true);
    }), 10);
  })

  .run(function () {
    require('sys').print('All tests passed!');
  });

// Output

$ node test.js

✿ Testing async :

First test => ✓
Second test => ✓ ✓

» 0 responses, 3 asserts

Example with gently stubbing and sync: true:

var testosterone = require('testosterone')({post: 3000, title: 'Testing with stubs', sync: true})
  , gently = new (require('gently'))
  , fs = require('fs')
  , assert = testosterone.assert;

testosterone
  .add('GIVEN foo.txt \nWHEN its empty \nTHEN it return null', function (spec) {
    gently.expect(fs, 'readFile', function (path, encoding, cb) {
      assert.equal(path, 'foo.txt');
      cb(null, null);
    });

    fs.readFile('foo.txt', 'utf-8', function (er, data) {
      assert.equal(er, null);
      assert.equal(data, null);
    });
  })

  .add('GIVEN foo.txt \nWHEN it have content \nTHEN it return that content', function (spec) {
    gently.expect(fs, 'readFile', function (path, encoding, cb) {
      assert.equal(path, 'foo.txt');
      cb(null, 'foo');
    });

    fs.readFile('foo.txt', 'utf-8', function (er, data) {
      assert.equal(er, null);
      assert.equal(data, 'foo');
    });
  })

  .run(function () {
    require('sys').print('done!');
  });

// Output

$ node test.js

✿ Testing with stubs :

GIVEN foo.txt
WHEN its empty
THEN it return null => ✓ ✓ ✓

GIVEN foo.txt
WHEN it have content
THEN it return that content => ✓ ✓ ✓

» 6 asserts

Test

In order to run the tests type:

npm install
make test_app
make

Credits

The _call function of this library is a shameless copy from expresso response assert done by TJ Holowaychuk (visionmedia)