Skip to content

Commit

Permalink
fixed tests and removed type alias
Browse files Browse the repository at this point in the history
  • Loading branch information
geelen committed Aug 4, 2022
1 parent 7e1de66 commit ec019c3
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/d1/package.json
Expand Up @@ -36,7 +36,7 @@
"extends": "../../package.json"
},
"dependencies": {
"@miniflare/core": "^2.6.0",
"@miniflare/core": "2.6.0",
"@miniflare/shared": "2.6.0"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/d1/test/database.spec.ts
Expand Up @@ -11,9 +11,10 @@ interface Context {

const test = anyTest as TestInterface<Context>;

test.beforeEach((t) => {
test.beforeEach(async (t) => {
const storage = new MemoryStorage(undefined, testClock);
const db = new BetaDatabase(storage);
await db.init();
t.context = { storage, db };
});

Expand Down
5 changes: 0 additions & 5 deletions packages/shared/src/storage.ts
Expand Up @@ -167,11 +167,6 @@ export interface StorageFactory {
dispose?(): Awaitable<void>;
}

// @types/better-sqlite3 doesn't seem to export DatabaseConstructor, so we do this
export type BetterSqlite3Exports = {
new (filename: string, options?: Database.Options): Database.Database;
};

export function getSQLiteNativeBindingLocation(sqliteResolvePath: string) {
return path.resolve(
path.dirname(sqliteResolvePath),
Expand Down
7 changes: 3 additions & 4 deletions packages/storage-file/src/index.ts
@@ -1,7 +1,6 @@
import fs, { existsSync } from "fs";
import path from "path";
import {
BetterSqlite3Exports,
MiniflareError,
Range,
RangeStoredValueMeta,
Expand Down Expand Up @@ -109,9 +108,9 @@ export class FileStorage extends LocalStorage {
}

async getSqliteDatabase(): Promise<Database.Database> {
const DatabaseConstructor = await npxImport<BetterSqlite3Exports>(
"better-sqlite3@^7.5.3"
);
const DatabaseConstructor = await npxImport<
typeof import("better-sqlite3")
>("better-sqlite3@^7.5.3");
fs.mkdirSync(path.dirname(this.root), { recursive: true });
return new DatabaseConstructor(this.root + ".sqlite3", {
nativeBinding: getSQLiteNativeBindingLocation(
Expand Down
7 changes: 3 additions & 4 deletions packages/storage-memory/src/local.ts
@@ -1,6 +1,5 @@
import {
Awaitable,
BetterSqlite3Exports,
Range,
RangeStoredValueMeta,
Storage,
Expand Down Expand Up @@ -122,9 +121,9 @@ export abstract class LocalStorage extends Storage {
}

async getSqliteDatabase(): Promise<Database.Database> {
const DatabaseConstructor = await npxImport<BetterSqlite3Exports>(
"better-sqlite3@^7.5.3"
);
const DatabaseConstructor = await npxImport<
typeof import("better-sqlite3")
>("better-sqlite3@^7.5.3");
return new DatabaseConstructor(":memory:", {
nativeBinding: getSQLiteNativeBindingLocation(
npxResolve("better-sqlite3")
Expand Down

0 comments on commit ec019c3

Please sign in to comment.