diff --git a/packages/better-auth/src/plugins/custom-session/custom-session.test.ts b/packages/better-auth/src/plugins/custom-session/custom-session.test.ts index 5301281ecb..e96b431259 100644 --- a/packages/better-auth/src/plugins/custom-session/custom-session.test.ts +++ b/packages/better-auth/src/plugins/custom-session/custom-session.test.ts @@ -93,42 +93,43 @@ describe("Custom Session Plugin Tests", async () => { expect(session.newData).toEqual({ message: "Hello, World!" }); }); - it("should not create memory leaks with multiple plugin instances", async () => { - const initialMemory = process.memoryUsage(); + it.skipIf(globalThis.gc == null)( + "should not create memory leaks with multiple plugin instances", + async () => { + const initialMemory = process.memoryUsage(); - const pluginInstances = []; - const sessionCount = 100; + const pluginInstances = []; + const sessionCount = 100; - for (let i = 0; i < sessionCount; i++) { - const plugin = customSession(async ({ user, session }) => { - return { - user: { - ...user, - testField: `test-${i}`, - }, - session, - iteration: i, - }; - }); - pluginInstances.push(plugin); - } + for (let i = 0; i < sessionCount; i++) { + const plugin = customSession(async ({ user, session }) => { + return { + user: { + ...user, + testField: `test-${i}`, + }, + session, + iteration: i, + }; + }); + pluginInstances.push(plugin); + } + // Force garbage collection (only works if Node.js is started with --expose-gc) + // @ts-expect-error + globalThis.gc(); - // Force garbage collection if available (in test environment) - if (global.gc) { - global.gc(); - } + const afterPluginCreation = process.memoryUsage(); - const afterPluginCreation = process.memoryUsage(); - - const memoryIncrease = - afterPluginCreation.heapUsed - initialMemory.heapUsed; - const memoryIncreasePerPlugin = memoryIncrease / sessionCount; - // Each plugin instance should not use more than <5KB of memory - // (this is a reasonable threshold that indicates no major memory leak) - expect(memoryIncreasePerPlugin).toBeLessThan(5 * 1024); - // Verify that plugins are still functional - expect(pluginInstances).toHaveLength(sessionCount); - expect(pluginInstances[0].id).toBe("custom-session"); - expect(pluginInstances[sessionCount - 1].id).toBe("custom-session"); - }); + const memoryIncrease = + afterPluginCreation.heapUsed - initialMemory.heapUsed; + const memoryIncreasePerPlugin = memoryIncrease / sessionCount; + // Each plugin instance should not use more than <5KB of memory + // (this is a reasonable threshold that indicates no major memory leak) + expect(memoryIncreasePerPlugin).toBeLessThan(5 * 1024); + // Verify that plugins are still functional + expect(pluginInstances).toHaveLength(sessionCount); + expect(pluginInstances[0].id).toBe("custom-session"); + expect(pluginInstances[sessionCount - 1].id).toBe("custom-session"); + }, + ); }); diff --git a/packages/better-auth/vitest.config.ts b/packages/better-auth/vitest.config.ts new file mode 100644 index 0000000000..9b231fc614 --- /dev/null +++ b/packages/better-auth/vitest.config.ts @@ -0,0 +1,11 @@ +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + poolOptions: { + forks: { + execArgv: ["--expose-gc"], + }, + }, + }, +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 68a4d30299..bbe2118429 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,8 +10,8 @@ catalogs: specifier: ^1.1.18 version: 1.1.18 better-call: - specifier: 1.0.16 - version: 1.0.16 + specifier: 1.0.18 + version: 1.0.18 typescript: specifier: ^5.9.2 version: 5.9.2 @@ -179,7 +179,7 @@ importers: version: link:../../packages/better-auth better-call: specifier: 'catalog:' - version: 1.0.16 + version: 1.0.18 better-sqlite3: specifier: ^12.2.0 version: 12.2.0 @@ -626,7 +626,7 @@ importers: version: 13.1.2 better-call: specifier: 'catalog:' - version: 1.0.16 + version: 1.0.18 defu: specifier: ^6.1.4 version: 6.1.4 @@ -885,7 +885,7 @@ importers: version: link:../better-auth better-call: specifier: 'catalog:' - version: 1.0.16 + version: 1.0.18 express: specifier: ^5.1.0 version: 5.1.0 @@ -901,7 +901,7 @@ importers: version: link:../better-auth better-call: specifier: 'catalog:' - version: 1.0.16 + version: 1.0.18 stripe: specifier: ^18.5.0 version: 18.5.0(@types/node@24.3.0) @@ -5783,8 +5783,8 @@ packages: resolution: {integrity: sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==} engines: {node: '>= 0.8'} - better-call@1.0.16: - resolution: {integrity: sha512-42dgJ1rOtc0anOoxjXPOWuel/Z/4aeO7EJ2SiXNwvlkySSgjXhNjAjTMWa8DL1nt6EXS3jl3VKC3mPsU/lUgVA==} + better-call@1.0.18: + resolution: {integrity: sha512-Ojyck3P3fs/egBmCW50tvfbCJorNV5KphfPOKrkCxPfOr8Brth1ruDtAJuhHVHEUiWrXv+vpEgWQk7m7FzhbbQ==} better-opn@3.0.2: resolution: {integrity: sha512-aVNobHnJqLiUelTaHat9DZ1qM2w0C0Eym4LPI/3JxOnSokGVdsl1T1kN7TFvsEAD8G47A6VKQ0TVHqbBnYMJlQ==} @@ -18098,7 +18098,7 @@ snapshots: dependencies: safe-buffer: 5.1.2 - better-call@1.0.16: + better-call@1.0.18: dependencies: '@better-fetch/fetch': 1.1.18 rou3: 0.5.1 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 5dc5cb8d3c..835516650f 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -11,7 +11,7 @@ catalogs: react: 19.1.1 react-dom: 19.1.1 catalog: - "better-call": "1.0.16" + "better-call": "1.0.18" "@better-fetch/fetch": "^1.1.18" "unbuild": "^3.6.1" "typescript": "^5.9.2"