Giter VIP home page Giter VIP logo

spekk's Introduction

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
  const db = await db({ name: 'spekk-test' })

  // Run before each test if defined
  async function before() {}

  // Run after each test if defined
  async function after() {}

  return { db, before, after }
}

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 }) {
  const user = await db('user').get()
  t.ok(user.id)
})

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

There are 4 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
  • setup or s - run before each test

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
setup(async function({ t }){
  // Do some setup
})

// 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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.