Skip to content

fix: use proper ESM with jest #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default defineConfig([
"coverage",
"global.d.ts",
"eslint.config.js",
"jest.config.js",
"jest.config.ts",
]),
eslintPluginPrettierRecommended,
]);
2 changes: 1 addition & 1 deletion jest.config.js → jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default {
"ts-jest",
{
useESM: true,
tsconfig: "tsconfig.jest.json", // Use specific tsconfig file for Jest
tsconfig: "tsconfig.jest.json",
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"check:types": "tsc --noEmit --project tsconfig.json",
"reformat": "prettier --write .",
"generate": "./scripts/generate.sh",
"test": "jest --coverage"
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage"
},
"license": "Apache-2.0",
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/tools/mongodb/mongodbHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { MongoCluster } from "mongodb-runner";
import path from "path";
import { fileURLToPath } from "url";
import fs from "fs/promises";
import { MongoClient, ObjectId } from "mongodb";
import { getResponseContent, IntegrationTest, setupIntegrationTest } from "../../helpers.js";
import { config, UserConfig } from "../../../../src/config.js";

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

interface MongoDBIntegrationTest {
mongoClient: () => MongoClient;
connectionString: () => string;
Expand Down
12 changes: 10 additions & 2 deletions tests/unit/telemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Telemetry } from "../../src/telemetry/telemetry.js";
import { BaseEvent, TelemetryResult } from "../../src/telemetry/types.js";
import { EventCache } from "../../src/telemetry/eventCache.js";
import { config } from "../../src/config.js";
import { jest } from "@jest/globals";

// Mock the ApiClient to avoid real API calls
jest.mock("../../src/common/atlas/apiClient.js");
Expand Down Expand Up @@ -93,22 +94,29 @@ describe("Telemetry", () => {

// Setup mocked API client
mockApiClient = new MockApiClient({ baseUrl: "" }) as jest.Mocked<ApiClient>;
mockApiClient.sendEvents = jest.fn().mockResolvedValue(undefined);
mockApiClient.hasCredentials = jest.fn().mockReturnValue(true);
//@ts-expect-error This is a workaround
mockApiClient.sendEvents = jest.fn<() => undefined>().mockResolvedValue(undefined);
mockApiClient.hasCredentials = jest.fn<() => boolean>().mockReturnValue(true);

// Setup mocked EventCache
mockEventCache = new MockEventCache() as jest.Mocked<EventCache>;
//@ts-expect-error This is a workaround
mockEventCache.getEvents = jest.fn().mockReturnValue([]);
//@ts-expect-error This is a workaround
mockEventCache.clearEvents = jest.fn().mockResolvedValue(undefined);
//@ts-expect-error This is a workaround
mockEventCache.appendEvents = jest.fn().mockResolvedValue(undefined);
//@ts-expect-error This is a workaround
MockEventCache.getInstance = jest.fn().mockReturnValue(mockEventCache);

// Create a simplified session with our mocked API client
session = {
apiClient: mockApiClient,
sessionId: "test-session-id",
agentRunner: { name: "test-agent", version: "1.0.0" } as const,
//@ts-expect-error This is a workaround
close: jest.fn().mockResolvedValue(undefined),
//@ts-expect-error This is a workaround
setAgentRunner: jest.fn().mockResolvedValue(undefined),
} as unknown as Session;

Expand Down
2 changes: 0 additions & 2 deletions tsconfig.jest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"module": "esnext",
"target": "esnext",
"isolatedModules": true,
"allowSyntheticDefaultImports": true,
"types": ["jest", "jest-extended"]
Expand Down
Loading