Code Monkey home page Code Monkey logo

qunit-metadata's Introduction

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

qunit-metadata's People

Contributors

dependabot-support avatar ember-tomster avatar mike-north avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

qunit-metadata's Issues

Why?

This looks really neat! The README does a great job of explaining "how" to use the library, but doesn't seem to touch at all on "why" you would...

Maybe there is room for a small motivating example showing how it is useful to have additional metadata?

Dependency deprecation warning: travis-deploy-once (npm)

On registry https://registry.npmjs.org/, the "latest" version (v5.0.11) of dependency travis-deploy-once has the following deprecation notice:

We recommend to use Travis Build Stages instead

Marking the latest version of an npm package as deprecated results in the entire package being considered deprecated, so contact the package author you think this is a mistake.

Affected package file(s): package.json

If you don't care about this, you can close this issue and not be warned about travis-deploy-once's deprecation again. If you would like to completely disable all future deprecation warnings then add the following to your config:

"suppressNotifications": ["deprecationWarningIssues"]

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: Using npm packages for Renovate presets is now deprecated. Please migrate to repository-based presets instead.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm travis-deploy-once Unavailable
npm tslint Unavailable

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): husky
  • chore: lockfile maintenance
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • object-predicate ^1.2.0
  • @commitlint/cli 8.3.6
  • @commitlint/config-conventional 8.3.6
  • @commitlint/travis-cli 8.3.6
  • @mike-north/js-lib-renovate-config 1.3.1
  • @mike-north/js-lib-semantic-release-config 1.0.1
  • @types/qunit 2.5.4
  • ember-cli 4.1.0
  • husky 2.4.1
  • qunit-decorators 1.1.5
  • qunit 2.17.2
  • semantic-release 15.12.5
  • shelljs 0.8.5
  • travis-deploy-once 5.0.11
  • ts-std 0.7.0
  • tslint 5.17.0
  • typescript 3.5.3
travis
.travis.yml
  • node 10
  • node 8

  • Check this box to trigger a request for Renovate to run again on this repository

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.