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

taf

v1.0.1

Published

Test Runner for JavaScript

Downloads

6

Readme

TAF

TAF is a test runner for JavaScript.

Getting started

Install TAF

npm install -g taf

1. Simple tests

1.1 Create tests in tests folder

Each test method name should start with test.

const assert = require('assert')

class TestOne {
    testAlwaysPassingTest1() {
        return async () => {
            assert.equal(1, 1, "Equals")
        }
    }
    testAlwaysFailingTest1() {
    	return async () => {
    	    assert.equal(1, 2)
    	}
    }
    testAlwaysBrokenTest1() {
        return async () => {
            throw Error('AlwaysBrokenTest')
        }
    }
}

module.exports = TestOne

1.2 Run tests

taf --tests ./tests

2. Tests with properties

2.1 Create tests with properties

const assert = require('assert')

class TestTwo {
    testAlwaysPassingTest2(testProperties) {
        testProperties.severity = 'Blocker'
        return async () => {
            assert.equal(1, 1, "Equals")
        }
    }
    testAlwaysFailingTest2(testProperties) {
        testProperties.severity = 'Major'
        return async () => {
            assert.equal(1, 2)
        }
    }
    testAlwaysBrokenTest2(testProperties) {
        testProperties.severity = 'Minor'
        return async () => {
            throw Error('AlwaysBrokenTest')
        }
    }
}

module.exports = TestTwo

2.2 Create test suite blocker.suite in suites folder

By default tests are run in one thread, to override this setting add threadCount to test suite.

To select tests which have severity Blocker define query method. This method will be called with tests parameter which is array of all tests from tests folder. This method should return array of tests to be run as suite.

module.exports = {
    threadCount: 2,
    query(tests) {
       return tests.filter(test => test.severity === 'Blocker')
    }
}

2.3 Run test suite

taf --tests ./tests --suite ./suites/blocker.suite.js

3. Tests with context

3.1 Create tests with context

Each test body is now have testContext parameter. This parameter is object passed to each test.

const assert = require('assert')

class TestThree {
    testAlwaysPassingTest3(testProperties) {
        testProperties.severity = 'Blocker'
        testProperties.withContext = true
        return async (testContext) => {
            const {value} = testContext
            assert.equal(value, 1)
        }
    }
    testAlwaysFailingTest3(testProperties) {
        testProperties.severity = 'Major'
        testProperties.withContext = true
        return async (testContext) => {
            const {value} = testContext
            assert.equal(value, 2)
        }
    }
}

module.exports = TestThree

3.2 Create context provider

Context provider class should have getContext method. This method will be called with context parameter which contains default context. In this method we can extend the default context by adding more properties. For this example the property is value. Method getContext is going to be called before each test and result of this method will be injected into test.

class TestContext {
    getContext(context) {
        context.value = 1
        return context
    }
}

module.exports = TestContext

3.3 Create test suite context.suite in suites folder

module.exports = {
    threadCount: 2,
    query(tests) {
        return tests.filter(test => test.withContext)
    }
}

3.4 Run test suite with context

taf --tests ./tests --suite ./suites/context.suite.js --context ./context/test.context.js

4. Configuration

It is possible to put all command-line arguments into config file.

4.1 Create config file

module.exports = {
    tests: './tests',
    suite: './suites/context.suite',
    context: './context/test.context'
}

4.2 Run tests

taf --config config.js

5.Examples

See code for this Getting Started: https://github.com/georgiik/taf_examples