Skip to content

Commit

Permalink
chore: remove of the mockSuperThis in favour of the public method
Browse files Browse the repository at this point in the history
       ensureSuperThis
  • Loading branch information
mabels committed Dec 10, 2024
1 parent ef4a31e commit 332528b
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 97 deletions.
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface SuperThisOpts {

export interface SuperThis {
readonly logger: Logger;
readonly loggerCollector?: Logger;
readonly env: Env;
readonly pathOps: PathOps;
readonly ctx: Record<string, unknown>;
Expand Down
5 changes: 2 additions & 3 deletions tests/blockstore/fragment-gateway.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Result, URI } from "@adviser/cement";
import { mockSuperThis } from "../helpers.js";
import { bs } from "@fireproof/core";
import { bs, ensureSuperThis } from "@fireproof/core";

class TraceGateway implements bs.Gateway {
readonly buildUrlFn = vitest.fn();
Expand Down Expand Up @@ -53,7 +52,7 @@ class TraceGateway implements bs.Gateway {
}

describe("FragmentGateway", () => {
const sthis = mockSuperThis();
const sthis = ensureSuperThis();
it("passthrough", async () => {
const innerGW = new TraceGateway();
const fgw = new bs.FragmentGateway(sthis, innerGW);
Expand Down
14 changes: 7 additions & 7 deletions tests/blockstore/keyed-crypto.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { bs, rt } from "@fireproof/core";
import { bs, ensureSuperThis, rt, SuperThis } from "@fireproof/core";
import { BuildURI, Logger, MockLogger, runtimeFn, toCryptoRuntime, URI } from "@adviser/cement";
import { base58btc } from "multiformats/bases/base58";
import { sha256 as hasher } from "multiformats/hashes/sha2";
import * as dagCodec from "@fireproof/vendor/@ipld/dag-cbor";
import { MockSuperThis, mockSuperThis } from "../helpers.js";

describe("KeyBag", () => {
let url: URI;
let sthis: MockSuperThis;
let sthis: SuperThis;
const mockLogger = MockLogger();

beforeEach(async () => {
sthis = mockSuperThis();
sthis = ensureSuperThis({ logger: mockLogger.logger });
await sthis.start();
if (runtimeFn().isBrowser) {
url = URI.from("indexdb://fp-keybag");
Expand Down Expand Up @@ -54,7 +54,7 @@ describe("KeyBag", () => {
});
sthis.env.set("FP_KEYBAG_URL", old);
await sthis.logger.Flush();
expect(sthis.logCollector.Logs()).toEqual([
expect(mockLogger.logCollector.Logs()).toEqual([
{
level: "warn",
module: "KeyBag",
Expand Down Expand Up @@ -124,7 +124,7 @@ describe("KeyedCryptoStore", () => {
let kb: rt.kb.KeyBag;
let logger: Logger;
let baseUrl: URI;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();
beforeEach(async () => {
await sthis.start();
logger = MockLogger().logger;
Expand Down Expand Up @@ -264,7 +264,7 @@ describe("KeyedCrypto", () => {
let kb: rt.kb.KeyBag;
let kycr: bs.KeyedCrypto;
let keyStr: string;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();
beforeEach(async () => {
let url: URI;
if (runtimeFn().isBrowser) {
Expand Down
9 changes: 4 additions & 5 deletions tests/blockstore/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { sha256 as hasher } from "multiformats/hashes/sha2";
import { BlockView } from "multiformats";
import { CID } from "multiformats/cid";
import { MemoryBlockstore } from "@fireproof/vendor/@web3-storage/pail/block";
import { CRDTMeta, IndexTransactionMeta, SuperThis, bs, rt } from "@fireproof/core";
import { mockSuperThis } from "../helpers.js";
import { CRDTMeta, IndexTransactionMeta, SuperThis, bs, ensureSuperThis, rt } from "@fireproof/core";

class MyMemoryBlockStore extends bs.EncryptedBlockstore {
readonly memblock = new MemoryBlockstore();
Expand Down Expand Up @@ -51,7 +50,7 @@ describe("basic Loader simple", function () {
let loader: bs.Loader;
let block: BlockView;
let t: bs.CarTransaction;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();

afterEach(async function () {
await loader.close();
Expand Down Expand Up @@ -99,7 +98,7 @@ describe("basic Loader with two commits", function () {
let carCid: bs.CarGroup;
let carCid0: bs.CarGroup;

const sthis = mockSuperThis();
const sthis = ensureSuperThis();

afterEach(async function () {
await loader.close();
Expand Down Expand Up @@ -201,7 +200,7 @@ describe("basic Loader with index commits", function () {
let indexerResult: IndexTransactionMeta;
let cid: CID;
// let indexMap: Map<string, CID>;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();

afterEach(async function () {
await ib.close();
Expand Down
11 changes: 5 additions & 6 deletions tests/blockstore/store.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { CID } from "multiformats";
import { bs, NotFoundError, SuperThis } from "@fireproof/core";
import { mockSuperThis } from "../helpers.js";
import { bs, ensureSuperThis, NotFoundError, SuperThis } from "@fireproof/core";

function runtime(sthis: SuperThis) {
return bs.toStoreRuntime({}, sthis);
Expand All @@ -20,7 +19,7 @@ describe("DataStore", function () {
let store: bs.DataStore;
let raw: bs.TestGateway;

const sthis = mockSuperThis();
const sthis = ensureSuperThis();
afterEach(async () => {
await store.close();
await store.destroy();
Expand Down Expand Up @@ -53,7 +52,7 @@ describe("DataStore with a saved car", function () {
let raw: bs.TestGateway;
let car: bs.AnyBlock;

const sthis = mockSuperThis();
const sthis = ensureSuperThis();

afterEach(async () => {
await store.close();
Expand Down Expand Up @@ -95,7 +94,7 @@ describe("MetaStore", function () {
let store: bs.MetaStore;
let raw: bs.TestGateway;

const sthis = mockSuperThis();
const sthis = ensureSuperThis();

afterEach(async () => {
await store.close();
Expand Down Expand Up @@ -133,7 +132,7 @@ describe("MetaStore with a saved header", function () {
let store: bs.MetaStore;
let raw: bs.TestGateway;
let cid: CID;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();

afterEach(async () => {
await store.close();
Expand Down
11 changes: 5 additions & 6 deletions tests/blockstore/transaction.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { CID } from "multiformats";
import { bs, SuperThis } from "@fireproof/core";
import { mockSuperThis } from "../helpers.js";
import { bs, ensureSuperThis, SuperThis } from "@fireproof/core";

describe("Fresh TransactionBlockstore", function () {
let blocks: bs.BaseBlockstore;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();
beforeEach(function () {
blocks = new bs.BaseBlockstore();
});
Expand Down Expand Up @@ -33,7 +32,7 @@ describe("Fresh TransactionBlockstore", function () {

describe("TransactionBlockstore with name", function () {
let blocks: bs.EncryptedBlockstore;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();
beforeEach(function () {
blocks = new bs.EncryptedBlockstore(sthis, { name: "test" });
});
Expand All @@ -57,7 +56,7 @@ describe("TransactionBlockstore with name", function () {
describe("A transaction", function () {
let tblocks: bs.CarTransaction;
let blocks: bs.EncryptedBlockstore;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();
beforeEach(async function () {
blocks = new bs.EncryptedBlockstore(sthis, { name: "test" });
tblocks = new bs.CarTransaction(blocks);
Expand All @@ -83,7 +82,7 @@ describe("TransactionBlockstore with a completed transaction", function () {
let blocks: bs.BaseBlockstore;
let cid: CID;
let cid2: CID;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();

beforeEach(async function () {
cid = CID.parse("bafybeia4luuns6dgymy5kau5rm7r4qzrrzg6cglpzpogussprpy42cmcn4");
Expand Down
9 changes: 4 additions & 5 deletions tests/fireproof/all-gateway.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Database, bs } from "@fireproof/core";
import { Database, bs, ensureSuperThis } from "@fireproof/core";
import { URI } from "@adviser/cement";

import { fileContent } from "./cars/bafkreidxwt2nhvbl4fnqfw3ctlt6zbrir4kqwmjo5im6rf4q5si27kgo2i.js";
import { mockSuperThis } from "../helpers.js";

function customExpect(value: unknown, matcher: (val: unknown) => void, message: string): void {
try {
Expand Down Expand Up @@ -37,7 +36,7 @@ describe("noop Gateway", function () {
let fileGateway: ExtendedGateway;
let walGateway: ExtendedGateway;

const sthis = mockSuperThis();
const sthis = ensureSuperThis();

afterEach(async function () {
await db.close();
Expand Down Expand Up @@ -302,7 +301,7 @@ describe("noop Gateway subscribe", function () {
let metaStore: ExtendedStore;

let metaGateway: ExtendedGateway;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();

afterEach(async function () {
await db.close();
Expand Down Expand Up @@ -352,7 +351,7 @@ describe("Gateway", function () {
let metaGateway: ExtendedGateway;
// let fileGateway: ExtendedGateway;
// let walGateway: ExtendedGateway;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();

afterEach(async function () {
await db.close();
Expand Down
5 changes: 2 additions & 3 deletions tests/fireproof/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { describe, it, expect, beforeAll } from "vitest";
import { dataDir, fireproof, rt } from "@fireproof/core";
import { dataDir, ensureSuperThis, fireproof, rt } from "@fireproof/core";
import { runtimeFn, URI } from "@adviser/cement";
import { mockSuperThis } from "../helpers.js";

describe("runtime", () => {
it("runtime", () => {
Expand All @@ -28,7 +27,7 @@ describe("fireproof/config", () => {
version: rt.FILESTORE_VERSION,
});
}
const sthis = mockSuperThis();
const sthis = ensureSuperThis();
beforeAll(async () => {
await sthis.start();
if (runtimeFn().isNodeIsh) {
Expand Down
21 changes: 10 additions & 11 deletions tests/fireproof/crdt.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { CRDT } from "@fireproof/core";
import { CRDT, ensureSuperThis } from "@fireproof/core";
import { bs } from "@fireproof/core";
import { CRDTMeta, DocValue } from "@fireproof/core";
import { Index, index } from "@fireproof/core";
import { mockSuperThis } from "../helpers.js";

describe("Fresh crdt", function () {
let crdt: CRDT<{ hello: string } | { points: number }>;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();
afterEach(async function () {
await crdt.close();
await crdt.destroy();
Expand Down Expand Up @@ -41,7 +40,7 @@ describe("CRDT with one record", function () {
}
let crdt: CRDT<Partial<CRDTTestType>>;
let firstPut: CRDTMeta;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();

afterEach(async function () {
await crdt.close();
Expand Down Expand Up @@ -92,7 +91,7 @@ describe("CRDT with a multi-write", function () {
}
let crdt: CRDT<CRDTTestType>;
let firstPut: CRDTMeta;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();

afterEach(async function () {
await crdt.close();
Expand Down Expand Up @@ -158,7 +157,7 @@ describe("CRDT with two multi-writes", function () {
let crdt: CRDT<CRDTTestType>;
let firstPut: CRDTMeta;
let secondPut: CRDTMeta;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();
afterEach(async function () {
await crdt.close();
await crdt.destroy();
Expand Down Expand Up @@ -206,7 +205,7 @@ describe("CRDT with two multi-writes", function () {

describe("Compact a named CRDT with writes", function () {
let crdt: CRDT<CRDTTestType>;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();
afterEach(async function () {
await crdt.close();
await crdt.destroy();
Expand Down Expand Up @@ -262,7 +261,7 @@ describe("Compact a named CRDT with writes", function () {
describe("CRDT with an index", function () {
let crdt: CRDT<CRDTTestType>;
let idx: Index<number, CRDTTestType>;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();
afterEach(async function () {
await crdt.close();
await crdt.destroy();
Expand Down Expand Up @@ -308,7 +307,7 @@ describe("Loader with a committed transaction", function () {
let crdt: CRDT<CRDTTestType>;
let done: CRDTMeta;
const dbname = "test-loader";
const sthis = mockSuperThis();
const sthis = ensureSuperThis();
afterEach(async function () {
await crdt.close();
await crdt.destroy();
Expand Down Expand Up @@ -351,7 +350,7 @@ describe("Loader with two committed transactions", function () {
let blockstore: bs.EncryptedBlockstore;
let done1: CRDTMeta;
let done2: CRDTMeta;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();
afterEach(async function () {
await crdt.close();
await crdt.destroy();
Expand Down Expand Up @@ -401,7 +400,7 @@ describe("Loader with many committed transactions", function () {
let crdt: CRDT<Doc>;
let dones: CRDTMeta[];
const count = 10;
const sthis = mockSuperThis();
const sthis = ensureSuperThis();
afterEach(async function () {
await crdt.close();
await crdt.destroy();
Expand Down
Loading

0 comments on commit 332528b

Please sign in to comment.