All Projects → mradionov → karma-jasmine-diff-reporter

mradionov / karma-jasmine-diff-reporter

Licence: MIT License
Diff and pretty print for failed tests

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to karma-jasmine-diff-reporter

tv
📺(tv) Tidy Viewer is a cross-platform CLI csv pretty printer that uses column styling to maximize viewer enjoyment.
Stars: ✭ 1,763 (+5587.1%)
Mutual labels:  pretty-print
jasmine-marbles
Marble testing helpers for RxJS and Jasmine
Stars: ✭ 102 (+229.03%)
Mutual labels:  jasmine
metadatamanagement
Metadatamanagement (MDM) - Data Search for Higher Education Research and Science Studies
Stars: ✭ 21 (-32.26%)
Mutual labels:  jasmine
jsonpp-rs
UNIX style tool to pretty print json
Stars: ✭ 26 (-16.13%)
Mutual labels:  pretty-print
wdio-jasmine-framework
A WebdriverIO v4 plugin. Adapter for Jasmine testing framework.
Stars: ✭ 22 (-29.03%)
Mutual labels:  jasmine
prism-pretty
A Chrome Extension to format/highlight/preview HTML/JS/CSS/Markdown code with Prism.js
Stars: ✭ 91 (+193.55%)
Mutual labels:  pretty-print
ts-node-starter
GitHub template to get started with Node.js & TypeScript. ⚡
Stars: ✭ 28 (-9.68%)
Mutual labels:  jasmine
SITreg
SAP Event Registration app backend
Stars: ✭ 26 (-16.13%)
Mutual labels:  jasmine
karma-nested-reporter
Easy to read test output with nested describe and it blocks
Stars: ✭ 14 (-54.84%)
Mutual labels:  karma-reporter
jsoncat
Json pretty-print parser based on a recursive lexical analyser
Stars: ✭ 26 (-16.13%)
Mutual labels:  pretty-print
karma-expect
Expect.js adapter for Karma test runner
Stars: ✭ 12 (-61.29%)
Mutual labels:  karma-plugin
json-viewer
Pretty JSON viewer for the terminal
Stars: ✭ 26 (-16.13%)
Mutual labels:  pretty-print
angular-material-boilerplate
A straightforward and well structured boilerplate based on Google's Angular Material project.
Stars: ✭ 28 (-9.68%)
Mutual labels:  jasmine
hgrep
Grep with human-friendly search results
Stars: ✭ 335 (+980.65%)
Mutual labels:  pretty-print
eslint-config-adjunct
A reasonable collection of plugins to use alongside your main esLint configuration
Stars: ✭ 39 (+25.81%)
Mutual labels:  jasmine
aurelia-typescript-boilerplate
A starter kit for building a standard navigation-style app with Aurelia, typescript and webpack by @w3tecch
Stars: ✭ 18 (-41.94%)
Mutual labels:  jasmine
jsonlint
JSON/CJSON/JSON5 parser, syntax & schema validator and pretty-printer with a command-line client, written in pure JavaScript.
Stars: ✭ 21 (-32.26%)
Mutual labels:  pretty-print
eslint-plugin-jasmine
ESLint rules for Jasmine
Stars: ✭ 91 (+193.55%)
Mutual labels:  jasmine
eq
jq, but for EDN.
Stars: ✭ 23 (-25.81%)
Mutual labels:  pretty-print
angular-unit-testing-examples
Showroom for different Angular unit testing concepts
Stars: ✭ 19 (-38.71%)
Mutual labels:  jasmine

karma-jasmine-diff-reporter Build status

Diff and pretty print for failed tests.

Example

Important

The goal of the reporter is to add user-friendly diff highlighting for complex nested structures. Jasmine 2.6 introduced it's own solution, which conflicts with the reporter original intent. When used, reporter will override Jasmine output in order to enchance it.

Install

npm install karma-jasmine-diff-reporter --save-dev

Add reporter to karma config file:

// karma.conf.js
module.exports = function(config) {
  config.set({
    reporters: ['jasmine-diff']
  });
};

You can use it together with another reporters, which tweak the output - just place them after:

reporters: ['jasmine-diff', 'progress']

Some specific reporters might break because of how the output is changed, make sure to place them before:

