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.
- package/package.json +1 -1
- package/src/d1.ts +9 -1
- package/src/env.ts +4 -2
package/package.json
CHANGED
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
|
-
|
|
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(
|
|
11
|
+
mock.module(MODULE_NAME, () => ({ env }));
|
|
10
12
|
});
|
|
11
13
|
|
|
12
14
|
afterEach(() => {
|
|
13
|
-
mock.module(
|
|
15
|
+
mock.module(MODULE_NAME, () => ({ env: {} }));
|
|
14
16
|
});
|
|
15
17
|
}
|