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.

This commit is contained in:
Ryan Mwangi 2024-11-19 14:17:42 +03:00
parent ca52065f66
commit 8965eaa319
2 changed files with 13 additions and 3 deletions

View File

@ -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;
}

View File

@ -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 () => {