reporters: ['junit', 'jasmine-diff']

If you have plugins option overriden, make sure to add the reporter in there too (Karma/Loading Plugins)

// karma.conf.js
module.exports = function(config) {
  config.set({
    reporters: ['jasmine-diff'],
    plugins: [
      'karma-jasmine-diff-reporter'
    ]
  });
};

Options

Default options:

// karma.conf.js
module.exports = function(config) {
  config.set({
    jasmineDiffReporter: {
      color: {
        expectedBg: 'bgRed',
        expectedWhitespaceBg: 'bgRed',
        expectedFg: 'white',

        actualBg: 'bgGreen',
        actualWhitespaceBg: 'bgGreen',
        actualFg: 'white',

        warningBg: 'bgYellow',
        warningWhitespaceBg: 'bgYellow',
        warningFg: 'white',

        defaultBg: '',
        defaultFg: ''
      },
      pretty: false,
      multiline: false,
      verbose: true,
      matchers: {}
    }
  });
};

color

  • expected* - colors for test expectations
  • actual* - colors for actual results
  • warning* - values which reporter could not fully diff and they are worth attention
  • default* - text of the value which was not highlighted with any of the above colors

You can use any colors that a supported by chalk.

If karma config option colors: false is set, then reporter will ignore any custom colors and display diffs in inverse color of the terminal. (see output example).

To use default terminal color for any of the option just provide an empty string ('') as a value.

pretty

Values in objects and arrays will be indented depending on the nesting level. (see output example)

Disabled by default. To enable:

  • pretty: true - 2 spaces for indent level
  • pretty: 4 - number of spaces per level
  • pretty: '\t' - string per level

multiline

Adds extra newlines to separate Jasmine matcher text from actual values. (see output example)

Disabled by default. To enable:

  • multiline: true - 2 newlines before and after the value + 2 spaces of indentation.

  • Each option can configured using numbers (number of newlines/spaces) and strings.

    multiline: {
      before: 3,    // 3 newlines
      after: '\n',  // 1 newline
      indent: '  '  // 2 spaces
    }

verbose

If turned off, reduces the output by cutting of some Jasmine-specific syntax.

Enabled by default, which means nothing is cut off. To disable:

  • verbose: false - remove all extra Jasmine syntax

  • Detailed configuration:

    verbose: {
      object: false
    }
    • object - Jasmine wraps objects - Object({ foo: 42 }), if set to false objects will be displayed without this wrapper - { foo: 42 }.

matchers

By default only Jasmine core matchers are supported. Use this option to add any custom matchers so they could be correctly parsed and highlighted as well.

matchers: {
  toLookTheSameAs: {
    pattern: /Expected ([\S\s]*) to look the same as ([\S\s]*)\./,
    reverse: true,
    format: 'complex'
  }
}
  • pattern (required) - pattern to parse a failure message. It must have two capturing groups, which will capture actual and expected values. Suggested regular expression for capturing group is [\S\s]*, which will capture all characters including whitespaces.
  • reverse (optional) - if set to true, then the colors, which are used to highlight actual and expected values will be swapped. By default, first capturing group stands for expected value and second - for actual value.
  • format (optional) - accepts either a string or a function. String specifies which diff algorithm to use. Available algorithms are:
    • complex (default) - values are deeply parsed and analyzed, diffed parts get highlighted
    • full - highlights the entire values in their appropriate colors
    • multiple - internal option for values which hold multiple arrays
    • passthru - nothing is diffed and highlighted
    • primitive - values are diffed and highlighted as raw strings
    • warning - highlights the entire values in warning colors

Take a look at the definitions of in-built matchers to have a better understaning.

Support

  • node.js >= 6
  • jasmine >= 2
  • karma >= 0.9
  • karma-jasmine >= 0.3

Pitfalls

Diffs won't be displayed for a deep nested objects or large arrays, a threshold for these situations is configured in Jasmine. By default it has object nest level MAX_PRETTY_PRINT_DEPTH = 40 and array length MAX_PRETTY_PRINT_ARRAY_LENGTH = 100. It means that if the diff is out of these bounds, then Jasmine will return the same strings for both compared objects and the reporter won't be able to highlight those diffs.

License

MIT

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].