Skip to content

Mocha's diff algorithm extracted for anyone to use 🎉

Notifications You must be signed in to change notification settings

mainmatter/mocha-diff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mocha-diff

This lib is an extraction of Mocha's diff implementation

Why did I want to extract Mocha's implementation? Because of this line:

Mocha’s own diff output does not conform to any known standards, and is designed to be human-readable.

Installation

npm install mocha-diff

Usage

import { generateDiff } from 'mocha-diff';

console.log(generateDiff(actual, expected));

Example output

      + expected - actual

       function aVeryNiceTestFunction() {
      -  console.log('I really should impolement something here');
      -  console.log('I really should impolement something here');
      -  console.log('I really should impolement something here');
      -  console.log('I really should impolement something here');
      -  console.log('I really should impolement something here');
      +  console.log('I really should implement something here');
      +  console.log('I really should implement something here');
       }
       
       function badlyIndented() {
         let items = [
           'one',
      -      'two',
      +    'two',
           'three',
      -  'four',
      -    'five'
      +    'four',
      +    'five',
         ];
       }
      -
      -function possiblyMissing() {
      -  console.log('a very important function');
      -}

The implementation also supports colours if your terminal supports colours:

Screenshot 2023-03-19 at 10 44 35

About

Mocha's diff algorithm extracted for anyone to use 🎉

Resources

Stars

Watchers

Forks

Packages

No packages published