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

mocha-apiary-reporter

v1.1.0

Published

Generate API documentation using Apiary's Blueprint style, then plug it right into apiary.io to get beautiful docs!

Downloads

62

Readme

Apiary Documentation for your Node.js RESTful API

Apairy Screenshot

mocha-apiary-reporter is a Mocha reporter that understands Supertest to generate reliable and up-to-date API samples. It allows you to:

  • define concrete request/response examples in your test suite
  • if you need to, use mocks to make sure you fully control the API responses
  • add a few explanations
  • get high-level API documentation that's beautiful and always up-to-date!

Works with any Node.js http.Server, like Express or Restify

Results

Check out the demo docs to see the final result.

Setup

npm install mocha-apiary-reporter --save-dev

You also need to specify documentation options in a mocha-apiary.json file at the root. This file has to be valid JSON, but also supports comments:

{
  "baseUrl": "http://example.com/",
  "name": "Cats API",
  "description": "Cats is a super simple API of cats and their human owners. Check out docs at: https://app.apiary.io/catsapi1",

  // Mocha reporter to display test results
  // e.g. Dot, TAP, Spec...
  "reporter": "Spec",
}

Usage

Have a look at the test example to get started.

Simply use nested describe blocks, and it will generate the request/response documentation for you! The first describe is the header of a collection of endpoints. The next describe is each endpoints header. The 3rd, and final, describe is the description of that endpoint.

let app = require("./server");
let req = require("supertest")(app);

describe("User Collection [/user]", () => {
  describe("Create a new user", () =>
    describe("A description of what this API endpoint does", () => {
      it("creates the user", done =>
        req.post("/user")
        .body(userInfo)
        .expect("Content-Type", /json/)
        .expect(200, done)
      );

      it("fails due to bad email", done =>
        req.post("/user")
        .body(userInfoWithBadEmail)
        .expect("Content-Type", /text/)
        .expect(400, done)
      );
    })
  );
})

Then run your tests:

./node_modules/.bin/mocha --reporter mocha-apiary-reporter path/to/tests

Note that the text of the it doesn't show up in the docs.

Credits and More

Huge thanks go to the authors of supersamples. I used a lot of ideas from their work.

If you're looking to generate API docs in Markdown, HTML, or JSON format, you check supersamples out.

Contributions

Any kind of contribution would be highly appreciated. You are welcome, and encouraged, to use the pull requests and issues sections of this repo :)