0.1.0 • Published 7 years ago

compare-dir-json v0.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

compare-dir-json

Expect a directory structure to match a specified result.

Install

$ npm install compare-dir-json --save

Usage

import {softCompare, hardCompare} from 'compare-dir-json';

const dirPath = './tests/fixtures/sample-dir';
const expectedResult = {
    'cat.md': true,
    'dog.md': true,
    empty: {},
    ignored: {'dog.md': true},
    nested: {'cat.md': true, 'dog.md': true},
    nonExistentFile: false
};


const result = softCompare(dirPath, expectedResult);
// result =>
// {
//     success: true,
//     error: null,
//     diff: [ Object<DeepDiff> ]
// }

API

General

Both compare functions take the same parameters as input and output the same formatted Object.

Input

dirPath: String

Path to directory.

expectedResult: Object

Expected Object tree, where keys hold the file name with value true, false, or {}:

ValueTypePurpose
trueFile should exist
falseFile should not exist
{}Directory

Output

{
    success: Boolean,
    error: String | null,
    diff: Array<DeepDiff>
}

diff: Array

An Array that holds deep-diff Objects. Showing the difference between the directory structure and the expectedResult.

softCompare(dirPath, expectedResult)

Files may be added, deleted if specified, but can not be altered.

hardCompare(dirPath, expectedResult)

The expectedResult should be the same as the directory structure.

License

MIT