test: skip if adapter doesn't support transaction (#4753)

This commit is contained in:
Alex Yang
2025-09-18 15:33:08 +00:00
committed by GitHub
parent bb1a520432
commit 8cd7d40abb
4 changed files with 43 additions and 5 deletions
@@ -20,7 +20,7 @@ exports[`init > should match config 1`] = `
"supportsDates": false,
"supportsJSON": false,
"supportsNumericIds": true,
"transaction": [Function],
"transaction": false,
"usePlural": undefined,
},
"debugLogs": false,
+29 -2
View File
@@ -874,12 +874,26 @@ async function adapterTest(
test.skipIf(disabledTests?.SHOULD_ROLLBACK_FAILING_TRANSACTION)(
`${testPrefix ? `${testPrefix} - ` : ""}${adapterTests.SHOULD_ROLLBACK_FAILING_TRANSACTION}`,
async ({ onTestFailed }) => {
async ({ onTestFailed, skip }) => {
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const customAdapter = await adapter();
// Check if adapter actually supports transactions
const enableTransaction =
customAdapter?.options?.adapterConfig.transaction;
if (!enableTransaction) {
skip(
`Skipping test: ${
customAdapter?.options?.adapterConfig.adapterName || "Adapter"
}
does not support transactions`,
);
return;
}
const user5 = {
name: "user5",
email: getUniqueEmail("user5@email.com"),
@@ -924,12 +938,25 @@ async function adapterTest(
test.skipIf(disabledTests?.SHOULD_RETURN_TRANSACTION_RESULT)(
`${testPrefix ? `${testPrefix} - ` : ""}${adapterTests.SHOULD_RETURN_TRANSACTION_RESULT}`,
async ({ onTestFailed }) => {
async ({ onTestFailed, skip }) => {
await resetDebugLogs();
onTestFailed(async () => {
await printDebugLogs();
});
const customAdapter = await adapter();
const enableTransaction =
customAdapter?.options?.adapterConfig.transaction;
if (!enableTransaction) {
skip(
`Skipping test: ${
customAdapter?.options?.adapterConfig.adapterName || "Adapter"
}
does not support transactions`,
);
return;
}
const result = await customAdapter.transaction(async (tx) => {
const createdUser = await tx.create<User>({
model: "user",
@@ -77,8 +77,11 @@ describe("sign-up with custom fields", async (it) => {
});
});
it("should rollback when session creation fails", async () => {
it("should rollback when session creation fails", async ({ skip }) => {
const ctx = await auth.$context;
if (!ctx.adapter.options?.adapterConfig.transaction) {
skip();
}
const originalCreateSession = ctx.internalAdapter.createSession;
ctx.internalAdapter.createSession = vi
.fn()
@@ -92,7 +92,9 @@ describe("organization creation in database hooks", async () => {
});
});
it("should handle errors gracefully when organization creation fails in hook", async () => {
it("should handle errors gracefully when organization creation fails in hook", async ({
skip,
}) => {
let firstUserCreated = false;
let errorOnSecondUser: any = null;
@@ -123,6 +125,12 @@ describe("organization creation in database hooks", async () => {
},
});
if (!db.options?.adapterConfig.transaction) {
skip(
"Skipping since transactions are enabled and will rollback automatically",
);
}
// First user should succeed
const result1 = await client.signUp.email({
email: "user1-hook@example.com",