[PR #4844] [MERGED] chore: fix adapter tests #31210

Closed
opened 2026-04-17 22:07:06 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4844
Author: @ping-maxwell
Created: 9/23/2025
Status: Merged
Merged: 9/30/2025
Merged by: @himself65

Base: canaryHead: fix/adapter-tests


📝 Commits (10+)

📊 Changes

73 files changed (+3681 additions, -1824 deletions)

View changed files

📝 biome.json (+2 -1)
📝 docker-compose.yml (+60 -2)
📝 docs/content/docs/adapters/mssql.mdx (+4 -0)
📝 docs/content/docs/adapters/mysql.mdx (+1 -0)
📝 packages/better-auth/package.json (+2 -1)
📝 packages/better-auth/src/__snapshots__/init.test.ts.snap (+2 -0)
📝 packages/better-auth/src/adapters/adapter-factory/index.ts (+93 -79)
📝 packages/better-auth/src/adapters/adapter-factory/types.ts (+31 -0)
packages/better-auth/src/adapters/create-test-suite.ts (+534 -0)
packages/better-auth/src/adapters/drizzle-adapter/test/.gitignore (+2 -0)
📝 packages/better-auth/src/adapters/drizzle-adapter/test/adapter.drizzle.mysql.test.ts (+75 -188)
packages/better-auth/src/adapters/drizzle-adapter/test/adapter.drizzle.pg.test.ts (+73 -0)
packages/better-auth/src/adapters/drizzle-adapter/test/adapter.drizzle.sqlite.test.ts (+77 -0)
packages/better-auth/src/adapters/drizzle-adapter/test/adapter.drizzle.test.ts (+0 -183)
packages/better-auth/src/adapters/drizzle-adapter/test/generate-schema.ts (+98 -0)
packages/better-auth/src/adapters/drizzle-adapter/test/schema.mysql.ts (+0 -53)
packages/better-auth/src/adapters/drizzle-adapter/test/schema.ts (+0 -64)
📝 packages/better-auth/src/adapters/kysely-adapter/kysely-adapter.ts (+22 -11)
packages/better-auth/src/adapters/kysely-adapter/test/adapter.kysely.mssql.test.ts (+317 -0)
packages/better-auth/src/adapters/kysely-adapter/test/adapter.kysely.mysql.test.ts (+63 -0)

...and 53 more files

📄 Description

TLDR

  • New adapter test systems
  • New DB conflict prevention systems (removes the old STATE.txt stuff)
    • Update: Given that all tests are now able to run independently, we can remove the conflict prevention system ^
  • Fixed a bunch of DB inconsistency issues
    • kysely + pg using adapter.count returns a string
    • mysql dates returns with incorrect timezones
    • mysql dates do not store milliseconds - unlike all other DBs
      • fixed findOne/many operators related to dates giving inconsistent results
    • probably others that I forgot
  • New unit tests
  • Fixed schema generation issues:
    • Prisma generates maps that break custom fields
    • Drizzle for sqlite will have missing imports
    • Drizzle for sqlite doesn’t have autoIncrement in the PK when using useNumberId
    • Drizzle for sqlite doesn’t store dates in milliseconds
    • Drizzle for mysql doesn't store dates in milliseconds
  • I fixed mongo adapter to actually use the where clause when using adapter.count
  • Improved the performance of findOne to actually use the select in mongo adapter.

Warnings for existing users

Drizzle + Sqlite users

Currently, we do not store milliseconds of dates if the schema was generated by our CLI.

To fix this, please update your schema by changing all integer('${name}', { mode: 'timestamp' }) to integer('${name}', { mode: 'timestamp_ms' }) or by running our latest version CLI generate command again.

And don't forget to push your schema!

MSSQL users

Please update your schema to use datetime2 over datetime for any date fields previously generated by Better-Auth.
MSSQL datetime only stores time to an accuracy of ~3.33 milliseconds. This means when you insert a JS date into a datetime column, SQL Server rounds the fractional seconds to the nearest 0, 3, or 7 ms increment. To resolve this, it's recommended to use datetime2.

As of now, Kysely uses datetime and not datetime2 by default (this is being changed)

Read more about the active Kysely issue here if interested: https://github.com/kysely-org/kysely/issues/1596

Please also update the Tedious config to include the DateTime2 types:

new MssqlDialect({
	tarn: {
		...Tarn,
		options: {
			min: 0,
			max: 10,
		},
	},
	tedious: {
		...Tedious,
		connectionFactory: () =>
			new Tedious.Connection({/*...*/}),
+		TYPES: {
+			...Tedious.TYPES,
+			DateTime: Tedious.TYPES.DateTime2,
+		},
	},
});

Summary by cubic

Refactored and unified the adapter test infrastructure, adding reusable test suites and schema generation, while fixing transactions, field mapping, and comparison operators across adapters.

  • New Features

    • Added createTestSuite and testAdapter to compose and run adapter tests with cleanup, migrations, and logging.
    • Introduced reusable suites: normal, transactions, auth-flow, performance.
    • Generated Drizzle schema from BetterAuth options per dialect (mysql, pg, sqlite).
    • Scoped debug logs by adapter instance; added print/reset helpers.
    • Exposed transformInput/transformOutput/transformWhereClause to custom adapters; added flags to disable transforms when wrapping adapters.
    • Memory adapter: added ne, gt/gte, lt/lte operators.
    • Exported testing utilities from adapters; added MySQL, Postgres, and SQLite adapter tests.
  • Refactors / Fixes

    • Transactions now await and return results correctly (Drizzle and Memory adapters) and rollback properly on failure.
    • Improved field resolution when fieldName differs from schema key.
    • Conditional application of input/output transforms to avoid double transforms in wrapper adapters.
    • Moved ANSI color helpers to utils/colors and simplified logger usage.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/4844 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 9/23/2025 **Status:** ✅ Merged **Merged:** 9/30/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/adapter-tests` --- ### 📝 Commits (10+) - [`20a66e6`](https://github.com/better-auth/better-auth/commit/20a66e6f45448f8cf07db1b159317ea884a85f66) chore: fix adapter tests - [`0e1e0bc`](https://github.com/better-auth/better-auth/commit/0e1e0bcba821898d32cd6908500423c1887d986f) chore: cleanup - [`c472897`](https://github.com/better-auth/better-auth/commit/c472897e03102fca18b61283e4243c28d713176e) chore: lint - [`0275d6d`](https://github.com/better-auth/better-auth/commit/0275d6d6b31f65961168282ec671a547378e4324) progress - [`67cfdfc`](https://github.com/better-auth/better-auth/commit/67cfdfca2b8049ec227de7dacecd4dc53d724707) update: sorting fixed for sqlite - [`b79f2dc`](https://github.com/better-auth/better-auth/commit/b79f2dca0552b09bdcae6a7a60dd847fbc0710e1) fix: kysely pg `adapter.count` returns string - [`3cbe002`](https://github.com/better-auth/better-auth/commit/3cbe00289d3ce2e947fb06899bc82d4833d968fc) Merge branch 'canary' into fix/adapter-tests - [`39e3a69`](https://github.com/better-auth/better-auth/commit/39e3a694b01eaf618965349837819689a0362f69) update: progress - [`fcb8626`](https://github.com/better-auth/better-auth/commit/fcb862607b349edbeeeed7bbe672bd7f7c271765) fix: ts issues - [`a56d309`](https://github.com/better-auth/better-auth/commit/a56d3093f68b1a5f7274441d0e3550d0670f2591) fix: ts issue ### 📊 Changes **73 files changed** (+3681 additions, -1824 deletions) <details> <summary>View changed files</summary> 📝 `biome.json` (+2 -1) 📝 `docker-compose.yml` (+60 -2) 📝 `docs/content/docs/adapters/mssql.mdx` (+4 -0) 📝 `docs/content/docs/adapters/mysql.mdx` (+1 -0) 📝 `packages/better-auth/package.json` (+2 -1) 📝 `packages/better-auth/src/__snapshots__/init.test.ts.snap` (+2 -0) 📝 `packages/better-auth/src/adapters/adapter-factory/index.ts` (+93 -79) 📝 `packages/better-auth/src/adapters/adapter-factory/types.ts` (+31 -0) ➕ `packages/better-auth/src/adapters/create-test-suite.ts` (+534 -0) ➕ `packages/better-auth/src/adapters/drizzle-adapter/test/.gitignore` (+2 -0) 📝 `packages/better-auth/src/adapters/drizzle-adapter/test/adapter.drizzle.mysql.test.ts` (+75 -188) ➕ `packages/better-auth/src/adapters/drizzle-adapter/test/adapter.drizzle.pg.test.ts` (+73 -0) ➕ `packages/better-auth/src/adapters/drizzle-adapter/test/adapter.drizzle.sqlite.test.ts` (+77 -0) ➖ `packages/better-auth/src/adapters/drizzle-adapter/test/adapter.drizzle.test.ts` (+0 -183) ➕ `packages/better-auth/src/adapters/drizzle-adapter/test/generate-schema.ts` (+98 -0) ➖ `packages/better-auth/src/adapters/drizzle-adapter/test/schema.mysql.ts` (+0 -53) ➖ `packages/better-auth/src/adapters/drizzle-adapter/test/schema.ts` (+0 -64) 📝 `packages/better-auth/src/adapters/kysely-adapter/kysely-adapter.ts` (+22 -11) ➕ `packages/better-auth/src/adapters/kysely-adapter/test/adapter.kysely.mssql.test.ts` (+317 -0) ➕ `packages/better-auth/src/adapters/kysely-adapter/test/adapter.kysely.mysql.test.ts` (+63 -0) _...and 53 more files_ </details> ### 📄 Description # TLDR * New adapter test systems * New DB conflict prevention systems (removes the old `STATE.txt` stuff) * Update: Given that all tests are now able to run independently, we can remove the conflict prevention system ^ * Fixed a bunch of DB inconsistency issues * kysely + pg using `adapter.count` returns a string * mysql dates returns with incorrect timezones * mysql dates do not store milliseconds - unlike all other DBs * fixed findOne/many operators related to dates giving inconsistent results * probably others that I forgot * New unit tests * Fixed schema generation issues: * Prisma generates maps that break custom fields * Drizzle for sqlite will have missing imports * Drizzle for sqlite doesn’t have autoIncrement in the PK when using useNumberId * Drizzle for sqlite doesn’t store dates in milliseconds * Drizzle for mysql doesn't store dates in milliseconds * I fixed mongo adapter to actually use the where clause when using adapter.count * Improved the performance of `findOne` to actually use the `select` in mongo adapter. # Warnings for existing users ## Drizzle + Sqlite users Currently, we do not store milliseconds of dates if the schema was generated by our CLI. To fix this, please update your schema by changing all `integer('${name}', { mode: 'timestamp' })` to `integer('${name}', { mode: 'timestamp_ms' })` or by running our latest version CLI generate command again. And don't forget to push your schema! ## MSSQL users Please update your schema to use `datetime2` over `datetime` for any date fields previously generated by Better-Auth. MSSQL datetime only stores time to an accuracy of ~3.33 milliseconds. This means when you insert a JS date into a datetime column, SQL Server rounds the fractional seconds to the nearest 0, 3, or 7 ms increment. To resolve this, it's recommended to use `datetime2`. As of now, Kysely uses `datetime` and not `datetime2` by default (this is being [changed](https://github.com/kysely-org/kysely/issues/1596#issuecomment-3341591075)) Read more about the active Kysely issue here if interested: https://github.com/kysely-org/kysely/issues/1596 Please also update the Tedious config to include the DateTime2 types: ```diff new MssqlDialect({ tarn: { ...Tarn, options: { min: 0, max: 10, }, }, tedious: { ...Tedious, connectionFactory: () => new Tedious.Connection({/*...*/}), + TYPES: { + ...Tedious.TYPES, + DateTime: Tedious.TYPES.DateTime2, + }, }, }); ``` --- <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Refactored and unified the adapter test infrastructure, adding reusable test suites and schema generation, while fixing transactions, field mapping, and comparison operators across adapters. - **New Features** - Added createTestSuite and testAdapter to compose and run adapter tests with cleanup, migrations, and logging. - Introduced reusable suites: normal, transactions, auth-flow, performance. - Generated Drizzle schema from BetterAuth options per dialect (mysql, pg, sqlite). - Scoped debug logs by adapter instance; added print/reset helpers. - Exposed transformInput/transformOutput/transformWhereClause to custom adapters; added flags to disable transforms when wrapping adapters. - Memory adapter: added ne, gt/gte, lt/lte operators. - Exported testing utilities from adapters; added MySQL, Postgres, and SQLite adapter tests. - **Refactors / Fixes** - Transactions now await and return results correctly (Drizzle and Memory adapters) and rollback properly on failure. - Improved field resolution when fieldName differs from schema key. - Conditional application of input/output transforms to avoid double transforms in wrapper adapters. - Moved ANSI color helpers to utils/colors and simplified logger usage. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 22:07:06 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#31210