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

@lewis-campbell/dmt

v2.0.4

Published

A declarative, minimalist testing library for the browser

Downloads

15

Readme

DMT - Declarative Minimalist Testing

DMT is a testing microframework for JavaScript. It's tiny, runs in the browser, and has a simple but powerful API.

Example:

<script type="module">
  import dmt from "https://unpkg.com/@lewis-campbell/dmt"

  dmt(document.body, {
    'Promise': {
      '#resolve()': async () => {
        const actual = await Promise.resolve('Success')
        return {check: actual, equals: 'Success'}
      }
    },
    
    'Array': {
      '#indexOf()': {
        'should return -1 when the value is not present': () => ({
          check: [1, 2, 3].indexOf(4),
          equals: -1
        })
      },
      '#map()': {
        'should map [] to []': () => ({
          check: [].map(x => x * x),
          deepEquals: []
        })
      }
    }
  })
</script>

Motivation

When I began practicing TDD in Javascript, my first instinct was to use a popular framework like Mocha.

I hated it:

  • test files used un-declared global functions
  • it needed a separate binary to run tests
  • the browser output couldn't refresh after bundling

I wanted to create something that was declarative, minmalist, unobtrusive, and got the job done.

Features

The Test Suite doesn't depend on the library

One thing you might notice about the example test suite - it doesn't depend on any imports from DMT at all! This is by design.

Test suites are just a javascript object of a certain shape. This means your usual tooling will work (ie, typechecking) and you're free to generate and compose test suites in whatever way you seem fit.

Declarative

DMT doesn't have global functions like describe, beforeEach, afterEach etc. In fact DMT only has one function - and it runs your tests. The tests themselves are simply trees represented by javascript objects, where the keys are descriptions and the leaf values are es6 arrow functions that return an assertion. This means that test files do not need to reference this library.

Assertions built in

I'm a simple man, and I really only need two assertions - 'equals' for primitives, and 'deepEquals' for arrays and objects.

Check out the article Rethinking Unit Test Assertions by Eric Elliot.

Doesn't impose a workflow on you.

You decide, when, where, and how you run to tests by passing the test suite to the DMT function

There's no command line switches, or compatability plugins - it's a just a function that you can call whenever you want to

It can automatically run on the browser after webpack is done rebuilding, so it's good for running tests on phones.

FAQ

How do I do teardown and setup?

There are no need for special functions when you have objects and closures already.