@hammadj/better-auth-test-utils 1.5.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,163 @@
1
+ import { deepmerge, initGetModelName } from "@better-auth/core/db/adapter";
2
+ import { TTY_COLORS } from "@better-auth/core/env";
3
+ import { afterAll, beforeAll, describe } from "vitest";
4
+ import { getAuthTables } from "better-auth/db";
5
+
6
+ //#region src/adapter/test-adapter.ts
7
+ const testAdapter = async ({ adapter: getAdapter, runMigrations, overrideBetterAuthOptions, additionalCleanups, tests, prefixTests, onFinish, customIdGenerator, transformIdOutput }) => {
8
+ const defaultBAOptions = {};
9
+ let betterAuthOptions = {
10
+ ...defaultBAOptions,
11
+ ...overrideBetterAuthOptions?.(defaultBAOptions) || {}
12
+ };
13
+ let adapter = (await getAdapter(betterAuthOptions))(betterAuthOptions);
14
+ const adapterName = adapter.options?.adapterConfig.adapterName;
15
+ const adapterId = adapter.options?.adapterConfig.adapterId || adapter.id;
16
+ const adapterDisplayName = adapterName || adapterId;
17
+ const refreshAdapter = async (betterAuthOptions) => {
18
+ adapter = (await getAdapter(betterAuthOptions))(betterAuthOptions);
19
+ };
20
+ /**
21
+ * A helper function to log to the console.
22
+ */
23
+ const log = {
24
+ info: (...args) => console.log(`${TTY_COLORS.fg.blue}INFO ${TTY_COLORS.reset} [${adapterDisplayName}]`, ...args),
25
+ success: (...args) => console.log(`${TTY_COLORS.fg.green}SUCCESS${TTY_COLORS.reset} [${adapterDisplayName}]`, ...args),
26
+ warn: (...args) => console.log(`${TTY_COLORS.fg.yellow}WARN ${TTY_COLORS.reset} [${adapterDisplayName}]`, ...args),
27
+ error: (...args) => console.log(`${TTY_COLORS.fg.red}ERROR ${TTY_COLORS.reset} [${adapterDisplayName}]`, ...args),
28
+ debug: (...args) => console.log(`${TTY_COLORS.fg.magenta}DEBUG ${TTY_COLORS.reset} [${adapterDisplayName}]`, ...args)
29
+ };
30
+ /**
31
+ * Cleanup function to remove all rows from the database.
32
+ */
33
+ const cleanup = async () => {
34
+ const start = performance.now();
35
+ await refreshAdapter(betterAuthOptions);
36
+ const getAllModels = getAuthTables(betterAuthOptions);
37
+ for (const model of Object.keys(getAllModels)) {
38
+ const getModelName = initGetModelName({
39
+ usePlural: adapter.options?.adapterConfig?.usePlural,
40
+ schema: getAllModels
41
+ });
42
+ try {
43
+ const modelName = getModelName(model);
44
+ await adapter.deleteMany({
45
+ model: modelName,
46
+ where: []
47
+ });
48
+ } catch (error) {
49
+ const msg = `Error while cleaning up all rows from ${model}`;
50
+ log.error(msg, error);
51
+ throw new Error(msg, { cause: error });
52
+ }
53
+ }
54
+ try {
55
+ await additionalCleanups?.();
56
+ } catch (error) {
57
+ const msg = `Error while running additional cleanups`;
58
+ log.error(msg, error);
59
+ throw new Error(msg, { cause: error });
60
+ }
61
+ await refreshAdapter(betterAuthOptions);
62
+ log.success(`${TTY_COLORS.bright}CLEAN-UP${TTY_COLORS.reset} completed successfully (${(performance.now() - start).toFixed(3)}ms)`);
63
+ };
64
+ /**
65
+ * A function that will run the database migrations.
66
+ */
67
+ const migrate = async () => {
68
+ const start = performance.now();
69
+ try {
70
+ await runMigrations(betterAuthOptions);
71
+ } catch (error) {
72
+ const msg = `Error while running migrations`;
73
+ log.error(msg, error);
74
+ throw new Error(msg, { cause: error });
75
+ }
76
+ log.success(`${TTY_COLORS.bright}MIGRATIONS${TTY_COLORS.reset} completed successfully (${(performance.now() - start).toFixed(3)}ms)`);
77
+ };
78
+ return { execute: () => {
79
+ describe(adapterDisplayName, async () => {
80
+ const allSuiteStats = [];
81
+ beforeAll(async () => {
82
+ await migrate();
83
+ }, 6e4);
84
+ afterAll(async () => {
85
+ await cleanup();
86
+ if (allSuiteStats.length > 0) {
87
+ const totalMigrations = allSuiteStats.reduce((sum, stats) => sum + stats.migrationCount, 0);
88
+ const totalMigrationTime = allSuiteStats.reduce((sum, stats) => sum + stats.totalMigrationTime, 0);
89
+ const totalTests = allSuiteStats.reduce((sum, stats) => sum + stats.testCount, 0);
90
+ const totalDuration = allSuiteStats.reduce((sum, stats) => sum + stats.suiteDuration, 0);
91
+ const separator = `${"─".repeat(80)}`;
92
+ console.log(`\n${TTY_COLORS.fg.cyan}${separator}`);
93
+ console.log(`${TTY_COLORS.fg.cyan}${TTY_COLORS.bright}TEST SUITE STATISTICS SUMMARY${TTY_COLORS.reset}`);
94
+ console.log(`${TTY_COLORS.fg.cyan}${separator}${TTY_COLORS.reset}\n`);
95
+ for (const stats of allSuiteStats) {
96
+ const avgMigrationTime = stats.migrationCount > 0 ? (stats.totalMigrationTime / stats.migrationCount).toFixed(2) : "0.00";
97
+ console.log(`${TTY_COLORS.fg.magenta}${stats.suiteName}${TTY_COLORS.reset}:`);
98
+ console.log(` Tests: ${TTY_COLORS.fg.green}${stats.testCount}${TTY_COLORS.reset}`);
99
+ console.log(` Migrations: ${TTY_COLORS.fg.yellow}${stats.migrationCount}${TTY_COLORS.reset} (avg: ${avgMigrationTime}ms)`);
100
+ console.log(` Total Migration Time: ${TTY_COLORS.fg.yellow}${stats.totalMigrationTime.toFixed(2)}ms${TTY_COLORS.reset}`);
101
+ console.log(` Suite Duration: ${TTY_COLORS.fg.blue}${stats.suiteDuration.toFixed(2)}ms${TTY_COLORS.reset}`);
102
+ if (stats.groupingStats) {
103
+ const { totalGroups, averageTestsPerGroup, largestGroupSize, smallestGroupSize, groupsWithMultipleTests } = stats.groupingStats;
104
+ console.log(` Test Groups: ${TTY_COLORS.fg.cyan}${totalGroups}${TTY_COLORS.reset}`);
105
+ if (totalGroups > 0) {
106
+ console.log(` Avg Tests/Group: ${TTY_COLORS.fg.cyan}${averageTestsPerGroup.toFixed(2)}${TTY_COLORS.reset}`);
107
+ console.log(` Largest Group: ${TTY_COLORS.fg.cyan}${largestGroupSize}${TTY_COLORS.reset}`);
108
+ console.log(` Smallest Group: ${TTY_COLORS.fg.cyan}${smallestGroupSize}${TTY_COLORS.reset}`);
109
+ console.log(` Groups w/ Multiple Tests: ${TTY_COLORS.fg.cyan}${groupsWithMultipleTests}${TTY_COLORS.reset}`);
110
+ }
111
+ }
112
+ console.log("");
113
+ }
114
+ const avgMigrationTime = totalMigrations > 0 ? (totalMigrationTime / totalMigrations).toFixed(2) : "0.00";
115
+ const totalGroups = allSuiteStats.reduce((sum, stats) => sum + (stats.groupingStats?.totalGroups || 0), 0);
116
+ const totalGroupsWithMultipleTests = allSuiteStats.reduce((sum, stats) => sum + (stats.groupingStats?.groupsWithMultipleTests || 0), 0);
117
+ const totalTestsInGroups = allSuiteStats.reduce((sum, stats) => sum + (stats.groupingStats?.totalTestsInGroups || 0), 0);
118
+ const avgTestsPerGroup = totalGroups > 0 ? totalTestsInGroups / totalGroups : 0;
119
+ console.log(`${TTY_COLORS.fg.cyan}${separator}`);
120
+ console.log(`${TTY_COLORS.fg.cyan}${TTY_COLORS.bright}TOTALS${TTY_COLORS.reset}`);
121
+ console.log(` Total Tests: ${TTY_COLORS.fg.green}${totalTests}${TTY_COLORS.reset}`);
122
+ console.log(` Total Migrations: ${TTY_COLORS.fg.yellow}${totalMigrations}${TTY_COLORS.reset} (avg: ${avgMigrationTime}ms)`);
123
+ console.log(` Total Migration Time: ${TTY_COLORS.fg.yellow}${totalMigrationTime.toFixed(2)}ms${TTY_COLORS.reset}`);
124
+ console.log(` Total Duration: ${TTY_COLORS.fg.blue}${totalDuration.toFixed(2)}ms${TTY_COLORS.reset}`);
125
+ if (totalGroups > 0) {
126
+ console.log(` Total Test Groups: ${TTY_COLORS.fg.cyan}${totalGroups}${TTY_COLORS.reset}`);
127
+ console.log(` Avg Tests/Group: ${TTY_COLORS.fg.cyan}${avgTestsPerGroup.toFixed(2)}${TTY_COLORS.reset}`);
128
+ console.log(` Groups w/ Multiple Tests: ${TTY_COLORS.fg.cyan}${totalGroupsWithMultipleTests}${TTY_COLORS.reset}`);
129
+ }
130
+ console.log(`${TTY_COLORS.fg.cyan}${separator}${TTY_COLORS.reset}\n`);
131
+ }
132
+ await onFinish?.();
133
+ }, 6e4);
134
+ for (const testSuite of tests) await testSuite({
135
+ adapter: async () => {
136
+ await refreshAdapter(betterAuthOptions);
137
+ return adapter;
138
+ },
139
+ adapterDisplayName,
140
+ log,
141
+ getBetterAuthOptions: () => betterAuthOptions,
142
+ modifyBetterAuthOptions: async (options) => {
143
+ const newOptions = deepmerge(defaultBAOptions, options);
144
+ betterAuthOptions = deepmerge(newOptions, overrideBetterAuthOptions?.(newOptions) || {});
145
+ await refreshAdapter(betterAuthOptions);
146
+ return betterAuthOptions;
147
+ },
148
+ cleanup,
149
+ prefixTests,
150
+ runMigrations: migrate,
151
+ onTestFinish: async (stats) => {
152
+ allSuiteStats.push(stats);
153
+ },
154
+ customIdGenerator,
155
+ transformIdOutput
156
+ });
157
+ });
158
+ } };
159
+ };
160
+
161
+ //#endregion
162
+ export { testAdapter };
163
+ //# sourceMappingURL=test-adapter.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-adapter.mjs","names":[],"sources":["../src/adapter/test-adapter.ts"],"sourcesContent":["import type { Awaitable, BetterAuthOptions } from \"@better-auth/core\";\nimport type { DBAdapter } from \"@better-auth/core/db/adapter\";\nimport { deepmerge, initGetModelName } from \"@better-auth/core/db/adapter\";\nimport { TTY_COLORS } from \"@better-auth/core/env\";\nimport { getAuthTables } from \"better-auth/db\";\nimport { afterAll, beforeAll, describe } from \"vitest\";\nimport type { createTestSuite, TestSuiteStats } from \"./create-test-suite\";\n\nexport type Logger = {\n\tinfo: (...args: any[]) => void;\n\tsuccess: (...args: any[]) => void;\n\twarn: (...args: any[]) => void;\n\terror: (...args: any[]) => void;\n\tdebug: (...args: any[]) => void;\n};\n\nexport const testAdapter = async ({\n\tadapter: getAdapter,\n\trunMigrations,\n\toverrideBetterAuthOptions,\n\tadditionalCleanups,\n\ttests,\n\tprefixTests,\n\tonFinish,\n\tcustomIdGenerator,\n\ttransformIdOutput,\n}: {\n\t/**\n\t * A function that will return the adapter instance to test with.\n\t *\n\t * @example\n\t * ```ts\n\t * testAdapter({\n\t * adapter: (options) => drizzleAdapter(drizzle(db), {\n\t * schema: generateSchema(options),\n\t * }),\n\t * })\n\t */\n\tadapter: (\n\t\toptions: BetterAuthOptions,\n\t) => Awaitable<(options: BetterAuthOptions) => DBAdapter<BetterAuthOptions>>;\n\t/**\n\t * A function that will run the database migrations.\n\t */\n\trunMigrations: (betterAuthOptions: BetterAuthOptions) => Promise<void> | void;\n\t/**\n\t * Any potential better-auth options overrides.\n\t */\n\toverrideBetterAuthOptions?: (\n\t\tbetterAuthOptions: BetterAuthOptions,\n\t) => BetterAuthOptions;\n\t/**\n\t * By default we will cleanup all tables automatically,\n\t * but if you have additional cleanup logic, you can pass it here.\n\t *\n\t * Such as deleting a DB file that could had been created.\n\t */\n\tadditionalCleanups?: () => Promise<void> | void;\n\t/**\n\t * A test suite to run.\n\t */\n\ttests: ReturnType<ReturnType<typeof createTestSuite>>[];\n\t/**\n\t * A prefix to add to the test suite name.\n\t */\n\tprefixTests?: string;\n\t/**\n\t * Upon finish of the tests, this function will be called.\n\t */\n\tonFinish?: () => Promise<void> | void;\n\t/**\n\t * Custom ID generator function to be used by the helper functions. (such as `insertRandom`)\n\t */\n\tcustomIdGenerator?: () => any;\n\t/**\n\t * A function that will transform the ID output.\n\t */\n\ttransformIdOutput?: (id: any) => any;\n}) => {\n\tconst defaultBAOptions = {} satisfies BetterAuthOptions;\n\tlet betterAuthOptions = (() => {\n\t\treturn {\n\t\t\t...defaultBAOptions,\n\t\t\t...(overrideBetterAuthOptions?.(defaultBAOptions) || {}),\n\t\t} satisfies BetterAuthOptions;\n\t})();\n\n\tlet adapter: DBAdapter<BetterAuthOptions> = (\n\t\tawait getAdapter(betterAuthOptions)\n\t)(betterAuthOptions);\n\n\tconst adapterName = adapter.options?.adapterConfig.adapterName;\n\tconst adapterId = adapter.options?.adapterConfig.adapterId || adapter.id;\n\tconst adapterDisplayName = adapterName || adapterId;\n\n\tconst refreshAdapter = async (betterAuthOptions: BetterAuthOptions) => {\n\t\tadapter = (await getAdapter(betterAuthOptions))(betterAuthOptions);\n\t};\n\n\t/**\n\t * A helper function to log to the console.\n\t */\n\tconst log: Logger = (() => {\n\t\treturn {\n\t\t\tinfo: (...args: any[]) =>\n\t\t\t\tconsole.log(\n\t\t\t\t\t`${TTY_COLORS.fg.blue}INFO ${TTY_COLORS.reset} [${adapterDisplayName}]`,\n\t\t\t\t\t...args,\n\t\t\t\t),\n\t\t\tsuccess: (...args: any[]) =>\n\t\t\t\tconsole.log(\n\t\t\t\t\t`${TTY_COLORS.fg.green}SUCCESS${TTY_COLORS.reset} [${adapterDisplayName}]`,\n\t\t\t\t\t...args,\n\t\t\t\t),\n\t\t\twarn: (...args: any[]) =>\n\t\t\t\tconsole.log(\n\t\t\t\t\t`${TTY_COLORS.fg.yellow}WARN ${TTY_COLORS.reset} [${adapterDisplayName}]`,\n\t\t\t\t\t...args,\n\t\t\t\t),\n\t\t\terror: (...args: any[]) =>\n\t\t\t\tconsole.log(\n\t\t\t\t\t`${TTY_COLORS.fg.red}ERROR ${TTY_COLORS.reset} [${adapterDisplayName}]`,\n\t\t\t\t\t...args,\n\t\t\t\t),\n\t\t\tdebug: (...args: any[]) =>\n\t\t\t\tconsole.log(\n\t\t\t\t\t`${TTY_COLORS.fg.magenta}DEBUG ${TTY_COLORS.reset} [${adapterDisplayName}]`,\n\t\t\t\t\t...args,\n\t\t\t\t),\n\t\t};\n\t})();\n\n\t/**\n\t * Cleanup function to remove all rows from the database.\n\t */\n\tconst cleanup = async () => {\n\t\tconst start = performance.now();\n\t\tawait refreshAdapter(betterAuthOptions);\n\t\tconst getAllModels = getAuthTables(betterAuthOptions);\n\n\t\t// Clean up all rows from all models\n\t\tfor (const model of Object.keys(getAllModels)) {\n\t\t\tconst getModelName = initGetModelName({\n\t\t\t\tusePlural: adapter.options?.adapterConfig?.usePlural,\n\t\t\t\tschema: getAllModels,\n\t\t\t});\n\t\t\ttry {\n\t\t\t\tconst modelName = getModelName(model);\n\t\t\t\tawait adapter.deleteMany({ model: modelName, where: [] });\n\t\t\t} catch (error) {\n\t\t\t\tconst msg = `Error while cleaning up all rows from ${model}`;\n\t\t\t\tlog.error(msg, error);\n\t\t\t\tthrow new Error(msg, {\n\t\t\t\t\tcause: error,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// Run additional cleanups\n\t\ttry {\n\t\t\tawait additionalCleanups?.();\n\t\t} catch (error) {\n\t\t\tconst msg = `Error while running additional cleanups`;\n\t\t\tlog.error(msg, error);\n\t\t\tthrow new Error(msg, {\n\t\t\t\tcause: error,\n\t\t\t});\n\t\t}\n\t\tawait refreshAdapter(betterAuthOptions);\n\t\tlog.success(\n\t\t\t`${TTY_COLORS.bright}CLEAN-UP${TTY_COLORS.reset} completed successfully (${(performance.now() - start).toFixed(3)}ms)`,\n\t\t);\n\t};\n\n\t/**\n\t * A function that will run the database migrations.\n\t */\n\tconst migrate = async () => {\n\t\tconst start = performance.now();\n\n\t\ttry {\n\t\t\tawait runMigrations(betterAuthOptions);\n\t\t} catch (error) {\n\t\t\tconst msg = `Error while running migrations`;\n\t\t\tlog.error(msg, error);\n\t\t\tthrow new Error(msg, {\n\t\t\t\tcause: error,\n\t\t\t});\n\t\t}\n\t\tlog.success(\n\t\t\t`${TTY_COLORS.bright}MIGRATIONS${TTY_COLORS.reset} completed successfully (${(performance.now() - start).toFixed(3)}ms)`,\n\t\t);\n\t};\n\n\treturn {\n\t\texecute: () => {\n\t\t\tdescribe(adapterDisplayName, async () => {\n\t\t\t\t// Collect statistics from all test suites\n\t\t\t\tconst allSuiteStats: TestSuiteStats[] = [];\n\n\t\t\t\tbeforeAll(async () => {\n\t\t\t\t\tawait migrate();\n\t\t\t\t}, 60000);\n\n\t\t\t\tafterAll(async () => {\n\t\t\t\t\tawait cleanup();\n\n\t\t\t\t\t// Display statistics summary\n\t\t\t\t\tif (allSuiteStats.length > 0) {\n\t\t\t\t\t\tconst totalMigrations = allSuiteStats.reduce(\n\t\t\t\t\t\t\t(sum, stats) => sum + stats.migrationCount,\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst totalMigrationTime = allSuiteStats.reduce(\n\t\t\t\t\t\t\t(sum, stats) => sum + stats.totalMigrationTime,\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst totalTests = allSuiteStats.reduce(\n\t\t\t\t\t\t\t(sum, stats) => sum + stats.testCount,\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst totalDuration = allSuiteStats.reduce(\n\t\t\t\t\t\t\t(sum, stats) => sum + stats.suiteDuration,\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst dash = \"─\";\n\t\t\t\t\t\tconst separator = `${dash.repeat(80)}`;\n\n\t\t\t\t\t\tconsole.log(`\\n${TTY_COLORS.fg.cyan}${separator}`);\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t`${TTY_COLORS.fg.cyan}${TTY_COLORS.bright}TEST SUITE STATISTICS SUMMARY${TTY_COLORS.reset}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t`${TTY_COLORS.fg.cyan}${separator}${TTY_COLORS.reset}\\n`,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// Per-suite breakdown\n\t\t\t\t\t\tfor (const stats of allSuiteStats) {\n\t\t\t\t\t\t\tconst avgMigrationTime =\n\t\t\t\t\t\t\t\tstats.migrationCount > 0\n\t\t\t\t\t\t\t\t\t? (stats.totalMigrationTime / stats.migrationCount).toFixed(2)\n\t\t\t\t\t\t\t\t\t: \"0.00\";\n\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t`${TTY_COLORS.fg.magenta}${stats.suiteName}${TTY_COLORS.reset}:`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t` Tests: ${TTY_COLORS.fg.green}${stats.testCount}${TTY_COLORS.reset}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t` Migrations: ${TTY_COLORS.fg.yellow}${stats.migrationCount}${TTY_COLORS.reset} (avg: ${avgMigrationTime}ms)`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t` Total Migration Time: ${TTY_COLORS.fg.yellow}${stats.totalMigrationTime.toFixed(2)}ms${TTY_COLORS.reset}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t` Suite Duration: ${TTY_COLORS.fg.blue}${stats.suiteDuration.toFixed(2)}ms${TTY_COLORS.reset}`,\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t// Display grouping statistics if available\n\t\t\t\t\t\t\tif (stats.groupingStats) {\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\ttotalGroups,\n\t\t\t\t\t\t\t\t\taverageTestsPerGroup,\n\t\t\t\t\t\t\t\t\tlargestGroupSize,\n\t\t\t\t\t\t\t\t\tsmallestGroupSize,\n\t\t\t\t\t\t\t\t\tgroupsWithMultipleTests,\n\t\t\t\t\t\t\t\t} = stats.groupingStats;\n\t\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t\t` Test Groups: ${TTY_COLORS.fg.cyan}${totalGroups}${TTY_COLORS.reset}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tif (totalGroups > 0) {\n\t\t\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t\t\t` Avg Tests/Group: ${TTY_COLORS.fg.cyan}${averageTestsPerGroup.toFixed(2)}${TTY_COLORS.reset}`,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t\t\t` Largest Group: ${TTY_COLORS.fg.cyan}${largestGroupSize}${TTY_COLORS.reset}`,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t\t\t` Smallest Group: ${TTY_COLORS.fg.cyan}${smallestGroupSize}${TTY_COLORS.reset}`,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t\t\t` Groups w/ Multiple Tests: ${TTY_COLORS.fg.cyan}${groupsWithMultipleTests}${TTY_COLORS.reset}`,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconsole.log(\"\");\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Totals\n\t\t\t\t\t\tconst avgMigrationTime =\n\t\t\t\t\t\t\ttotalMigrations > 0\n\t\t\t\t\t\t\t\t? (totalMigrationTime / totalMigrations).toFixed(2)\n\t\t\t\t\t\t\t\t: \"0.00\";\n\n\t\t\t\t\t\t// Calculate total grouping statistics\n\t\t\t\t\t\tconst totalGroups = allSuiteStats.reduce(\n\t\t\t\t\t\t\t(sum, stats) => sum + (stats.groupingStats?.totalGroups || 0),\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst totalGroupsWithMultipleTests = allSuiteStats.reduce(\n\t\t\t\t\t\t\t(sum, stats) =>\n\t\t\t\t\t\t\t\tsum + (stats.groupingStats?.groupsWithMultipleTests || 0),\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst totalTestsInGroups = allSuiteStats.reduce(\n\t\t\t\t\t\t\t(sum, stats) =>\n\t\t\t\t\t\t\t\tsum + (stats.groupingStats?.totalTestsInGroups || 0),\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst avgTestsPerGroup =\n\t\t\t\t\t\t\ttotalGroups > 0 ? totalTestsInGroups / totalGroups : 0;\n\n\t\t\t\t\t\tconsole.log(`${TTY_COLORS.fg.cyan}${separator}`);\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t`${TTY_COLORS.fg.cyan}${TTY_COLORS.bright}TOTALS${TTY_COLORS.reset}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t` Total Tests: ${TTY_COLORS.fg.green}${totalTests}${TTY_COLORS.reset}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t` Total Migrations: ${TTY_COLORS.fg.yellow}${totalMigrations}${TTY_COLORS.reset} (avg: ${avgMigrationTime}ms)`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t` Total Migration Time: ${TTY_COLORS.fg.yellow}${totalMigrationTime.toFixed(2)}ms${TTY_COLORS.reset}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t` Total Duration: ${TTY_COLORS.fg.blue}${totalDuration.toFixed(2)}ms${TTY_COLORS.reset}`,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\t// Display total grouping statistics\n\t\t\t\t\t\tif (totalGroups > 0) {\n\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t` Total Test Groups: ${TTY_COLORS.fg.cyan}${totalGroups}${TTY_COLORS.reset}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t` Avg Tests/Group: ${TTY_COLORS.fg.cyan}${avgTestsPerGroup.toFixed(2)}${TTY_COLORS.reset}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t` Groups w/ Multiple Tests: ${TTY_COLORS.fg.cyan}${totalGroupsWithMultipleTests}${TTY_COLORS.reset}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t`${TTY_COLORS.fg.cyan}${separator}${TTY_COLORS.reset}\\n`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tawait onFinish?.();\n\t\t\t\t}, 60000);\n\n\t\t\t\tfor (const testSuite of tests) {\n\t\t\t\t\tawait testSuite({\n\t\t\t\t\t\tadapter: async () => {\n\t\t\t\t\t\t\tawait refreshAdapter(betterAuthOptions);\n\t\t\t\t\t\t\treturn adapter;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tadapterDisplayName,\n\t\t\t\t\t\tlog,\n\t\t\t\t\t\tgetBetterAuthOptions: () => betterAuthOptions,\n\t\t\t\t\t\tmodifyBetterAuthOptions: async (options) => {\n\t\t\t\t\t\t\tconst newOptions = deepmerge(defaultBAOptions, options);\n\t\t\t\t\t\t\tbetterAuthOptions = deepmerge(\n\t\t\t\t\t\t\t\tnewOptions,\n\t\t\t\t\t\t\t\toverrideBetterAuthOptions?.(newOptions) || {},\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tawait refreshAdapter(betterAuthOptions);\n\t\t\t\t\t\t\treturn betterAuthOptions;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcleanup,\n\t\t\t\t\t\tprefixTests,\n\t\t\t\t\t\trunMigrations: migrate,\n\t\t\t\t\t\tonTestFinish: async (stats: TestSuiteStats) => {\n\t\t\t\t\t\t\tallSuiteStats.push(stats);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcustomIdGenerator,\n\t\t\t\t\t\ttransformIdOutput,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t};\n};\n"],"mappings":";;;;;;AAgBA,MAAa,cAAc,OAAO,EACjC,SAAS,YACT,eACA,2BACA,oBACA,OACA,aACA,UACA,mBACA,wBAqDK;CACL,MAAM,mBAAmB,EAAE;CAC3B,IAAI,oBACI;EACN,GAAG;EACH,GAAI,4BAA4B,iBAAiB,IAAI,EAAE;EACvD;CAGF,IAAI,WACH,M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B,UACnB,YACA,4BAA4B,WAAW,IAAI,EAAE,CAC7C;AACD,WAAM,eAAe,kBAAkB;AACvC,YAAO;;IAER;IACA;IACA,eAAe;IACf,cAAc,OAAO,UAA0B;AAC9C,mBAAc,KAAK,MAAM;;IAE1B;IACA;IACA,CAAC;IAEF;IAEH"}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@hammadj/better-auth-test-utils",
3
+ "version": "1.5.0-beta.9",
4
+ "type": "module",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/META-DREAMER/better-auth.git"
8
+ },
9
+ "exports": {
10
+ "./adapter": {
11
+ "dev-source": "./src/adapter.ts",
12
+ "default": "./dist/adapter.mjs",
13
+ "types": "./dist/adapter.d.mts"
14
+ }
15
+ },
16
+ "devDependencies": {
17
+ "tsdown": "^0.20.1",
18
+ "vitest": "^4.0.18",
19
+ "@hammadj/better-auth-core": "1.5.0-beta.9",
20
+ "@hammadj/better-auth": "1.5.0-beta.9"
21
+ },
22
+ "peerDependencies": {
23
+ "vitest": "^4.0.18",
24
+ "@hammadj/better-auth-core": "1.5.0-beta.9",
25
+ "@hammadj/better-auth": "1.5.0-beta.9"
26
+ },
27
+ "scripts": {
28
+ "build": "tsdown",
29
+ "dev": "tsdown --watch"
30
+ }
31
+ }