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

qunit-metadata

v1.3.1

Published

Add metadata to your QUnit test suite

Downloads

8

Readme

qunit-metadata

Add metadata to your QUnit tests, with your choice of ES5, ES6 or TypeScript syntax

Build Status Version

Why might you want to use this library

Motivations for associating metadata with tests includes

  • Running a subset of tests, which match a particular criteria
    • All acceptance tests, except those which involve mutating data
    • All tests that involve a particular UI component
    • (In a training workshop) all tests that are flagged with level === 'beginner'
  • Gathering data on a subset of tests, before during or after a run
    • (In a training workshop) Attach points: number to tests in modules, and display the student's "score" based on how many tests their code passes
    • After a test run, storing elapsed time for each test to disk, for comparison against future test runs.

QUnit is very limited in terms of being able to attach some of these kinds of data to tests in a sustainable way. The best you can do is apply something like a hashtag, or invent your own microsyntax (all of which would be placed in the test/module titles). This library appends custom metadata as a JavaScript object to QUnit's own data structures, allowing for greater flexibility and maintainability.

Setup

Step 1: Install

Install this library in your project. If you use npm

npm install --save-dev qunit-metadata

or if you use yarn

yarn add -D qunit-metadata

Step 2: Enhance QUnit

Augment QUnit with metadata support

import QUnit from 'qunit';
import qunitMetadata from 'qunit-metadata';

qunitMetadata(QUnit);

Adding metadata to your tests

This library works well with qunit-decorators. Metadata can be added to suites or tests by passing arguments to the respective decorators

import { suite, test } from 'qunit-decorators';

@suite('A description for my suite', { writtenBy: 'Mike' }/* <-- module metadata */)
class MyTests {

  @test('Make sure 1 is more than 0', { toRemove: true }/* <-- test metadata */)
  verifyOne(assert: Assert) {
    assert.ok(1 > 0, 'One should be more than zero');
  }
}

If you prefer to use this library without decorators, you are free to do so

import { module, test } from 'qunit';

module('A description for my suite')
  .meta({ writtenBy: 'Mike' });/* <-- module metadata */

test('Make sure 1 is more than 0', assert => {
  assert.ok(1 > 0, 'One should be more than zero');
}).meta({ toRemove: true });/* <-- test metadata */

or the more modern "nested" syntax

import { module, test } from 'qunit';

module('A description for my suite', hooks => {
  
  test('Make sure 1 is more than 0', assert => {
    assert.ok(1 > 0, 'One should be more than zero');
  }).meta({ toRemove: true });/* <-- test metadata */

})
.meta({ writtenBy: 'Mike' });/* <-- module metadata */

Retrieving Metadata

This library comes with a family of functions you can use to retrieve data

import {
  getAllModuleData,  // get information about a collection of modules
  getAllTestData,    // get information about a collection of tests
  getModuleData,     // get information about a single module
  getTestData        // get information about a single test
} from 'qunit-metadata';

All four of these functions take a single argument: an object that's used to describe the desired condition for the item or subset of interest using strings, regular expressions and/or predicates. You may filter on multiple properties if you wish

Example: Find all tests with metadata { toRemove: true }

let testsToRemove = getAllTestData({
  meta: tst => tst.toRemove === true
});

Example: Find tests whose name contains the word "interesting"`

let testsToRemove = getAllTestData({
  name: /interesting/
});

Example: Find a module whose name is "Authentication tests"`

let testsToRemove = getAllModuleData({
  name: "Authentication tests"
});

What does the data look like?

I plan to add more later, but for now it looks like

interface QUnitModuleDetails {
  meta: { [k: string]: any };
  moduleId: string;
  name: string;
  parentModule: string;
  skip?: boolean;
  stats?: { all: number, bad: number, started: number};
  suiteReport?: SuiteReport;
  tests: QUnitTestDetails[];
  testsRun?: number;
  unskippedTestsRun?: number;
}

interface QUnitTestDetails {
  meta: { [k: string]: any };
  module: string;
  name: string;
  testId: string;
}

interface SuiteReport {
  fullName: string[];
  name: string;
  tests: TestReport[];
}

interface TestReport {
  assertions: AssertionReport[];
  fullName: string[];
  name: string;
  runtime: number;
  skipped: boolean;
  todo: boolean;
  valid: boolean;
}

interface AssertionReport {
  message: string;
  passed: boolean;
  todo: boolean;
}

Copyright

(c) 2018 LinkedIn