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

dump_describes

v0.3.4

Published

View all `describe` and `it` blocks in a test suite

Downloads

5

Readme

dump_describes

Build Status Coverage Status npm

dump_describes is a tool that provides a high-level view of all of the describe and it blocks in a test suite. This is useful to quickly gain familiarity with a particular suite and to easily determine where to insert new tests.

Any testing framework that uses describe and it blocks to define a suite is supported, such as Jasmine, Mocha and Jest.

How It Works

dump_describes uses Esprima to parse the given JavaScript and create an AST. This is then recursively walked to find all of the describe blocks and, optionally, all of the it blocks. The results are either logged to stdout or written to an html document.

The top-most describe block which wraps the entire suite will be used as the name of the produced output and will lend its name to the generated html file (if the --html switch is given).

When transpiling from another language into JavaScript, it can be useful to pipe the results of the transpilation to dump_describes. This is useful and avoids the intermediary step of having to save to a file:

coffee -p suite.coffee | dump_describes

By default, dump_describes will only dump the describe blocks. Use the --verbose flag to also dump the it blocks.

The following identifiers are supported:

  • describe
  • fdescribe
  • xdescribe
  • it
  • fit
  • xit

Installation

npm install https://github.com/btoll/dump_describes.git -g

Usage

Property | Description
------------ | -------------
--destination, -d | [Optional] The location to save the output (defaults to $PWD)
--html | Creates an html document of the tree
--markdown, --md | Creates a markdown document of the tree
--target, -t | The target suite to parse
--debug | Turns on debug mode
--verbose, -v | Also dumps `it` blocks
--help, -h | Show help

Examples

Test on the CLI by piping into stdin:

cat | dump_describes -v

At which point enter the following snippet, followed by Ctrl-D:

describe('test', () => {
    describe('foo', () => {
        it('should derp', () => {
        });
    });
});

The following will dump the result of processing the Filters.js suite to stdout:

dump_describes -t Filters.js

Also, print debugging information:

dump_describes --debug -t Filters.js

Also, dump it blocks:

dump_describes -t Filters.js -v

Create an html document of the same tree produced by the previous command (describe nodes can be expanded/collapsed):

dump_describes -t Filters.js -v --html

Create an markdown document of the same tree produced by the previous command (describe nodes can be expanded/collapsed):

dump_describes -t Filters.js -v --md

Pipe:

coffee -p suite.coffee | dump_describes -v --html

cat suite.js | dump_describes -v

dump_describes -t Filters.js | tee foo

Let's get fancy and open a file from the internet in the default browser:

curl https://raw.githubusercontent.com/btoll/dump_describes/master/spec/dump_describes_spec.js |
    dump_describes -v --html |
    cut -d' ' -f3 |
    xargs xdg-open

Creating a Custom Code Generator

dump_describes ships with three generators, LOG, HTML and MARKDOWN.

However, it's very easy to create a generator. The only stipulation is that the generator module expose a print method, which is called with the node results and the value of verbose.

print must return a Promise, which in turn will resolve with the list of transformed results or a simple message or something else, depending on the requirements.

Using with Vim

I use the following command abbreviations to view a suite from within Vim.

Typing :dd followed by a [[space]] will become :!clear && dump_describes -t %:

autocmd FileType javascript cnoreabbrev <expr> dd getcmdtype() == ":" && getcmdline() == 'dd' ? '!clear && dump_describes -t %' : 'dd'

Typing :ddv followed by a [[space]] will become :!clear && dump_describes -t % -v:

autocmd FileType javascript cnoreabbrev <expr> ddv getcmdtype() == ":" && getcmdline() == 'ddv' ? '!clear && dump_describes -t % -v' : 'ddv'

Screenshots

ScreenShot ScreenShot ScreenShot ScreenShot

Known Issues

The following nodes are not yet supported and parsing them will produce surprising and unexpected results (even errors):

  • ForStatement
  • ForInStatement
  • ForOfStatement
  • DoWhileStatement
  • WhileStatement

License

GPLv3

Author

Benjamin Toll