@vaharoni/devops 1.2.14 → 1.2.16
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.
- package/dist/src/target-templates/lang-variants-prisma/typescript/db/db-client-test.ts +8 -12
- package/dist/src/target-templates/lang-variants-prisma/typescript/db/prisma-setup-vitest.ts +26 -12
- package/package.json +1 -1
- package/src/target-templates/lang-variants-prisma/typescript/db/db-client-test.ts +8 -12
- package/src/target-templates/lang-variants-prisma/typescript/db/prisma-setup-vitest.ts +26 -12
|
@@ -107,16 +107,6 @@ export const prismaClientSingleton = () => {
|
|
|
107
107
|
return client as unknown as ExtendedTransactionClient | FlatTransactionClient;
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
-
// Use the same global singleton key as db-client.ts (prismaGlobal)
|
|
111
|
-
// This ensures all code importing from "db" uses the same transactional client
|
|
112
|
-
declare global {
|
|
113
|
-
// eslint-disable-next-line no-var
|
|
114
|
-
var prismaGlobal:
|
|
115
|
-
| ExtendedTransactionClient
|
|
116
|
-
| FlatTransactionClient
|
|
117
|
-
| undefined;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
110
|
export type ExtendedTransactionClient = Prisma.TransactionClient & {
|
|
121
111
|
$begin: () => Promise<FlatTransactionClient>;
|
|
122
112
|
};
|
|
@@ -126,10 +116,16 @@ export type FlatTransactionClient = Prisma.TransactionClient & {
|
|
|
126
116
|
$rollback: () => Promise<void>;
|
|
127
117
|
};
|
|
128
118
|
|
|
119
|
+
// Use the same global singleton key as db-client.ts (prismaGlobal)
|
|
120
|
+
// This ensures all code importing from "db" uses the same transactional client
|
|
121
|
+
// Note: We don't redeclare the global type here to avoid conflicts with db-client.ts
|
|
122
|
+
// when the IDE loads both files. We use type assertions instead.
|
|
123
|
+
type TestPrismaGlobal = ExtendedTransactionClient | FlatTransactionClient | undefined;
|
|
124
|
+
|
|
129
125
|
const prisma: ExtendedTransactionClient | FlatTransactionClient =
|
|
130
|
-
globalThis.prismaGlobal ?? prismaClientSingleton();
|
|
126
|
+
(globalThis.prismaGlobal as TestPrismaGlobal) ?? prismaClientSingleton();
|
|
131
127
|
|
|
132
|
-
globalThis.prismaGlobal = prisma;
|
|
128
|
+
(globalThis as { prismaGlobal: TestPrismaGlobal }).prismaGlobal = prisma;
|
|
133
129
|
|
|
134
130
|
export { prisma };
|
|
135
131
|
|
|
@@ -2,21 +2,35 @@ import { afterEach, beforeEach, vi } from 'vitest';
|
|
|
2
2
|
import { prisma, rollbackTx, startTx } from './db-client-test';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
+
* Vitest setup for Prisma transactional tests.
|
|
6
|
+
*
|
|
7
|
+
* Each test runs inside a transaction that is rolled back after the test completes,
|
|
8
|
+
* ensuring test isolation without persisting data to the database.
|
|
9
|
+
*
|
|
5
10
|
* Usage:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
* Create a `vitest.config.ts` in the project's folder:
|
|
12
|
+
*
|
|
13
|
+
* import { defineConfig } from 'vitest/config'
|
|
14
|
+
* export default defineConfig({
|
|
15
|
+
* test: {
|
|
16
|
+
* setupFiles: ['../../db/prisma-setup-vitest.ts'] // adjust path as needed
|
|
17
|
+
* },
|
|
18
|
+
* })
|
|
19
|
+
*
|
|
20
|
+
* How it works:
|
|
21
|
+
* - db-client-test.ts creates a transactional Prisma client and stores it in globalThis.prismaGlobal
|
|
22
|
+
* - This is the same singleton key used by db/db-client.ts
|
|
23
|
+
* - All code importing from "db" gets the transactional client
|
|
24
|
+
* - beforeEach starts a transaction, afterEach rolls it back
|
|
17
25
|
*/
|
|
18
26
|
|
|
19
|
-
vi.mock('db', () =>
|
|
27
|
+
vi.mock('db', async () => {
|
|
28
|
+
const prismaClient = await import('@prisma/client');
|
|
29
|
+
return {
|
|
30
|
+
...prismaClient,
|
|
31
|
+
prisma,
|
|
32
|
+
};
|
|
33
|
+
});
|
|
20
34
|
|
|
21
35
|
beforeEach(async () => {
|
|
22
36
|
await startTx();
|
package/package.json
CHANGED
|
@@ -107,16 +107,6 @@ export const prismaClientSingleton = () => {
|
|
|
107
107
|
return client as unknown as ExtendedTransactionClient | FlatTransactionClient;
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
-
// Use the same global singleton key as db-client.ts (prismaGlobal)
|
|
111
|
-
// This ensures all code importing from "db" uses the same transactional client
|
|
112
|
-
declare global {
|
|
113
|
-
// eslint-disable-next-line no-var
|
|
114
|
-
var prismaGlobal:
|
|
115
|
-
| ExtendedTransactionClient
|
|
116
|
-
| FlatTransactionClient
|
|
117
|
-
| undefined;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
110
|
export type ExtendedTransactionClient = Prisma.TransactionClient & {
|
|
121
111
|
$begin: () => Promise<FlatTransactionClient>;
|
|
122
112
|
};
|
|
@@ -126,10 +116,16 @@ export type FlatTransactionClient = Prisma.TransactionClient & {
|
|
|
126
116
|
$rollback: () => Promise<void>;
|
|
127
117
|
};
|
|
128
118
|
|
|
119
|
+
// Use the same global singleton key as db-client.ts (prismaGlobal)
|
|
120
|
+
// This ensures all code importing from "db" uses the same transactional client
|
|
121
|
+
// Note: We don't redeclare the global type here to avoid conflicts with db-client.ts
|
|
122
|
+
// when the IDE loads both files. We use type assertions instead.
|
|
123
|
+
type TestPrismaGlobal = ExtendedTransactionClient | FlatTransactionClient | undefined;
|
|
124
|
+
|
|
129
125
|
const prisma: ExtendedTransactionClient | FlatTransactionClient =
|
|
130
|
-
globalThis.prismaGlobal ?? prismaClientSingleton();
|
|
126
|
+
(globalThis.prismaGlobal as TestPrismaGlobal) ?? prismaClientSingleton();
|
|
131
127
|
|
|
132
|
-
globalThis.prismaGlobal = prisma;
|
|
128
|
+
(globalThis as { prismaGlobal: TestPrismaGlobal }).prismaGlobal = prisma;
|
|
133
129
|
|
|
134
130
|
export { prisma };
|
|
135
131
|
|
|
@@ -2,21 +2,35 @@ import { afterEach, beforeEach, vi } from 'vitest';
|
|
|
2
2
|
import { prisma, rollbackTx, startTx } from './db-client-test';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
+
* Vitest setup for Prisma transactional tests.
|
|
6
|
+
*
|
|
7
|
+
* Each test runs inside a transaction that is rolled back after the test completes,
|
|
8
|
+
* ensuring test isolation without persisting data to the database.
|
|
9
|
+
*
|
|
5
10
|
* Usage:
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
* Create a `vitest.config.ts` in the project's folder:
|
|
12
|
+
*
|
|
13
|
+
* import { defineConfig } from 'vitest/config'
|
|
14
|
+
* export default defineConfig({
|
|
15
|
+
* test: {
|
|
16
|
+
* setupFiles: ['../../db/prisma-setup-vitest.ts'] // adjust path as needed
|
|
17
|
+
* },
|
|
18
|
+
* })
|
|
19
|
+
*
|
|
20
|
+
* How it works:
|
|
21
|
+
* - db-client-test.ts creates a transactional Prisma client and stores it in globalThis.prismaGlobal
|
|
22
|
+
* - This is the same singleton key used by db/db-client.ts
|
|
23
|
+
* - All code importing from "db" gets the transactional client
|
|
24
|
+
* - beforeEach starts a transaction, afterEach rolls it back
|
|
17
25
|
*/
|
|
18
26
|
|
|
19
|
-
vi.mock('db', () =>
|
|
27
|
+
vi.mock('db', async () => {
|
|
28
|
+
const prismaClient = await import('@prisma/client');
|
|
29
|
+
return {
|
|
30
|
+
...prismaClient,
|
|
31
|
+
prisma,
|
|
32
|
+
};
|
|
33
|
+
});
|
|
20
34
|
|
|
21
35
|
beforeEach(async () => {
|
|
22
36
|
await startTx();
|