neon-testing 1.1.1 → 2.0.1-beta.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
@@ -25,11 +25,11 @@ Each test file runs against its own isolated PostgreSQL database (Neon branch),
25
25
 
26
26
  ### Test isolation
27
27
 
28
- Tests within a test file share the same database instance (Neon branch), so while all test files are isolated, tests within a test file are intentionally not.
28
+ Tests in the same file share a single database instance (Neon branch). This means test files are fully isolated from each other, but individual tests within a file are intentionally not isolated.
29
29
 
30
- This works because Vitest runs test files in parallel, but tests within each test file run sequentially one at a time.
30
+ This works because Vitest runs test files in [parallel](https://vitest.dev/guide/parallelism.html), while tests within each file run sequentially.
31
31
 
32
- If you prefer individual tests within a test file to be isolated, [simply clean up the database in a beforeEach lifecycle](examples/isolated.test.ts).
32
+ If you prefer individual tests to be isolated, you can [reset the database](examples/isolated.test.ts) in a `beforeEach` lifecycle hook.
33
33
 
34
34
  ## Quick start
35
35
 
@@ -184,7 +184,7 @@ The function identifies test branches by looking for the `integration-test: true
184
184
  The `lazySingleton()` function creates a lazy singleton from a factory function. This is useful for managing database connections efficiently:
185
185
 
186
186
  ```typescript
187
- import { lazySingleton } from "neon-testing";
187
+ import { lazySingleton } from "neon-testing/utils";
188
188
  import { neon } from "@neondatabase/serverless";
189
189
 
190
190
  const sql = lazySingleton(() => neon(process.env.DATABASE_URL!));
package/index.ts CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  import { afterAll, beforeAll } from "vitest";
10
10
  import { neonConfig } from "@neondatabase/serverless";
11
11
 
12
- export { lazySingleton } from "./singleton";
12
+ export * from "./utils";
13
13
 
14
14
  /**
15
15
  * Creates a PostgreSQL connection URI from connection parameters
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "neon-testing",
3
- "version": "1.1.1",
3
+ "version": "2.0.1-beta.0",
4
4
  "description": "A Vitest utility for seamless integration tests with Neon Postgres",
5
5
  "keywords": [
6
6
  "neon",
7
7
  "postgres",
8
8
  "postgresql",
9
- "testing",
10
9
  "vitest"
11
10
  ],
12
11
  "author": "Mikael Lirbank",
@@ -14,33 +13,42 @@
14
13
  "repository": "https://github.com/starmode-base/neon-testing",
15
14
  "homepage": "https://github.com/starmode-base/neon-testing",
16
15
  "bugs": "https://github.com/starmode-base/neon-testing/issues",
17
- "module": "index.ts",
18
16
  "type": "module",
17
+ "exports": {
18
+ ".": "./index.ts",
19
+ "./utils": "./utils.ts"
20
+ },
19
21
  "files": [
20
22
  "index.ts",
21
- "singleton.ts"
23
+ "utils.ts",
24
+ "singleton.ts",
25
+ "vite-plugin.ts",
26
+ "vitest-setup.ts"
22
27
  ],
23
28
  "scripts": {
24
29
  "test": "vitest",
25
30
  "format": "prettier --write .",
26
- "release": "bun publish",
27
- "prepublishOnly": "git diff-index --quiet HEAD || (echo 'Error: You have uncommitted changes' && exit 1) && tsc && vitest run && prettier --check .",
28
- "postpublish": "git tag v$(bun -p \"require('./package.json').version\") && git push --tags"
31
+ "release:patch": "bun pm version patch && bun publish --tag latest",
32
+ "release:minor": "bun pm version minor && bun publish --tag latest",
33
+ "release:major": "bun pm version major && bun publish --tag latest",
34
+ "release:beta": "bun pm version prerelease --preid=beta && bun publish --tag beta",
35
+ "prepublishOnly": "git diff-index --quiet HEAD || (echo 'Error: You have uncommitted changes' && exit 1) && tsc && vitest run && prettier --check ."
29
36
  },
30
37
  "dependencies": {
31
38
  "@neondatabase/api-client": "^2.2.0"
32
39
  },
33
40
  "peerDependencies": {
34
- "vitest": "^3.2.4"
41
+ "vitest": "^3"
35
42
  },
36
43
  "devDependencies": {
37
44
  "@neondatabase/serverless": "^1.0.1",
38
45
  "dotenv": "^17.2.1",
39
- "drizzle-orm": "^0.44.4",
46
+ "drizzle-orm": "^0.44.5",
40
47
  "pg": "^8.16.3",
41
48
  "postgres": "^3.4.7",
42
49
  "prettier": "^3.6.2",
43
50
  "typescript": "^5.9.2",
51
+ "vite-tsconfig-paths": "^5.1.4",
44
52
  "vitest": "^3.2.4"
45
53
  }
46
54
  }
package/utils.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { lazySingleton } from "./singleton";
2
+ export { neonTesting } from "./vite-plugin";
package/vite-plugin.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { fileURLToPath } from "node:url";
2
+ import type { Plugin, UserConfig } from "vite";
3
+
4
+ export function neonTesting() {
5
+ return {
6
+ name: "neon-testing-plugin",
7
+ enforce: "pre",
8
+ config(user: any) {
9
+ const setupPath = fileURLToPath(
10
+ new URL("./vitest-setup.ts", import.meta.url),
11
+ );
12
+
13
+ const setup = new Set([...(user.test?.setupFiles ?? []), setupPath]);
14
+
15
+ return {
16
+ test: {
17
+ setupFiles: Array.from(setup),
18
+ },
19
+ };
20
+ },
21
+ } satisfies Plugin;
22
+ }
@@ -0,0 +1,12 @@
1
+ const isVitest =
2
+ process.env.VITEST === "true" || !!process.env.VITEST_WORKER_ID;
3
+
4
+ if (isVitest) {
5
+ if (process.env.DATABASE_URL) {
6
+ console.warn(
7
+ "[neon-testing] Clearing existing DATABASE_URL in test environment",
8
+ );
9
+ }
10
+
11
+ delete process.env.DATABASE_URL;
12
+ }