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

@kolcelabs/spec.js

v0.3.0

Published

Testing Library for JavaScript/TypeScript using Specification Files

Downloads

8

Readme

Installation

npm install -D @kolcelabs/spec.js

Workflow

To use Spec.js you can create specification files ending with any of the following patterns: *.spec.ts, *.spec.js. They can be located anywhere in your project but it's recommended to put them next to the source files being specified.

For example, suppose you have a src directory with a routes.js file, you can create a routes.spec.js file alongside and start the testing process with the specjs command.

specjs src

Writing Tests

Each test file must export a template literal. The general structure is as follows:

// feature.spec.ts file
export default `
  Specification Title

  Specification Body

  |- <assertion> <assertion description>
`

First line must will be taken as the specification title for this file, the next lines can be anything you want. In the text, any line starting with a turnstile (|-) will be taken as an assertion.

Assertions have the following structure:

|- <assertion> <assertion description>

Where assertion can be any JavaScript expression that evaluates to a boolean value. And assertion description can be any short string.

The following is an example of a specification file:

// example.spec.ts file
import dependency from './dependency'

export default `
  [TS] Example of a Specification File

  Spec.js allows to test JavaScript programs using specification files.

  Every *.spec.ts|js file exports a single template literal that includes a general
  explanation of the file being specified. Each file represents a logical
  component of a bigger system. Each logical component is composed of several
  units of functionality that can be tested for certain properties.

  Each one of this units of functionality may have one or more
  assertions.

  |- ${dependency} The dependency has been loaded and the first assert has
  been evaluated.

  Multiple assertions can be made for each file:

  |- ${false} This assertion will fail.

  |- ${1+1 === 2} This assertion is true.

  The combination of | and - will form a Turnstile ligature (|-) using the appropriate
  font. Fira Code is recommended. A Turnstile symbol was used by Gottlob Frege
  at the start of a sentence being asserted as true.

  The intended usage is specification-first software. Where the programmer
  defines the high level structure of a program in terms of a specification,
  then progressively builds the parts conforming that specification until all
  the tests are passed. A desired side-effect is having a simple way to generate
  up-to-date documentation outside the code for API consumers.
`

Executing the specjs <projectDir> command will test those assertions and return the results.

Testing Single Specification Files

If you want to test only a single specification file then instead of indicating a directory to the specjs command, you can indicate the path of the specification file you want to test.

specjs feature/myFunction.spec.js

Usage with TypeScript

You can run TypeScript files using the ts-node package. First install it as a development dependency:

npm install -D ts-node

And then run the specjs command with it:

ts-node node_modules/@kolcelabs/spec.js/dist/bin <projectDir>

License

MIT License - James Kolce