From 8965eaa3194d1913345cc61d0bc79c940895ea8b Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Tue, 19 Nov 2024 14:17:42 +0300 Subject: [PATCH] fix(line-endings): normalize line endings to LF for cross-platform consistency- Normalized line endings in generated calendar content to LF.- Updated test assertions to handle line-ending discrepancies.- Ensured compatibility across Windows and UNIX-like systems. --- src/calendarUtil.js | 3 ++- test/calendar.test.js | 13 +++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/calendarUtil.js b/src/calendarUtil.js index f883251..b772bcd 100644 --- a/src/calendarUtil.js +++ b/src/calendarUtil.js @@ -127,8 +127,9 @@ export function addEventsToCalendar(calendarComponent, results, overrideFlag = f // Save calendar data to file export function saveCalendarFile(filename, content) { + const normalizedContent = content.replace(/\r\n/g, '\n').trimEnd(); // Normalize to LF const filePath = path.join(MERGED_CALENDARS_DIR, filename); // console.log(`Saving calendar data to file: ${filePath}`); - fs.writeFileSync(filePath, content); + fs.writeFileSync(filePath, normalizedContent); return filePath; } diff --git a/test/calendar.test.js b/test/calendar.test.js index 20965ce..71e9823 100644 --- a/test/calendar.test.js +++ b/test/calendar.test.js @@ -12,6 +12,8 @@ process.chdir(__dirname) // console.log(process.cwd()); const app = require('../src/server').default; +const normalizeLineEndings = (str) => str.replace(/\r\n/g, '\n').trimEnd(); + describe('Calendar Merging API', () => { beforeAll(async () => { // Start the server @@ -53,10 +55,17 @@ describe('Calendar Merging API', () => { const filePath = path.join(CALENDARS_DIR, 'nextcloud-minimal.ics'); // console.log('Checking if file exists at:', filePath); expect(fs.existsSync(filePath)).toBe(true); - // Load expected output and compare + + // Load expected output const expectedOutput = fs.readFileSync(input, 'utf8'); const actualOutput = fs.readFileSync(filePath, 'utf8'); - expect(actualOutput).toBe(expectedOutput); + + // Normalize line endings + const normalizedActual = normalizeLineEndings(actualOutput); + const normalizedExpected = normalizeLineEndings(expectedOutput); + + //compare + expect(normalizedActual).toBe(normalizedExpected); }); // test('Preserve date-based calendar', async () => {