Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions test/utils/d1-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function compareVersions(a: string, b: string): number {
const length = Math.max(aParts.length, bParts.length);

for (let i = 0; i < length; i++) {
const aNum = Number.isNaN(aParts[i]) ? 0 : aParts[i] ?? 0;
const bNum = Number.isNaN(bParts[i]) ? 0 : bParts[i] ?? 0;
const aNum = aParts[i] ?? 0;
const bNum = bParts[i] ?? 0;
Comment on lines 20 to +24

if (aNum < bNum) {
return -1;
Expand Down Expand Up @@ -50,6 +50,10 @@ function isVersionInRange(
);
}

function notImplementedInMock(methodName: string): Error {
return new Error(`MockD1Database.${methodName}() is not implemented for tests`);
}

export class MockD1Database implements D1Database {
private alerts: DatabaseAlert[] = [];

Expand Down Expand Up @@ -288,28 +292,28 @@ export class MockD1Database implements D1Database {
}

dump(): Promise<ArrayBuffer> {
throw new Error("dump() not implemented in mock");
throw notImplementedInMock("dump");
}

batch<T = unknown>(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_statements: D1PreparedStatement[]
): Promise<D1Result<T>[]> {
throw new Error("batch() not implemented in mock");
throw notImplementedInMock("batch");
}

exec(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_query: string
): Promise<D1ExecResult> {
throw new Error("exec() not implemented in mock");
throw notImplementedInMock("exec");
}

withSession(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_constraintOrBookmark?: string
): D1DatabaseSession {
throw new Error("withSession() not implemented in mock");
throw notImplementedInMock("withSession");
}
}

Expand Down
Loading