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

test-categories

v0.5.0

Published

This module allows you to add category names to Jasmine or Mocha tests and configure which categories run in each environment.

Downloads

57

Readme

Test Categories for Jasmin and Mocha

This module allows you to add category names to Jasmine or Mocha tests and configure which categories run in each environment.

it(testName`[commit, acceptance, smoke] should run under three different categories`)

It's more flexible than grouping testing in spec files and it provides error checking (typos in category names) that is missing when using --grep test name matching alone.

Start by configuring all the environments you have, adding the categories you want to run under each environment. Then attach multiple categories to each test.

The error checking will highlight any test category that doesn't match those in your configured environments. This helps ensure tests aren't being disabled just because of typos.

Getting Started

Add the environment and category configuration to your tests.

Here we add it at the top of our Protractor configuration but you can add the same to a single test spec file or anything that will run before your tests.

var testCategoriesSetup = require('test-categories').testCategoriesSetup;

exports.config = {
    capabilities: {
        browserName: 'chrome'
    },
    specs: ['*.spec.js'],
    onPrepare: function() {
        //In Protractor we can run `testCategoriesSetup` in the onPrepare
        testCategoriesSetup({
            environments: {
                    local: ['commit'],
                    systest: ['smoke','acceptance'],
                    live: ['smoke']
                },
            currentEnvironment: browser.params.environment, //Sets the current environment via Protractor's params
            grepFlag: '@@@' //This is a string we will prefix to all the tests we want to run
        });
    }
};

Then we add the template literal tag to any of the tests we want to give categories.

import {testName} from "test-categories";

describe('some tests marked with various categories', () => {
    it(testName`[commit, acceptance, smoke] should run in local environment`, () => {
        expect(true).toBe(true);
    });
    it(testName`[acceptance, smoke] should not run in local environment`, () => {
        expect(true).toBe(true);
    });
    it(testName`[commit, unknown] should flag unknown category but still run in local environment`, () => {
        expect(true).toBe(true);
    });
});

Finally we run our tests passing the grepFlag to the --grep argument of Jasmine Node, Mocha or in this example Protractor.

protractor myconfig.js --grep @@@ --params.environment=local

Prerequisites

This library will work with any test framework the uses strings as test names and can disabled tests via string matching (i.e. node-jasmine's --grep).

Installing

npm install test-categories

Config

  • environments: An object containing all the environments and their associated categories. The keys are the environment names and the value is an array strings that are categories. You must list all the environments\categories you use so the library can check for errors. If you have multiple spec files it is best you share this object in a module.
  • currentEnvironment: The name of the current environment you are running the tests in. As you are likely to run the same spec file in multiple environments it is best to pass this in from the command line i.e. browser.params.myEnvironment if you were using Protractor.
  • grepFlag: This string will be prefixed to all test names that should be run. It's will be visible in your tests reports. So it's best to keep it short.
{
    environments: {
        [key: string]: string[]
    },
    currentEnvironment: string,
    grepFlag: string
}

Running the example

There is an example in the example-tests folder. To run it download the source, do npm install and then

npm run example-tests

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MIT License - see choosealicense.com/licenses/mit/ file for details