@vaharoni/devops 1.2.14 → 1.2.15

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.
@@ -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
- * Create a `vitest.config.ts` in the project's folder with the following content.
7
- * Adjust the path to the setup file based on the nesting of the project's folder.
8
-
9
- import { defineConfig } from 'vitest/config'
10
-
11
- export default defineConfig({
12
- test: {
13
- setupFiles: ['../../db/prisma-setup-vitest.ts']
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', () => ({ prisma }));
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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vaharoni/devops",
3
3
  "type": "module",
4
- "version": "1.2.14",
4
+ "version": "1.2.15",
5
5
  "description": "Devops utility",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
@@ -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
- * Create a `vitest.config.ts` in the project's folder with the following content.
7
- * Adjust the path to the setup file based on the nesting of the project's folder.
8
-
9
- import { defineConfig } from 'vitest/config'
10
-
11
- export default defineConfig({
12
- test: {
13
- setupFiles: ['../../db/prisma-setup-vitest.ts']
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', () => ({ prisma }));
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();