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

chinotto

v1.0.0

Published

Custom Chai assertions, mainly filesystem-related.

Downloads

12

Readme

Chinotto: Custom assertions for Chai.js

Build status: TravisCI Build status: AppVeyor Coverage status

Compilation of useful Chai assertions that I've written over time, migrated from the test-suites of various projects (atom-mocha in particular).

“Uh, why did you name thi-”

Because if Chai and Mocha proved anything, it's that beverages make memorable library names. Also, I enjoy Chinotto and the name on NPM was available, so I took it. Superalo.

Usage

  1. Add chinotto to your project's devDependencies:

    $ npm install --save-dev chinotto
  2. Then call the register() function it exports:

    require("chinotto").register();

    This automatically registers every available extension with Chai, which are used like any other BDD-style assertion:

    expect(__filename).to.be.a.file.and.to.existOnDisk;
    __dirname.should.be.a.file.and.equalPath(__dirname + "/");

    Alternatively, you can just import chinotto/register instead. This calls register() for you automatically, and makes Chinotto globally available:

    require("chinotto/register");
    
    // Define a hypothetical extension to check modification status:
    global.Chinotto.defineAssertion("modified", (subject, expected) =>
    	[subject.isModified(), "to be modified"]);
    
    // Usage:
    expect("/some/edited/file").to.be.modified;
    expect("/unedited/file").not.to.be.modified;

API reference

  • chai: Object — Reference to the Chai module used by Chinotto.
  • methods: Map — Handler functions for assertion methods, keyed by name(s)
  • properties: Map — Handler functions for assertion properties, keyed by name(s)

The remaining exports are detailed under Utils:

Check if an HTMLElement contains one or more CSS classes.

Example:

document.body.should.have.class("content");
expect($(".btn.large")).to.have.classes("btn", "large");

Assert that two filesystem paths are logically the same.

Example:

"/bin".should.equalPath("/bin/");
"/bin/../bin".should.equalPath("/bin");

Assert that two files have the same inode and device number.

Example:

"/a/huge/file".should.have.hardLink("/same/huge/file");
expect("huge.file").to.be.hardLinkOf("also.huge");

Assert that a symbolic link points to the specified file.

Example:

"/tmp".should.be.a.symlink.pointingTo("/private/tmp");

Assert that an HTMLElement is rendered in the DOM tree.

Example:

document.body.should.be.drawn;
document.head.should.not.be.drawn;

Assert that an HTMLElement has user focus, or contains something which does.

Example:

document.activeElement.should.have.focus;
document.createElement("div").should.not.have.focus;

Assert that a file exists in the filesystem.

Example:

"/bin/sh".should.existOnDisk
"<>:*?\0".should.not.existOnDisk

Assert that subject is a path pointing to a regular file.

Example:

"/bin/sh".should.be.a.file
"/bin".should.not.be.a.file

Assert that subject is a path pointing to a directory.

Example:

"/bin".should.be.a.directory
"/bin/sh".should.not.be.a.directory

Assert that subject is a path pointing to a symbolic link.

Example:

"/usr/local/bin/node".should.be.a.symlink

Assert that subject is a path pointing to a device file.

“Device file” refers to either a character device or a block device, making this assertion preferable to blockDevice and characterDevice for cross-platform testing.

Example:

"/dev/zero".should.be.a.device;

Assert that subject is a path pointing to a block device.

Example:

"/dev/disk0s1".should.be.a.blockDevice

Assert that subject is a path pointing to a character device.

Example:

"/dev/null".should.be.a.characterDevice

Assert that subject is a path pointing to a FIFO (named pipe).

Example:

"/tmp/154B17E1-2BF7_IN".should.be.a.fifo

Assert that subject is a path pointing to a door.

Example:

"/system/volatile/syslog_door".should.be.a.door

Assert that subject is a path pointing to a socket.

Example:

"/run/systemd/private".should.be.a.socket

Variant of chai.Assertion.addMethod that supports plugin aliases.

If the property already exists on the prototype, it will not be overwritten. To redefine existing methods and prototypes, use chai.util.addMethod or chai.util.overwriteMethod.

Example:

addMethod(["pointTo", "pointingTo"], function(target){ … });

Variant of chai.Assertion.addProperty that supports plugin aliases.

Example:

addProperty(["coloured", "colored"], fn);

Variant of defineAssertions that defines only one assertion.

Wrapper for defining simple custom Chai assertions.

Example:

<caption>Defining a "colour" assertion</caption>
// Typical definition:
defineAssertions({
   ["colour, coloured"](subject, expected){
       const actual = subject.colour;
       this.assert(
           actual === expected,
           "expected #{this} to be coloured #{exp}",
           "expected #{this} not to be coloured #{exp}",
           expected,
           actual
       );
   },
});

// Usage:
expect({colour: 0xFF0000}).to.have.colour(0xFF0000);
expect({colour: "red"}).not.to.be.coloured("green");

<caption>Shorthand for the above</caption>
defineAssertions({
   ["colour, coloured"](subject, expected){
       return [
           subject.colour === expected,
           "to be coloured #{exp}",
       ];
   },
});

Register every available Chai extension.

Example:

import Chinotto from "./lib/index.mjs";
Chinotto.register();