@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,86 @@
1
+
2
+ > @hammadj/better-auth-test-utils@1.5.0-beta.9 build /Users/hammadjutt/Dev/better-auth-fork/packages/test-utils
3
+ > tsdown
4
+
5
+ β„Ή tsdown v0.20.1 powered by rolldown v1.0.0-rc.1
6
+ β„Ή config file: /Users/hammadjutt/Dev/better-auth-fork/packages/test-utils/tsdown.config.ts
7
+ β„Ή entry: src/adapter/index.ts
8
+ β„Ή tsconfig: tsconfig.json
9
+ β„Ή Build start
10
+ β„Ή Cleaning 6 files
11
+ β„Ή dist/adapter.mjs  0.15 kB β”‚ gzip: 0.10 kB
12
+ β„Ή dist/create-test-suite.mjs.map 39.07 kB β”‚ gzip: 9.66 kB
13
+ β„Ή dist/test-adapter.mjs.map 18.06 kB β”‚ gzip: 4.23 kB
14
+ β„Ή dist/create-test-suite.mjs 15.96 kB β”‚ gzip: 3.98 kB
15
+ β„Ή dist/test-adapter.mjs  8.12 kB β”‚ gzip: 1.97 kB
16
+ β„Ή dist/adapter.d.mts  0.27 kB β”‚ gzip: 0.16 kB
17
+ β„Ή dist/create-test-suite.d.mts  5.13 kB β”‚ gzip: 1.70 kB
18
+ β„Ή dist/test-adapter.d.mts  2.21 kB β”‚ gzip: 0.87 kB
19
+ β„Ή 8 files, total: 88.97 kB
20
+ src/adapter/test-adapter.ts (3:44) [UNRESOLVED_IMPORT] Warning: Could not resolve '@better-auth/core/db/adapter' in src/adapter/test-adapter.ts
21
+ β•­─[ src/adapter/test-adapter.ts:3:45 ]
22
+ β”‚
23
+ 3 β”‚ import { deepmerge, initGetModelName } from "@better-auth/core/db/adapter";
24
+  β”‚ ───────────────┬──────────────
25
+  β”‚ ╰──────────────── Module not found, treating it as an external dependency
26
+ ───╯
27
+
28
+ src/adapter/test-adapter.ts (4:27) [UNRESOLVED_IMPORT] Warning: Could not resolve '@better-auth/core/env' in src/adapter/test-adapter.ts
29
+ β•­─[ src/adapter/test-adapter.ts:4:28 ]
30
+ β”‚
31
+ 4 β”‚ import { TTY_COLORS } from "@better-auth/core/env";
32
+  β”‚ ───────────┬───────────
33
+  β”‚ ╰───────────── Module not found, treating it as an external dependency
34
+ ───╯
35
+
36
+ src/adapter/test-adapter.ts (5:30) [UNRESOLVED_IMPORT] Warning: Could not resolve 'better-auth/db' in src/adapter/test-adapter.ts
37
+ β•­─[ src/adapter/test-adapter.ts:5:31 ]
38
+ β”‚
39
+ 5 β”‚ import { getAuthTables } from "better-auth/db";
40
+  β”‚ ────────┬───────
41
+  β”‚ ╰───────── Module not found, treating it as an external dependency
42
+ ───╯
43
+
44
+ src/adapter/create-test-suite.ts (8:30) [UNRESOLVED_IMPORT] Warning: Could not resolve '@better-auth/core/db' in src/adapter/create-test-suite.ts
45
+ β•­─[ src/adapter/create-test-suite.ts:8:31 ]
46
+ β”‚
47
+ 8 β”‚ import { getAuthTables } from "@better-auth/core/db";
48
+  β”‚ ───────────┬──────────
49
+  β”‚ ╰──────────── Module not found, treating it as an external dependency
50
+ ───╯
51
+
52
+ src/adapter/create-test-suite.ts (14:7) [UNRESOLVED_IMPORT] Warning: Could not resolve '@better-auth/core/db/adapter' in src/adapter/create-test-suite.ts
53
+ β•­─[ src/adapter/create-test-suite.ts:14:8 ]
54
+ β”‚
55
+ 14 β”‚ } from "@better-auth/core/db/adapter";
56
+  β”‚ ───────────────┬──────────────
57
+  β”‚ ╰──────────────── Module not found, treating it as an external dependency
58
+ ────╯
59
+
60
+ src/adapter/create-test-suite.ts (15:27) [UNRESOLVED_IMPORT] Warning: Could not resolve '@better-auth/core/env' in src/adapter/create-test-suite.ts
61
+ β•­─[ src/adapter/create-test-suite.ts:15:28 ]
62
+ β”‚
63
+ 15 β”‚ import { TTY_COLORS } from "@better-auth/core/env";
64
+  β”‚ ───────────┬───────────
65
+  β”‚ ╰───────────── Module not found, treating it as an external dependency
66
+ ────╯
67
+
68
+ src/adapter/create-test-suite.ts (16:27) [UNRESOLVED_IMPORT] Warning: Could not resolve '@better-auth/core/utils/id' in src/adapter/create-test-suite.ts
69
+ β•­─[ src/adapter/create-test-suite.ts:16:28 ]
70
+ β”‚
71
+ 16 β”‚ import { generateId } from "@better-auth/core/utils/id";
72
+  β”‚ ──────────────┬─────────────
73
+  β”‚ ╰─────────────── Module not found, treating it as an external dependency
74
+ ────╯
75
+
76
+ src/adapter/create-test-suite.ts (18:27) [UNRESOLVED_IMPORT] Warning: Could not resolve 'better-auth' in src/adapter/create-test-suite.ts
77
+ β•­─[ src/adapter/create-test-suite.ts:18:28 ]
78
+ β”‚
79
+ 18 β”‚ import { betterAuth } from "better-auth";
80
+  β”‚ ──────┬──────
81
+  β”‚ ╰──────── Module not found, treating it as an external dependency
82
+ ────╯
83
+
84
+ [PLUGIN_TIMINGS] Warning: Your build spent significant time in plugin `rolldown-plugin-dts:generate`. See https://rolldown.rs/options/checks#plugintimings for more details.
85
+
86
+ βœ” Build complete in 12440ms
package/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2024 - present, Bereket Engida
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ this software and associated documentation files (the β€œSoftware”), to deal in
6
+ the Software without restriction, including without limitation the rights to
7
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ the Software, and to permit persons to whom the Software is furnished to do so,
9
+ subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED β€œAS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
+ DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ import { Logger, testAdapter } from "./test-adapter.mjs";
2
+ import { InsertRandomFn, TestEntry, TestSuiteStats, createTestSuite } from "./create-test-suite.mjs";
3
+ export { type InsertRandomFn, type Logger, type TestEntry, type TestSuiteStats, createTestSuite, testAdapter };
@@ -0,0 +1,4 @@
1
+ import { createTestSuite } from "./create-test-suite.mjs";
2
+ import { testAdapter } from "./test-adapter.mjs";
3
+
4
+ export { createTestSuite, testAdapter };
@@ -0,0 +1,118 @@
1
+ import { Logger } from "./test-adapter.mjs";
2
+ import { Account, Session, User, Verification } from "@better-auth/core/db";
3
+ import { DBAdapter } from "@better-auth/core/db/adapter";
4
+ import { Auth } from "better-auth";
5
+ import { BetterAuthOptions } from "@better-auth/core";
6
+
7
+ //#region src/adapter/create-test-suite.d.ts
8
+ /**
9
+ * Test entry type that supports both callback and object formats.
10
+ * Object format allows specifying migration options that will be applied before the test runs.
11
+ */
12
+ type TestEntry = ((context: {
13
+ readonly skip: {
14
+ (note?: string | undefined): never;
15
+ (condition: boolean, note?: string | undefined): void;
16
+ };
17
+ }) => Promise<void>) | {
18
+ migrateBetterAuth?: BetterAuthOptions;
19
+ test: (context: {
20
+ readonly skip: {
21
+ (note?: string | undefined): never;
22
+ (condition: boolean, note?: string | undefined): void;
23
+ };
24
+ }) => Promise<void>;
25
+ };
26
+ /**
27
+ * Statistics tracking for test suites.
28
+ */
29
+ type TestSuiteStats = {
30
+ migrationCount: number;
31
+ totalMigrationTime: number;
32
+ testCount: number;
33
+ suiteStartTime: number;
34
+ suiteDuration: number;
35
+ suiteName: string;
36
+ groupingStats?: {
37
+ totalGroups: number;
38
+ averageTestsPerGroup: number;
39
+ largestGroupSize: number;
40
+ smallestGroupSize: number;
41
+ groupsWithMultipleTests: number;
42
+ totalTestsInGroups: number;
43
+ };
44
+ };
45
+ type GenerateFn = <M extends "user" | "session" | "verification" | "account">(Model: M) => Promise<M extends "user" ? User : M extends "session" ? Session : M extends "verification" ? Verification : M extends "account" ? Account : undefined>;
46
+ type Success<T> = {
47
+ data: T;
48
+ error: null;
49
+ };
50
+ type Failure<E> = {
51
+ data: null;
52
+ error: E;
53
+ };
54
+ type Result<T, E = Error> = Success<T> | Failure<E>;
55
+ type InsertRandomFn = <M extends "user" | "session" | "verification" | "account", Count extends number = 1>(model: M, count?: Count | undefined) => Promise<Count extends 1 ? M extends "user" ? [User] : M extends "session" ? [User, Session] : M extends "verification" ? [Verification] : M extends "account" ? [User, Account] : [undefined] : Array<M extends "user" ? [User] : M extends "session" ? [User, Session] : M extends "verification" ? [Verification] : M extends "account" ? [User, Account] : [undefined]>>;
56
+ declare const createTestSuite: <Tests extends Record<string, TestEntry>, AdditionalOptions extends Record<string, any> = {}>(suiteName: string, config: {
57
+ defaultBetterAuthOptions?: BetterAuthOptions | undefined;
58
+ /**
59
+ * Helpful if the default better auth options require migrations to be run.
60
+ */
61
+ alwaysMigrate?: boolean | undefined;
62
+ prefixTests?: string | undefined;
63
+ customIdGenerator?: () => any | Promise<any> | undefined;
64
+ }, tests: (helpers: {
65
+ adapter: DBAdapter;
66
+ log: Logger;
67
+ generate: GenerateFn;
68
+ insertRandom: InsertRandomFn;
69
+ /**
70
+ * A light cleanup function that will only delete rows it knows about.
71
+ */
72
+ cleanup: () => Promise<void>;
73
+ /**
74
+ * A hard cleanup function that will delete all rows from the database.
75
+ */
76
+ hardCleanup: () => Promise<void>;
77
+ modifyBetterAuthOptions: (options: BetterAuthOptions, shouldRunMigrations: boolean) => Promise<BetterAuthOptions>;
78
+ getBetterAuthOptions: () => BetterAuthOptions;
79
+ sortModels: (models: Array<Record<string, any> & {
80
+ id: string;
81
+ }>, by?: ("id" | "createdAt") | undefined) => (Record<string, any> & {
82
+ id: string;
83
+ })[];
84
+ getAuth: () => Promise<Auth>;
85
+ tryCatch<T, E = Error>(promise: Promise<T>): Promise<Result<T, E>>;
86
+ customIdGenerator?: () => any | Promise<any> | undefined;
87
+ transformIdOutput?: (id: any) => string | undefined;
88
+ /**
89
+ * Some adapters may change the ID type, this function allows you to pass the entire model
90
+ * data and it will return the correct better-auth-expected transformed data.
91
+ *
92
+ * Eg:
93
+ * MongoDB uses ObjectId for IDs, but it's possible the user can disable that option in the adapter config.
94
+ * Because of this, the expected data would be a string.
95
+ * These sorts of conversions will cause issues with the test when you use the `generate` function.
96
+ * This is because the `generate` function will return the raw data expected to be saved in DB, not the excpected BA output.
97
+ */
98
+ transformGeneratedModel: (data: Record<string, any>) => Record<string, any>;
99
+ }, additionalOptions?: AdditionalOptions | undefined) => Tests) => (options?: ({
100
+ disableTests?: Partial<Record<keyof Tests, boolean> & {
101
+ ALL?: boolean;
102
+ }>;
103
+ } & AdditionalOptions) | undefined) => (helpers: {
104
+ adapter: () => Promise<DBAdapter<BetterAuthOptions>>;
105
+ log: Logger;
106
+ adapterDisplayName: string;
107
+ getBetterAuthOptions: () => BetterAuthOptions;
108
+ modifyBetterAuthOptions: (options: BetterAuthOptions) => Promise<BetterAuthOptions>;
109
+ cleanup: () => Promise<void>;
110
+ runMigrations: () => Promise<void>;
111
+ prefixTests?: string | undefined;
112
+ onTestFinish: (stats: TestSuiteStats) => Promise<void>;
113
+ customIdGenerator?: () => any | Promise<any> | undefined;
114
+ transformIdOutput?: (id: any) => string | undefined;
115
+ }) => Promise<void>;
116
+ //#endregion
117
+ export { InsertRandomFn, TestEntry, TestSuiteStats, createTestSuite };
118
+ //# sourceMappingURL=create-test-suite.d.mts.map