Skip to content

Commit

Permalink
Merge pull request #132 from danielpowell4/main
Browse files Browse the repository at this point in the history
[Closes Issue #129] Adds option to configure isolation level
  • Loading branch information
Quramy committed Feb 27, 2024
2 parents 744fb6e + 70099c3 commit 98ea346
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,15 @@ export interface JestPrismaEnvironmentOptions {
*/
readonly timeout?: number;

/**
*
* Sets the transaction isolation level. By default this is set to the value currently configured in your database.
*
* @link https://www.prisma.io/docs/orm/prisma-client/queries/transactions#transaction-isolation-level
*
*/
readonly isolationLevel?: Prisma.TransactionIsolationLevel;

/**
*
* Override the database connection URL.
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-prisma-core/src/delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type PartialEnvironment = Pick<JestEnvironment<unknown>, "handleTestEvent" | "te

const DEFAULT_MAX_WAIT = 5_000;
const DEFAULT_TIMEOUT = 5_000;
const DEFAULT_ISOLATION_LEVEL = undefined; // use database default

export class PrismaEnvironmentDelegate implements PartialEnvironment {
private _originalClient: PrismaClientLike | undefined;
Expand Down Expand Up @@ -127,6 +128,7 @@ export class PrismaEnvironmentDelegate implements PartialEnvironment {
{
maxWait: this.options.maxWait ?? DEFAULT_MAX_WAIT,
timeout: this.options.timeout ?? DEFAULT_TIMEOUT,
isolationLevel: this.options.isolationLevel ?? DEFAULT_ISOLATION_LEVEL,
},
)
.catch(() => true),
Expand Down
18 changes: 17 additions & 1 deletion packages/jest-prisma-core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
type PrismaTransactionIsolationLevel =
| "ReadUncommitted"
| "ReadCommitted"
| "RepeatableRead"
| "Snapshot"
| "Serializable";

export interface PrismaClientLike {
$connect: () => Promise<unknown>;
$disconnect: () => Promise<unknown>;
$transaction: (
fn: (txClient: PrismaClientLike) => Promise<unknown>,
Options?: { maxWait: number; timeout: number },
Options?: { maxWait: number; timeout: number; isolationLevel?: PrismaTransactionIsolationLevel },
) => Promise<unknown>;
$executeRawUnsafe: (query: string) => Promise<number>;
$on: (event: "query", callbacck: (event: { readonly query: string; readonly params: string }) => unknown) => void;
Expand Down Expand Up @@ -70,6 +77,15 @@ export interface JestPrismaEnvironmentOptions {
*/
readonly timeout?: number;

/**
*
* Sets the transaction isolation level. By default this is set to the value currently configured in your database.
*
* @link https://www.prisma.io/docs/orm/prisma-client/queries/transactions#supported-isolation-levels
*
*/
readonly isolationLevel?: PrismaTransactionIsolationLevel;

/**
*
* Override the database connection URL.
Expand Down

0 comments on commit 98ea346

Please sign in to comment.