Code Monkey home page Code Monkey logo

mocha-annotated's Introduction

mocha-annotated

Mocha but with tasks and feedback built into it!

Install

npm install nwronski/mocha-annotated

Use

mocha --reporter mocha-annotated/spec --require mocha-annotated/ui --bail --ui mocha-annotated 'src/**/*.spec.js'

Note: Use the --bail flag so that you see at most one feedback message per test run.

UI

The Mocha ui is mocha-annotated/ui and you can add it to your mocha options using:

--require mocha-annotated/ui 
--ui mocha-annotated

Reporters

Annotated spec reporter

--reporter mocha-annotated/spec

Annotated json reporter

--reporter mocha-annotated/json

Annotated json-stream reporter

--reporter mocha-annotated/json-stream

Profit

Use it.annotated(title, taskNumber, feedback, fn) in place of it(title, fn) to associate a task number and some descriptive feedback (preferably in markdown) with each test case.

Use strip_heredoc to format multi-line string templates by stripping leading whitespace, preserving newlines, and preserving indentation level. You do not need to import strip_heredoc, it is a part of the mocha-annotated UI.

For bonus fun, try using it.annotated.only(), xit.annotated(), and/or it.annotated.skip() just like you would with the normal it() blocks in your testing code!

import { expect } from 'chai';

describe('Beep#add', () => {
  it.annotated(
    // Test title
    'put a boop in the beep',
    // [Optional]: Test task number (1-based index)
    1,
    // The feedback to display when this specific test fails
    strip_heredoc`
      Whoops, we forgot to put a boop in our beep when \`fiddlesticks\` is _truthy_.
            
      \`\`\`typescript
      if (fiddlesticks) {
        beep.add('boop');
      }
      \`\`\`
    `,
    // The test function containing the expectations/assertions
    () => {
      expect(beep.things).to.include('boop');
    },
  );
});

At the end of your test output, you will see the feedback for any failing test(s):

Using the mocha-annotated/spec reporter

  1) Task 1: put a boop in the beep
      Whoops, we forgot to put a boop in our beep when `fiddlesticks` is _truthy_.
            
      ```typescript
      if (fiddlesticks) {
        beep.add('boop');
      }
      ```

Using the mocha-annotated/json reporter

{
  "stats": {},
  "failures": [
    {
      "title": "put a boop in the beep",
      "fullTitle": "Beep#add put a boop in the beep",
      "duration": 1,
      "currentRetry": 0,
      "err": {
        "message": "expected [] to include 'boop'",
        "stack":"AssertionError: expected [] to include 'boop'\n"
      }
    }
  ],
  "tests": [
    {
      "title": "put a boop in the beep",
      "fullTitle": "Beep#add put a boop in the beep",
      "duration": 1,
      "currentRetry": 0,
      "err": {
        "message": "expected [] to include 'boop'",
        "stack":"AssertionError: expected [] to include 'boop'\n"
      }
    }
  ],
  "passes": []
}

Using the mocha-annotated/json-stream reporter

[  
   "fail",
   {  
      "title": "put a boop in the beep",
      "task": 1,
      "feedback": "Whoops, we forgot to put a boop in our beep when `fiddlesticks` is _truthy_.\n\n```typescript\nif (fiddlesticks) {\n\tbeep.add('boop');\n}\n```",
      "fullTitle": "Beep#add put a boop in the beep",
      "duration": 1,
      "currentRetry": 0,
      "err": {
        "message": "expected [] to include 'boop'",
        "stack":"AssertionError: expected [] to include 'boop'\n"
      }
   }
]

mocha-annotated's People

Contributors

nwronski avatar

Watchers

 avatar

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.