neon-testing 2.0.1-beta.9 โ†’ 2.1.0

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/README.md CHANGED
@@ -13,7 +13,7 @@ Each test file runs against its own isolated PostgreSQL database (Neon branch),
13
13
  - ๐Ÿ”„ **Isolated test environments** - Each test file runs against its own Postgres database with your actual schema and constraints
14
14
  - ๐Ÿงน **Automatic cleanup** - Neon test branches are created and destroyed automatically
15
15
  - ๐Ÿ› **Debug friendly** - Option to preserve test branches for debugging failed tests
16
- - ๐Ÿ›ก๏ธ **TypeScript native** - No JavaScript support
16
+ - ๐Ÿ›ก๏ธ **TypeScript native** - With JavaScript support
17
17
  - ๐ŸŽฏ **ESM only** - No CommonJS support
18
18
 
19
19
  ## How it works
@@ -73,7 +73,23 @@ test("database operations", async () => {
73
73
 
74
74
  ### Recommended usage
75
75
 
76
- #### 1. Configuration
76
+ #### 1. Plugin setup
77
+
78
+ First, add the Vite plugin to clear any existing `DATABASE_URL` environment variable before tests run, ensuring tests use isolated test databases.
79
+
80
+ ```typescript
81
+ // vitest.config.ts or vite.config.ts
82
+ import { defineConfig } from "vitest/config";
83
+ import { neonTesting } from "neon-testing/utils";
84
+
85
+ export default defineConfig({
86
+ plugins: [neonTesting()],
87
+ });
88
+ ```
89
+
90
+ This plugin is recommended but not required. Without it, tests might accidentally use your existing `DATABASE_URL` (from `.env` files or environment variables) instead of the isolated test databases that neon-testing creates. This can happen if you forget to call `withNeonTestBranch()` in a test file where database writes happen.
91
+
92
+ #### 2. Configuration
77
93
 
78
94
  Use the `makeNeonTesting` factory to generate a lifecycle function for your tests.
79
95
 
@@ -88,7 +104,7 @@ export const withNeonTestBranch = makeNeonTesting({
88
104
  });
89
105
  ```
90
106
 
91
- #### 2. Enable database testing
107
+ #### 3. Enable database testing
92
108
 
93
109
  Then call the exported test lifecycle function in the test files where you need database access.
94
110
 
@@ -164,6 +180,21 @@ import { withNeonTestBranch } from "./test-setup";
164
180
  withNeonTestBranch({ parentBranchId: "br-staging-123" });
165
181
  ```
166
182
 
183
+ ## CI/CD
184
+
185
+ It is easy to run Neon integration in CI/CD
186
+
187
+ ### GitHub Actions
188
+
189
+ [Example](.github/workflows/test.yml)
190
+
191
+ ### Vercel
192
+
193
+ Two options:
194
+
195
+ - Add `vitest run` to the `build` script in [package.json](https://github.com/starmode-base/template-tanstack-start/blob/83c784e164b55fd8d59c5b57b907251e5eb03de1/app/package.json#L11l)
196
+ - Add `vitest run` to the _Build Command_ in the Vercel dashboard
197
+
167
198
  ## Utilities
168
199
 
169
200
  ### deleteAllTestBranches()
package/dist/index.d.ts CHANGED
@@ -64,3 +64,4 @@ export declare function makeNeonTesting(factoryOptions: NeonTestingOptions): {
64
64
  (overrides?: NeonTestingOverrides): void;
65
65
  deleteAllTestBranches: () => Promise<void>;
66
66
  };
67
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AA8BA,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC/B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;;;OAOG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,mEAAmE;AACnE,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAAC,EAAE,QAAQ,CAAC,CAAC;AAE/E;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAAC,cAAc,EAAE,kBAAkB;iBA0BlD,oBAAoB;;EAmGnC"}
@@ -2,3 +2,4 @@
2
2
  * Create a lazy singleton from a factory function
3
3
  */
4
4
  export declare function lazySingleton<T>(factory: () => T): () => T;
5
+ //# sourceMappingURL=singleton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"singleton.d.ts","sourceRoot":"","sources":["../singleton.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,CAM1D"}
package/dist/utils.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { lazySingleton } from "./singleton.js";
2
2
  export { neonTesting } from "./vite-plugin.js";
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1,2 +1,10 @@
1
1
  import type { Plugin } from "vite";
2
- export declare function neonTesting(): Plugin;
2
+ export declare function neonTesting(options?: {
3
+ /**
4
+ * Enable debug logging.
5
+ *
6
+ * @default false
7
+ */
8
+ debug?: boolean;
9
+ }): Plugin;
10
+ //# sourceMappingURL=vite-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../vite-plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,wBAAgB,WAAW,CACzB,OAAO,GAAE;IACP;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACZ,GACL,MAAM,CAyBR"}
@@ -1,14 +1,20 @@
1
1
  import { fileURLToPath } from "node:url";
2
- export function neonTesting() {
2
+ export function neonTesting(options = {}) {
3
3
  return {
4
4
  name: "neon-testing-plugin",
5
- enforce: "pre",
5
+ // Run as late as possible to reduce the risk of other plugins restoring
6
+ // DATABASE_URL after we clear it
7
+ enforce: "post",
6
8
  config(user) {
7
9
  const setupPath = fileURLToPath(new URL("./vitest-setup.js", import.meta.url));
8
- const setup = new Set([...(user.test?.setupFiles ?? []), setupPath]);
9
10
  return {
10
11
  test: {
11
- setupFiles: Array.from(setup),
12
+ // Register the vitest-setup.js file to run after other setup files
13
+ setupFiles: Array.from(new Set([...(user.test?.setupFiles ?? []), setupPath])),
14
+ env: {
15
+ ...user.test?.env,
16
+ NEON_TESTING_DEBUG: options.debug ? "true" : "false",
17
+ },
12
18
  },
13
19
  };
14
20
  },
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,MAAM,UAAU,WAAW;IACzB,OAAO;QACL,IAAI,EAAE,qBAAqB;QAC3B,OAAO,EAAE,KAAK;QACd,MAAM,CAAC,IAAI;YACT,MAAM,SAAS,GAAG,aAAa,CAC7B,IAAI,GAAG,CAAC,mBAAmB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAC9C,CAAC;YAEF,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,IAAI,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;YAErE,OAAO;gBACL,IAAI,EAAE;oBACJ,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;iBAC9B;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGzC,MAAM,UAAU,WAAW,CACzB,UAOI,EAAE;IAEN,OAAO;QACL,IAAI,EAAE,qBAAqB;QAC3B,wEAAwE;QACxE,iCAAiC;QACjC,OAAO,EAAE,MAAM;QACf,MAAM,CAAC,IAAI;YACT,MAAM,SAAS,GAAG,aAAa,CAC7B,IAAI,GAAG,CAAC,mBAAmB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAC9C,CAAC;YAEF,OAAO;gBACL,IAAI,EAAE;oBACJ,mEAAmE;oBACnE,UAAU,EAAE,KAAK,CAAC,IAAI,CACpB,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,IAAI,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,CACvD;oBACD,GAAG,EAAE;wBACH,GAAG,IAAI,CAAC,IAAI,EAAE,GAAG;wBACjB,kBAAkB,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;qBACrD;iBACF;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const isVitest: string | undefined;
2
+ declare const isDebug: boolean;
3
+ //# sourceMappingURL=vitest-setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vitest-setup.d.ts","sourceRoot":"","sources":["../vitest-setup.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,QAAQ,oBAAqB,CAAC;AACpC,QAAA,MAAM,OAAO,SAA4C,CAAC"}
@@ -1,11 +1,10 @@
1
+ "use strict";
1
2
  const isVitest = process.env.VITEST;
2
-
3
+ const isDebug = process.env.NEON_TESTING_DEBUG === "true";
3
4
  if (isVitest) {
4
- if (process.env.DATABASE_URL) {
5
- console.warn(
6
- "[neon-testing] Clearing existing DATABASE_URL in test environment",
7
- );
8
- }
9
-
10
- delete process.env.DATABASE_URL;
5
+ if (process.env.DATABASE_URL && isDebug) {
6
+ console.debug("[neon-testing] Clearing existing DATABASE_URL in test environment");
7
+ }
8
+ delete process.env.DATABASE_URL;
11
9
  }
10
+ //# sourceMappingURL=vitest-setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vitest-setup.js","sourceRoot":"","sources":["../vitest-setup.ts"],"names":[],"mappings":";AAAA,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC;AACpC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,MAAM,CAAC;AAE1D,IAAI,QAAQ,EAAE,CAAC;IACb,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,OAAO,EAAE,CAAC;QACxC,OAAO,CAAC,KAAK,CACX,mEAAmE,CACpE,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;AAClC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neon-testing",
3
- "version": "2.0.1-beta.9",
3
+ "version": "2.1.0",
4
4
  "description": "A Vitest utility for seamless integration tests with Neon Postgres",
5
5
  "keywords": [
6
6
  "neon",
@@ -22,26 +22,20 @@
22
22
  "./utils": {
23
23
  "types": "./dist/utils.d.ts",
24
24
  "import": "./dist/utils.js"
25
- },
26
- "./vite-plugin": {
27
- "types": "./dist/vite-plugin.d.ts",
28
- "import": "./dist/vite-plugin.js"
29
25
  }
30
26
  },
31
- "types": "./dist/index.d.ts",
32
27
  "files": [
33
- "dist",
34
- "vitest-setup.js"
28
+ "dist"
35
29
  ],
36
30
  "scripts": {
31
+ "build": "rm -rf dist && tsc",
37
32
  "test": "vitest",
38
33
  "format": "prettier --write .",
39
- "build": "rm -rf dist && tsc -p tsconfig.build.json && cp vitest-setup.js dist/",
40
- "release:patch": "bun pm version patch && bun publish --tag latest",
41
- "release:minor": "bun pm version minor && bun publish --tag latest",
42
- "release:major": "bun pm version major && bun publish --tag latest",
43
- "release:beta": "bun pm version prerelease --preid=beta && bun publish --tag beta",
44
- "prepublishOnly": "bun run build && vitest run && prettier --check .",
34
+ "check": "bun run build && bunx vitest run && bunx prettier --check .",
35
+ "release:patch": "bun run check && bun pm version patch && bun publish --tag latest",
36
+ "release:minor": "bun run check && bun pm version minor && bun publish --tag latest",
37
+ "release:major": "bun run check && bun pm version major && bun publish --tag latest",
38
+ "release:beta": "bun run check && bun pm version prerelease --preid=beta && bun publish --tag beta",
45
39
  "postpublish": "git push --follow-tags"
46
40
  },
47
41
  "dependencies": {
package/vitest-setup.js DELETED
@@ -1,11 +0,0 @@
1
- const isVitest = process.env.VITEST;
2
-
3
- if (isVitest) {
4
- if (process.env.DATABASE_URL) {
5
- console.warn(
6
- "[neon-testing] Clearing existing DATABASE_URL in test environment",
7
- );
8
- }
9
-
10
- delete process.env.DATABASE_URL;
11
- }