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

literate-jasmine

v0.1.2

Published

Write jasmine tests in markdown as documentation

Downloads

13

Readme

literate-jasmine Build Status

NPM

var PI;

Mathematics

PI = 22/7;

add can add numbers

var a = 1,
    b = 2;

expect(a + b).toBe(3);

can divide numbers

var a = 6,
    b = 2;

And a comment here doesn't break things:

expect(a/b).toBe(3);

calculates the circumference of a circle

Note that we reference the variable PI below that is defined in the code block at the top of this describe (so right under "Mathematics").

var circumference = function(radius) {
  return 2 * PI * radius;
};

expect(circumference(5)).toBe(2 * 22/7 * 5);

Strings

appending works with +

var text = "abc";

expect(text + "d").toBe("abcd");

Asynchronous

works with done

setTimeout(function() {
  expect(true).toBe(true);
  done();
}, 50);

The file you are currently reading has a markdown structure (which includes the main header above and the other parts below) that is parsed into a tree:

  • literate-jasmine
    • Mathematices
      • add can add numbers (level 3 header)
      • add can add numbers
      • calculates the circumference of a circle
    • Strings
      • appending works with +
    • Asynchronous
      • works with done

Which is then uses the Jasmine describe, it and beforeEach to setup the tests and then run them.

Note that there is a convention -- a hard rule that there will be a top header (top describe), one or more headers below that (describes) and one or more header below each of those (it blocks).*

screen shot of convention

This hard limitation makes sense:

  • forces documentation to be simple
  • nested describes indicate that extracted some code to helper functions is probably a sensible solution instead of adding more nesting
  • easier to parse both as a human and as a computer
  • keeps everything simple

literate-jasmine README.md

screen shot of running literate-jasmine on this README.md

(If you're working on this project, run ./bin/literate-jasmine instead.)

Take a close look at how scope works for globals. In the Mathematics section below, we reference PI to reset it as a beforeEach so every test has PI reset to the correct value. The actual declaration of PI as a variable happens on the fourth line of this README. The root describe treats any code blocks after it as global setup.