Skip to content

Commit

Permalink
tried to edit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zebpaa committed Jul 8, 2024
1 parent f9131cc commit 08de1bf
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions __tests__/index.tests.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
import fs from 'fs';
import { fileURLToPath } from 'url';
import path, { dirname } from 'path';
import gendiff from '../index.js';
import { fileURLToPath } from 'url';
import fs from 'node:fs';
import genDiff from '../index.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const getFixturePath = (filename) => path.join(__dirname, '..', '__fixtures__', filename);
const readFile = (filename) => fs.readFileSync(getFixturePath(filename), 'utf-8');

test.each(['json', 'yml', 'yaml'])('gendiff_test_format', (format) => {
const filepath1 = getFixturePath(`file1.${format}`);
const filepath2 = getFixturePath(`file2.${format}`);
expect(gendiff(filepath1, filepath2)).toEqual(readFile('expectedStylish.txt'));
expect(gendiff(filepath1, filepath2, 'stylish')).toEqual(readFile('expectedStylish.txt'));
expect(gendiff(filepath1, filepath2, 'plain')).toEqual(readFile('expectedPlain.txt'));
expect(gendiff(filepath1, filepath2, 'json')).toEqual(readFile('expectedJson.json'));
let pathToFile1;
let pathToFile2;
let pathToFile3;
let pathToFile4;
let resultPlainFormat;
let resultStylishFormat;
beforeAll(() => {
pathToFile1 = getFixturePath('file1.json');
pathToFile2 = getFixturePath('file2.json');
pathToFile3 = getFixturePath('file1.yml');
pathToFile4 = getFixturePath('file2.yml');
resultPlainFormat = readFile('expectedPlain.txt');
resultStylishFormat = readFile('expectedStylish.txt');
});

test('test genDiff to work with stylish format', () => {
expect(genDiff(pathToFile1, pathToFile2)).toBe(resultStylishFormat);

expect(genDiff(pathToFile3, pathToFile4)).toBe(resultStylishFormat);
});

test('test genDiff to work with plain format', () => {
expect(genDiff(pathToFile1, pathToFile2, 'plain')).toBe(resultPlainFormat);

expect(genDiff(pathToFile3, pathToFile4, 'plain')).toBe(resultPlainFormat);
});

0 comments on commit 08de1bf

Please sign in to comment.