Skip to content

Commit ee91651

Browse files
authored
fix: use proper ESM with jest (#166)
1 parent 308b348 commit ee91651

File tree

6 files changed

+16
-7
lines changed

6 files changed

+16
-7
lines changed

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default defineConfig([
4848
"coverage",
4949
"global.d.ts",
5050
"eslint.config.js",
51-
"jest.config.js",
51+
"jest.config.ts",
5252
]),
5353
eslintPluginPrettierRecommended,
5454
]);

jest.config.js renamed to jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default {
1212
"ts-jest",
1313
{
1414
useESM: true,
15-
tsconfig: "tsconfig.jest.json", // Use specific tsconfig file for Jest
15+
tsconfig: "tsconfig.jest.json",
1616
},
1717
],
1818
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"check:types": "tsc --noEmit --project tsconfig.json",
3030
"reformat": "prettier --write .",
3131
"generate": "./scripts/generate.sh",
32-
"test": "jest --coverage"
32+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage"
3333
},
3434
"license": "Apache-2.0",
3535
"devDependencies": {

tests/integration/tools/mongodb/mongodbHelpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { MongoCluster } from "mongodb-runner";
22
import path from "path";
3+
import { fileURLToPath } from "url";
34
import fs from "fs/promises";
45
import { MongoClient, ObjectId } from "mongodb";
56
import { getResponseContent, IntegrationTest, setupIntegrationTest, defaultTestConfig } from "../../helpers.js";
67
import { UserConfig } from "../../../../src/config.js";
78

9+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
10+
811
interface MongoDBIntegrationTest {
912
mongoClient: () => MongoClient;
1013
connectionString: () => string;

tests/unit/telemetry.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Telemetry } from "../../src/telemetry/telemetry.js";
44
import { BaseEvent, TelemetryResult } from "../../src/telemetry/types.js";
55
import { EventCache } from "../../src/telemetry/eventCache.js";
66
import { config } from "../../src/config.js";
7+
import { jest } from "@jest/globals";
78

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

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

99101
// Setup mocked EventCache
100102
mockEventCache = new MockEventCache() as jest.Mocked<EventCache>;
103+
//@ts-expect-error This is a workaround
101104
mockEventCache.getEvents = jest.fn().mockReturnValue([]);
105+
//@ts-expect-error This is a workaround
102106
mockEventCache.clearEvents = jest.fn().mockResolvedValue(undefined);
107+
//@ts-expect-error This is a workaround
103108
mockEventCache.appendEvents = jest.fn().mockResolvedValue(undefined);
109+
//@ts-expect-error This is a workaround
104110
MockEventCache.getInstance = jest.fn().mockReturnValue(mockEventCache);
105111

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

tsconfig.jest.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
"extends": "./tsconfig.build.json",
33
"compilerOptions": {
4-
"module": "esnext",
5-
"target": "esnext",
64
"isolatedModules": true,
75
"allowSyntheticDefaultImports": true,
86
"types": ["jest", "jest-extended"]

0 commit comments

Comments
 (0)