cf-bun-mocks 0.1.0-alpha.1 → 0.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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/src/d1.ts +9 -1
  3. package/src/env.ts +4 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cf-bun-mocks",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0",
4
4
  "description": "Cloudflare Workers mocks and helpers for Bun testing",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/d1.ts CHANGED
@@ -180,7 +180,15 @@ export async function initD1(migrationsPath: string): Promise<D1Mock> {
180
180
  const db = new D1Mock(":memory:");
181
181
  for (const file of files) {
182
182
  const migration = await Bun.file(path.join(migrationsPath, file)).text();
183
- await db.exec(migration);
183
+ try {
184
+ await db.exec(migration);
185
+ } catch (error) {
186
+ throw new Error(
187
+ `Failed to execute migration ${file}: ${
188
+ error instanceof Error ? error.message : String(error)
189
+ }`
190
+ );
191
+ }
184
192
  }
185
193
  return db;
186
194
  }
package/src/env.ts CHANGED
@@ -1,15 +1,17 @@
1
1
  /// <reference types="@cloudflare/workers-types" />
2
2
  import { beforeEach, afterEach, mock } from "bun:test";
3
3
 
4
+ const MODULE_NAME = "cloudflare:workers";
5
+
4
6
  export function useEnv<TEnv extends Cloudflare.Env = Cloudflare.Env>(
5
7
  setup: () => Bun.MaybePromise<Partial<TEnv>>
6
8
  ) {
7
9
  beforeEach(async () => {
8
10
  const env = await setup();
9
- mock.module("cloudflare:env", () => env);
11
+ mock.module(MODULE_NAME, () => ({ env }));
10
12
  });
11
13
 
12
14
  afterEach(() => {
13
- mock.module("cloudflare:env", () => {});
15
+ mock.module(MODULE_NAME, () => ({ env: {} }));
14
16
  });
15
17
  }