From 08de1bf77a87d04aba14c09a132b8b6fe58011d4 Mon Sep 17 00:00:00 2001 From: zebpaa Date: Mon, 8 Jul 2024 20:57:41 +0400 Subject: [PATCH] tried to edit tests --- __tests__/index.tests.js | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/__tests__/index.tests.js b/__tests__/index.tests.js index 9bbdfd5..59520cd 100644 --- a/__tests__/index.tests.js +++ b/__tests__/index.tests.js @@ -1,7 +1,7 @@ -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); @@ -9,11 +9,29 @@ 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); });