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

cowboy-hat

v1.0.2

Published

A cli for testing the other universe of code

Downloads

5

Readme

Cowboy Hat

     .~~~~`\~~\
    ;       ~~ \
    |           ;
 ,--------,______|---.
/          \-----`    \
`.__________`-_______-'

Art by Tom Youderian

A package for testing code from the other universe (of uncompiled code).

What?

This is designed for use when generating code coverage reports on a project using babel.js or other compilation tools. Cowboy Hat allows you to write your tests against your compiled code but generate quick coverage reports against your source as you write and fulfill your tests. Also, it's a small Futurama reference.

Futurama

e.g.

Say you have a some code you want to test and you've written your tests against your babel output because you are a responsible person who wants to ensure that your end product is ready to be published. You want to run an in depth coverage report with a tool like nyc once you're ready to publish but you'd also really like to watch your codebase for file changes and generate quick coverage reports maybe even for use with line highlighting in your editor. Now You Can! Simply tell cowboy hat which files to watch, where your compiled code is, and where your original code is.

tests/test.js

const CodeToTest = require('../dist/code-to-test.js');

describe('A test', function() {
    // Stuffs here
});

Run tests written for files in dist/ against src/.

cowboy-hat --from '../dist/' --to '../src/'

This will watch files in src/ and test/ for changes, generate coverage reports, and report like so:

=============================== Coverage summary ===============================
Statements   : 100% ( 236/236 )
Branches     : 95.76% ( 113/118 )
Functions    : 92.73% ( 51/55 )
Lines        : 100% ( 234/234 )
================================================================================

Yes! You can write your tests in es6!

How?

cowboy-hat --from '../dist/' --to '../src/'

or

cowboy-hat -f '../dist/' -t '../src/'

With config file

cowboy-hat

As a lib

const cowboyHat = require('cowboy-hat');
const config = require('./cowboy-hat.config.js');

cowboyHat(config);

API

From

The diretory that your tests are written against. Default: ../dist/ Type: String Argument: --from or -f

To

The directory that your tests will run against. Default: ../src/ Type: String Argument: --to or -t

Test Directory

The directory where your tests are kept. Default: ./test/*.js Type: String Argument: --testDir or -d

Test Entry Point

The entry point for running tests. Default: <testDir> Type: String Argument: --testEntry or -e

Watch

An array of files to watch for changes. Default: [<to>.replace(/^\.\.\//, ''), <testDir>] Defaults to the to and testDir arguments. to will have the first ../ trimmed from the front of the string if it is present. This is because by default cowboy-hat expects the to and from arguments to be one directory lower than where the command is run from. Type: Array Argument: --watch or -w

Config file

You can use a config file cowboy-hat.config.js for any of these arguments. Cowboy hat will look for it when it is run from the command line and any arguments supplied to the cli will override the config.

module.exports = {
    from: '../dist/',
    to: '../src/',
    watch: [], // This will be overridden with the default listed above because it is empty
    testDir: 'test/*.js',
    testEntry: 'test.js',
};

Directory Structure

By default cowboy-hat expects that your to and from will be one directory lower than where the command is run from. This is why the paths are shown as they are. I.e. Watch the directories ./src and ./test for changes then replace '../dist' with '../src' inside of ./test (then run tests and swap back).

project -
    |____dist +
        |____foo.js
    |____src +
        |____foo.js
    |____test +
        |____foo-tests.js
    |____test.js

Testing Cowboy Hat

To test it just pull the repo and run cowboy-hat in it's root dir and make trigger a change on either test/test.js or src/mock-code.js. Everything is passing if you have 100% line coverage.

Feedback ✉️

It is greatly appreciated! 🎉 Please hit me up, I'd love to hear what you have to say!

[email protected]

https://github.com/limeandcoconut

@limeandcoconut

Cheers!

TODO:

  • [ ] FAASSTERR
  • [ ] Make cowboy-hat exit when no files are being watched
  • [ ] Make watching optional
  • [ ] Switch to (webpack-esque) constructor syntax
  • [ ] Add better tests

Usage Stats

NPM

License

MIT, see LICENSE.md for details.