Skip to content

Commit

Permalink
back to one default function from index.js module, violates purity, b…
Browse files Browse the repository at this point in the history
…ut who cares
  • Loading branch information
gonpaul committed May 29, 2024
1 parent bd8fb1a commit c344562
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
16 changes: 8 additions & 8 deletions __tests__/gendiff.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { genDiff as gendiff } from '../index.js';
import genDiff from '../index.js';

const answerStylish = `{
common: {
Expand Down Expand Up @@ -174,29 +174,29 @@ const answerJson = `[
}
]`;
test('json stylish format test 1', () => {
expect(gendiff('file1.json', 'file2.json', 'stylish')).toBe(answerStylish);
expect(genDiff('file1.json', 'file2.json', 'stylish')).toBe(answerStylish);
});

test('yaml stylish format test 2', () => {
expect(gendiff('file1.yml', 'file2.yml', 'stylish')).toBe(answerStylish);
expect(genDiff('file1.yml', 'file2.yml', 'stylish')).toBe(answerStylish);
});

test('json-yaml stylish format test 3', () => {
expect(gendiff('file1.json', 'file2.yml', 'stylish')).toBe(answerStylish);
expect(genDiff('file1.json', 'file2.yml', 'stylish')).toBe(answerStylish);
});

test('json plain format test 1', () => {
expect(gendiff('file1.json', 'file2.json', 'plain')).toBe(answerPlain);
expect(genDiff('file1.json', 'file2.json', 'plain')).toBe(answerPlain);
});

test('yaml plain format test 2', () => {
expect(gendiff('file1.yml', 'file2.yml', 'plain')).toBe(answerPlain);
expect(genDiff('file1.yml', 'file2.yml', 'plain')).toBe(answerPlain);
});

test('json-yaml plain format test 3', () => {
expect(gendiff('file1.json', 'file2.yml', 'plain')).toBe(answerPlain);
expect(genDiff('file1.json', 'file2.yml', 'plain')).toBe(answerPlain);
});

test('json format test', () => {
expect(gendiff('file1.json', 'file2.yml', 'json')).toBe(answerJson);
expect(genDiff('file1.json', 'file2.yml', 'json')).toBe(answerJson);
});
2 changes: 1 addition & 1 deletion bin/genDiff.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

import { program } from 'commander';
import { cliMain as genDiff } from '../index.js';
import genDiff from '../index.js';

program
.name('gendiff')
Expand Down
8 changes: 2 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,8 @@ const genDiff = (path1, path2, format = 'stylish') => {
const diff = generateDiff(data1, data2);
// console.log(diff);
const formattedDiff = formatFunc(diff);
console.log(formattedDiff);
return formattedDiff;
};

const cliMain = (path1, path2, format = 'stylish') => {
console.log(genDiff(path1, path2, format));
return 0;
};

export { genDiff, cliMain };
export default genDiff;

0 comments on commit c344562

Please sign in to comment.