From 5769c9ce5b3c6536f97fa9006494e639de8ed830 Mon Sep 17 00:00:00 2001 From: Ryan Mwangi Date: Thu, 21 Nov 2024 19:56:48 +0300 Subject: [PATCH] test: update imports and add ESM-compatible __dirname handling --- test/calendar.test.js | 8 +++++++- test/calendarUtil.test.js | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/test/calendar.test.js b/test/calendar.test.js index 4619b89..6f9614f 100644 --- a/test/calendar.test.js +++ b/test/calendar.test.js @@ -2,6 +2,12 @@ import request from 'supertest'; import express from 'express'; import fs from 'fs'; import path from 'path'; +import { jest } from '@jest/globals'; +import { fileURLToPath } from 'url'; + +// ESM equivalent of __dirname +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); const CALENDARS_DIR = path.join(__dirname, 'calendar'); const TEST_CALENDARS_DIR = path.join(__dirname, 'test_calendars'); @@ -10,7 +16,7 @@ const EXPECTED_OUTPUTS_DIR = path.join(__dirname, 'expected_outputs'); let server; process.chdir(__dirname) // console.log(process.cwd()); -const app = require('../src/server').default; +import app from '../src/server.js'; const normalizeLineEndings = (str) => str.replace(/\r\n/g, '\r\n').trimEnd(); // Normalize to CRLF diff --git a/test/calendarUtil.test.js b/test/calendarUtil.test.js index 63c30d0..9fd584a 100644 --- a/test/calendarUtil.test.js +++ b/test/calendarUtil.test.js @@ -2,6 +2,12 @@ import ICAL from '../src/lib/ical.timezones'; import fs from 'fs'; import path from 'path'; import axios from 'axios'; +import { jest } from '@jest/globals'; +import { fileURLToPath } from 'url'; + +// ESM equivalent of __dirname +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); // Describe the test suite for Calendar Utility Functions describe('Calendar Utility Functions', () => {