All Projects → adamgruber → Mochawesome

adamgruber / Mochawesome

Licence: mit
A Gorgeous HTML/CSS Reporter for Mocha.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Mochawesome

Public
Repository for wallaby.js questions and issues
Stars: ✭ 662 (-23.02%)
Mutual labels:  tdd, mocha
Testdeck
Object oriented testing
Stars: ✭ 206 (-76.05%)
Mutual labels:  tdd, mocha
Cracking The Coding Interview Javascript Solutions Ctci
Javascript solutions to Cracking the Coding Interview (CTCI)
Stars: ✭ 139 (-83.84%)
Mutual labels:  tdd, mocha
Mochawesome Report Generator
Standalone mochawesome report generator. Just add test data.
Stars: ✭ 152 (-82.33%)
Mutual labels:  tdd, mocha
Helm Test
A mocha based testing CLI for helm packages
Stars: ✭ 22 (-97.44%)
Mutual labels:  tdd, mocha
Snap Shot It
Smarter snapshot utility for Mocha and BDD test runners + data-driven testing!
Stars: ✭ 138 (-83.95%)
Mutual labels:  tdd, mocha
Karma
Spectacular Test Runner for JavaScript
Stars: ✭ 11,591 (+1247.79%)
Mutual labels:  tdd, mocha
Should Enzyme
Useful functions for testing React Components with Enzyme.
Stars: ✭ 41 (-95.23%)
Mutual labels:  tdd, mocha
mocha-cakes-2
A BDD plugin for Mocha testing framework
Stars: ✭ 44 (-94.88%)
Mutual labels:  mocha, tdd
chai-exclude
Exclude keys to compare from a deep equal operation with chai expect or assert.
Stars: ✭ 33 (-96.16%)
Mutual labels:  mocha, tdd
Nspec
A battle hardened testing framework for C# that's heavily inspired by Mocha and RSpec.
Stars: ✭ 242 (-71.86%)
Mutual labels:  tdd, mocha
Baretest
An extremely fast and simple JavaScript test runner.
Stars: ✭ 364 (-57.67%)
Mutual labels:  tdd, mocha
xv
❌ ✔️ zero-config test runner for simple projects
Stars: ✭ 588 (-31.63%)
Mutual labels:  mocha, tdd
Mocha
☕️ simple, flexible, fun javascript test framework for node.js & the browser
Stars: ✭ 20,986 (+2340.23%)
Mutual labels:  tdd, mocha
Mix Test.watch
🎠 Because TDD is awesome
Stars: ✭ 721 (-16.16%)
Mutual labels:  tdd
Aruba
Test command-line applications with Cucumber-Ruby, RSpec or Minitest. The most up to date documentation can be found on Cucumber.Pro (https://app.cucumber.pro/projects/aruba)
Stars: ✭ 900 (+4.65%)
Mutual labels:  tdd
Vue Webpack Typescript
A Vue, Webpack, Typescript, Bootstrap setup with hot reload, dynamic imports, unit testing, code coverage, sass, uncss and bundling/minification.
Stars: ✭ 677 (-21.28%)
Mutual labels:  mocha
Javascript Data Structures And Algorithms
Exercises, algorithms
Stars: ✭ 26 (-96.98%)
Mutual labels:  tdd
Calc
Unit Testing in JavaScript
Stars: ✭ 17 (-98.02%)
Mutual labels:  mocha
Vue Testing Handbook
A guide on testing Vue components and applications
Stars: ✭ 669 (-22.21%)
Mutual labels:  tdd

mochawesome

npm Node.js CI Gitter

Mochawesome is a custom reporter for use with the Javascript testing framework, mocha. It runs on Node.js (>=10) and works in conjunction with mochawesome-report-generator to generate a standalone HTML/CSS report to help visualize your test runs.

Features

Mochawesome Report
  • Simple, clean, and modern design
  • Beautiful charts (via ChartJS)
  • Support for test and suite nesting
  • Displays before and after hooks
  • Review test code inline
  • Stack trace for failed tests
  • Support for adding context information to tests
  • Filters to display only the tests you want
  • Responsive and mobile-friendly
  • Offline viewing
  • Supports parallel mode

Usage

  1. Add Mochawesome to your project:

npm install --save-dev mochawesome

  1. Tell mocha to use the Mochawesome reporter:

mocha testfile.js --reporter mochawesome

  1. If using mocha programatically:
var mocha = new Mocha({
  reporter: 'mochawesome',
});

Parallel Mode

Since [email protected] test files can be run in parallel using the --parallel flag. In order for mochawesome to work properly it needs to be registered as a hook.

mocha tests --reporter mochawesome --require mochawesome/register

Due to differences in how parallel tests are processed, statistics may differ between sequential and parallel test runs. Mocha does not provide information about skipped tests in parallel mode. For more information, see https://mochajs.org/#parallel-tests.

Output

Mochawesome generates the following inside your project directory:

mochawesome-report/
├── assets
│   ├── app.css
│   ├── app.js
│   ├── MaterialIcons-Regular.woff
│   ├── MaterialIcons-Regular.woff2
│   ├── roboto-light-webfont.woff
│   ├── roboto-light-webfont.woff2
│   ├── roboto-medium-webfont.woff
│   ├── roboto-medium-webfont.woff2
│   ├── roboto-regular-webfont.woff
│   └── roboto-regular-webfont.woff2
├── mochawesome.html
└── mochawesome.json

The two main files to be aware of are:

mochawesome.html - The rendered report file

mochawesome.json - The raw json output used to render the report

Options

Options can be passed to the reporter in two ways.

Environment variables

The reporter will try to read environment variables that begin with MOCHAWESOME_.

$ export MOCHAWESOME_REPORTFILENAME=customReportFilename

Note that environment variables must be in uppercase.

Mocha reporter-options

You can pass comma-separated options to the reporter via mocha's --reporter-options flag. Options passed this way will take precedence over environment variables.

$ mocha test.js --reporter mochawesome --reporter-options reportDir=customReportDir,reportFilename=customReportFilename

Alternately, reporter-options can be passed in programatically:

var mocha = new Mocha({
  reporter: 'mochawesome',
  reporterOptions: {
    reportFilename: 'customReportFilename',
    quiet: true,
  },
});

Available Options

The options below are specific to the reporter. For a list of all available options see mochawesome-report-generator options.

Option Name Type Default Description
quiet boolean false Silence console messages
reportFilename string mochawesome Filename of saved report
Applies to the generated html and json files.
html boolean true Save the HTML output for the test run
json boolean true Save the JSON output for the test run
consoleReporter string spec Name of mocha reporter to use for console output, or none to disable console report output entirely

Adding Test Context

Mochawesome ships with an addContext helper method that can be used to associate additional information with a test. This information will then be displayed inside the report.

Please note: arrow functions will not work with addContext. See the example.

addContext(testObj, context)

param type description
testObj object The test object
context string|object The context to be added to the test

Context as a string

Simple strings will be displayed as is. If you pass a URL, the reporter will attempt to turn it into a link. If the URL links to an image or video, it will be shown inline.

Context as an object

Context passed as an object must adhere to the following shape:

{
  title: 'some title'; // must be a string
  value: {
  } // can be anything
}

Example

Be sure to use ES5 functions and not ES6 arrow functions when using addContext to ensure this references the test object.

const addContext = require('mochawesome/addContext');

describe('test suite', function () {
  it('should add context', function () {
    // context can be a simple string
    addContext(this, 'simple string');

    // context can be a url and the report will create a link
    addContext(this, 'http://www.url.com/pathname');

    // context can be an image url and the report will show it inline
    addContext(this, 'http://www.url.com/screenshot-maybe.jpg');

    // context can be an object with title and value properties
    addContext(this, {
      title: 'expected output',
      value: {
        a: 1,
        b: '2',
        c: 'd',
      },
    });
  });
});

It is also possible to use addContext from within a beforeEach or afterEach test hook.

describe('test suite', () => {
  beforeEach(function () {
    addContext(this, 'some context');
  });

  afterEach(function () {
    addContext(this, {
      title: 'afterEach context',
      value: { a: 1 },
    });
  });

  it('should display with beforeEach and afterEach context', () => {
    // assert something
  });
});

Related

mochawesome-report-generator

License

mochawesome is MIT licensed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].