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

spekk

v0.3.1

Published

Javascript test runner for NodeJS applications

Downloads

11

Readme

Spekk

Javascript test runner for NodeJS applications.

Install

# Install globally
npm i -g spekk

# Install locally in app
npm i spekk

Usage

Add your tests in spec/tests. Data and test helpers can be added in spec/data and spec/lib respectively, they will be loaded automatically if they exist.

Optionally create a spekk file in spec/spekk.js. The spec/spekk.js file must export a function that returns a Javascript object with the things you need for your tests:

module.exports = async function() {
  // Set up db connection for example
  var db = await db({ name: 'spekk-test' })

  // Run before run if defined
  async function setup() {}

  // Run after run if defined
  async function teardown() {}

  return { db, setup, teardown }
}

Whatever the spekk file returns will be available in the tests:

// spec/tests/spec-test.js
it('should test something', async function({ t, db, data, lib }) {
  var user = await db('user').get()
  t.ok(user.id)
})

The t in the function above is included automatically and is Node assert.

There are some built in global functions you can use in your tests:

  • it or test- defines a test which will be run
  • xit or x - skips a test and does nothing
  • only or o - only these tests will be run
  • beforeEach - run before each test
  • afterEach - run after each test
  • beforeAll - run before all tests in a file
  • afterAll - run after all tests in a file

Run the tests with:

spekk

The name of the test will be taken from the file name, so if your test file is named project-test.js, then the test name will be Project Test.

This is a full example, stored in spec/tests/spekk-test.js:

// Setup is run before each test
beforeEach(async function({ t }){
  // Do something before each test
})

// This test is being run
it('should test it', async ({ t }) => {
  t.ok(true)
})

// This test is skipped
xit('should test it', async ({ t }) => {
  t.ok(true)
})

// Only this test will be run
only('should test it', async ({ t }) => {
  t.ok(true)
})

To run only certain tests, you can match with a regex pattern:

# Match any test file name that includes 'pattern'
spekk pattern

# Multiple patterns file, comma separated
spekk todo,project

If you want automatically run the tests when you save a file you can use nodemon:

nodemon --exec spekk

Add this to you package.json file to run with npm:

"scripts": {
  "test": "nodemon -q --exec spekk"
}

Then run with npm run test in your application.

MIT Licensed. Enjoy!