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

flitch

v0.7.3

Published

Minimal testing library

Downloads

5

Readme

flitch

flitch

Logo by twitter.com/haggle

A cute testing library that barks at you.

import { suite, run } from 'flitch';
import { strict as assert } from 'assert';

// create suite with timeout of 5 seconds for all operations
const test = suite('Flitch Tests', { timeout: 5 });

// attach before/after hooks
// e.g, test.before.all, test.before.each, test.after.all, test.after.each
test.before.all = (ctx) => {
  // use context object to share values within suite
  ctx.sum = 0;
};

test('addition works', (ctx) => {
  ctx.sum += 10;
  assert.equal(ctx.sum, 10); // tests rely on thrown errors to detect failures
});

test.not('this test will be skipped', (ctx) => {
  ctx.sum += 20;
  assert.equal(ctx.sum, 31); // this would fail, but we're skipping this test! *shrugs*
});

test.skip('test.skip is an alias for test.not', async () => {
  await new Promise(resolve => setTimeout(resolve, 6 * 1000));
});

test('this test would not timeout!', async () => {
  await new Promise(resolve => setTimeout(resolve, 6 * 1000));
}, 7); // timeout can be specified per test

test('this test cleans up after itself', async (ctx) => {
  await new Promise(resolve => setTimeout(resolve, 2 * 1000));
  ctx.sum += 100;
},
  3, // time out after 3 seconds
  (ctx) => {
    ctx.sum -= 100; // cleanup
  }
);

test.only('this test will run, by itself!', async (ctx) => {
  let num = await Promise.resolve(50);
  ctx.sum += num;
  assert.equal(ctx.sum, 50);
});

// `not`, `skip`, and `only` can also be used on suites
const test2 = suite.skip('This whole suite will be skipped');

test2('this will never run!', () => {
  assert.equal(1, 1);
});

run({ parallel: false }); // optionally run all suites in parallel

Save the above to test.js and run like so:

node test.js

The above outputs:

Flitch Tests
✓ 1 tests passed
↷ 5 tests skipped

⧗ 0.001s

• • •

Passed:  1
Failed:  0
Skipped: 5

↷ 1 suites skipped

Duration: 0.004s

Install

npm install flitch --save-dev

Running all test files in a directory

Pass a string to path to recursively look for test files. By default, test files with .test.js and .test.jsx extensions will be imported. A regular expression can be passed to ext for custom extensions.

import { run } from 'flitch';

run({
  // path: string
  // relative to `process.cwd()`
  path: './tests',

  // ext: RegExp
  // used to match filenames
  ext: /\.test.(js|cjs|mjs)$/
});

Credits

Inspired by fantestic.