diff --git a/packages/core/src/embeddings/utils.ts b/packages/core/src/embeddings/utils.ts index 1e3821b8714cd220cc8a1ffc1db63b790fca58c7..0c2ba7a28626fc2f8878aefda5c42fdb10ce753e 100644 --- a/packages/core/src/embeddings/utils.ts +++ b/packages/core/src/embeddings/utils.ts @@ -1,7 +1,8 @@ import _ from "lodash"; import { ImageType } from "../Node"; import { DEFAULT_SIMILARITY_TOP_K } from "../constants"; -import { DEFAULT_FS, VectorStoreQueryMode } from "../storage"; +import { defaultFS } from "../env"; +import { VectorStoreQueryMode } from "../storage"; import { SimilarityType } from "./types"; /** @@ -244,8 +245,7 @@ export async function imageToDataUrl(input: ImageType): Promise<string> { _.isString(input) ) { // string or file URL - const fs = DEFAULT_FS; - const dataBuffer = await fs.readFile( + const dataBuffer = await defaultFS.readFile( input instanceof URL ? input.pathname : input, ); input = new Blob([dataBuffer]); diff --git a/packages/core/src/env/index.edge-light.ts b/packages/core/src/env/index.edge-light.ts index c880100ab3bc484a4fc5d39d596d7586960ad81b..562710cbcd604e3b8888f5b29f9fea67074265ab 100644 --- a/packages/core/src/env/index.edge-light.ts +++ b/packages/core/src/env/index.edge-light.ts @@ -1,4 +1,5 @@ import { Sha256 } from "@aws-crypto/sha256-js"; +import { CompleteFileSystem, InMemoryFileSystem } from "../storage"; export interface SHA256 { update(data: string | Uint8Array): void; @@ -8,6 +9,8 @@ export interface SHA256 { export const EOL = "\n"; +export const defaultFS: CompleteFileSystem = new InMemoryFileSystem(); + export function ok(value: unknown, message?: string): asserts value { if (!value) { const error = Error(message); diff --git a/packages/core/src/env/index.ts b/packages/core/src/env/index.ts index 267e4d23935505758291f9e34c682291efd85a96..6d164da0fc9adb66dc70e22f27191ecf9da9c328 100644 --- a/packages/core/src/env/index.ts +++ b/packages/core/src/env/index.ts @@ -1,6 +1,8 @@ import { ok } from "node:assert"; import { createHash, randomUUID } from "node:crypto"; +import fs from "node:fs/promises"; import { EOL } from "node:os"; +import type { CompleteFileSystem } from "../storage"; import type { SHA256 } from "./index.edge-light"; export function createSHA256(): SHA256 { @@ -15,4 +17,6 @@ export function createSHA256(): SHA256 { }; } +export const defaultFS: CompleteFileSystem = fs; + export { EOL, ok, randomUUID }; diff --git a/packages/core/src/readers/CSVReader.ts b/packages/core/src/readers/CSVReader.ts index 9d389e3a0ed9db3985b840647c5c92ec6cf39dd4..e92eddaf3f6ca7132c51c71e3f26fb0c4d6ce7ff 100644 --- a/packages/core/src/readers/CSVReader.ts +++ b/packages/core/src/readers/CSVReader.ts @@ -1,6 +1,7 @@ import Papa, { ParseConfig } from "papaparse"; import { Document } from "../Node"; -import { DEFAULT_FS, GenericFileSystem } from "../storage/FileSystem"; +import { defaultFS } from "../env"; +import { GenericFileSystem } from "../storage/FileSystem"; import { BaseReader } from "./base"; /** @@ -40,7 +41,7 @@ export class PapaCSVReader implements BaseReader { */ async loadData( file: string, - fs: GenericFileSystem = DEFAULT_FS, + fs: GenericFileSystem = defaultFS, ): Promise<Document[]> { const fileContent: string = await fs.readFile(file, "utf-8"); const result = Papa.parse(fileContent, this.papaConfig); diff --git a/packages/core/src/readers/DocxReader.ts b/packages/core/src/readers/DocxReader.ts index 4b72bc6728d9c7ca4b8760fb5e3f135ef26a8d85..e394b712dcc6234671e30ac37541352c7a1ce138 100644 --- a/packages/core/src/readers/DocxReader.ts +++ b/packages/core/src/readers/DocxReader.ts @@ -1,14 +1,14 @@ import mammoth from "mammoth"; import { Document } from "../Node"; +import { defaultFS } from "../env"; import { GenericFileSystem } from "../storage/FileSystem"; -import { DEFAULT_FS } from "../storage/constants"; import { BaseReader } from "./base"; export class DocxReader implements BaseReader { /** DocxParser */ async loadData( file: string, - fs: GenericFileSystem = DEFAULT_FS, + fs: GenericFileSystem = defaultFS, ): Promise<Document[]> { const dataBuffer = (await fs.readFile(file)) as any; const { value } = await mammoth.extractRawText({ buffer: dataBuffer }); diff --git a/packages/core/src/readers/HTMLReader.ts b/packages/core/src/readers/HTMLReader.ts index f938cffa68cb7cfdad64fbfc9ed23c0391a775fe..f2fa2be340966f7e8acb337adc2f73eb2dd476d5 100644 --- a/packages/core/src/readers/HTMLReader.ts +++ b/packages/core/src/readers/HTMLReader.ts @@ -1,5 +1,5 @@ import { Document } from "../Node"; -import { DEFAULT_FS } from "../storage/constants"; +import { defaultFS } from "../env"; import { GenericFileSystem } from "../storage/FileSystem"; import { BaseReader } from "./base"; @@ -20,7 +20,7 @@ export class HTMLReader implements BaseReader { */ async loadData( file: string, - fs: GenericFileSystem = DEFAULT_FS, + fs: GenericFileSystem = defaultFS, ): Promise<Document[]> { const dataBuffer = await fs.readFile(file, "utf-8"); const htmlOptions = this.getOptions(); diff --git a/packages/core/src/readers/ImageReader.ts b/packages/core/src/readers/ImageReader.ts index fd1b3969558b7076a3ceaad960eb07f9fe86f42e..b4806cc1543e990883f0ff69b2d7a992412f10a1 100644 --- a/packages/core/src/readers/ImageReader.ts +++ b/packages/core/src/readers/ImageReader.ts @@ -1,5 +1,5 @@ import { Document, ImageDocument } from "../Node"; -import { DEFAULT_FS } from "../storage/constants"; +import { defaultFS } from "../env"; import { GenericFileSystem } from "../storage/FileSystem"; import { BaseReader } from "./base"; @@ -16,7 +16,7 @@ export class ImageReader implements BaseReader { */ async loadData( file: string, - fs: GenericFileSystem = DEFAULT_FS, + fs: GenericFileSystem = defaultFS, ): Promise<Document[]> { const dataBuffer = await fs.readFile(file); const blob = new Blob([dataBuffer]); diff --git a/packages/core/src/readers/MarkdownReader.ts b/packages/core/src/readers/MarkdownReader.ts index 63adfd7cda6c68776c5983c80aa945a93a331f1c..fef040d425aead08a0a54b18dc4e27f89ca7aeb3 100644 --- a/packages/core/src/readers/MarkdownReader.ts +++ b/packages/core/src/readers/MarkdownReader.ts @@ -1,5 +1,6 @@ import { Document } from "../Node"; -import { DEFAULT_FS, GenericFileSystem } from "../storage"; +import { defaultFS } from "../env"; +import { GenericFileSystem } from "../storage"; import { BaseReader } from "./base"; type MarkdownTuple = [string | null, string]; @@ -89,7 +90,7 @@ export class MarkdownReader implements BaseReader { async loadData( file: string, - fs: GenericFileSystem = DEFAULT_FS, + fs: GenericFileSystem = defaultFS, ): Promise<Document[]> { const content = await fs.readFile(file, { encoding: "utf-8" }); const tups = this.parseTups(content); diff --git a/packages/core/src/readers/PDFReader.ts b/packages/core/src/readers/PDFReader.ts index 829374fcae412acc1fb9a1a0fe6e6cfe34f00d01..574ac2c9bc698419c1f7b71d6a45f0501ae77f5b 100644 --- a/packages/core/src/readers/PDFReader.ts +++ b/packages/core/src/readers/PDFReader.ts @@ -1,6 +1,6 @@ import { Document } from "../Node"; +import { defaultFS } from "../env"; import { GenericFileSystem } from "../storage/FileSystem"; -import { DEFAULT_FS } from "../storage/constants"; import { BaseReader } from "./base"; /** @@ -9,7 +9,7 @@ import { BaseReader } from "./base"; export class PDFReader implements BaseReader { async loadData( file: string, - fs: GenericFileSystem = DEFAULT_FS, + fs: GenericFileSystem = defaultFS, ): Promise<Document[]> { const content = (await fs.readFile(file)) as any; if (!(content instanceof Buffer)) { diff --git a/packages/core/src/readers/SimpleDirectoryReader.ts b/packages/core/src/readers/SimpleDirectoryReader.ts index 5146256ae0251266429b34e58032a8068a8bcaed..a6177381beb75bc25a78cadd35a1efa7fbdac3fc 100644 --- a/packages/core/src/readers/SimpleDirectoryReader.ts +++ b/packages/core/src/readers/SimpleDirectoryReader.ts @@ -1,7 +1,7 @@ import _ from "lodash"; import { Document } from "../Node"; +import { defaultFS } from "../env"; import { CompleteFileSystem, walk } from "../storage/FileSystem"; -import { DEFAULT_FS } from "../storage/constants"; import { PapaCSVReader } from "./CSVReader"; import { DocxReader } from "./DocxReader"; import { HTMLReader } from "./HTMLReader"; @@ -28,7 +28,7 @@ enum ReaderStatus { export class TextFileReader implements BaseReader { async loadData( file: string, - fs: CompleteFileSystem = DEFAULT_FS as CompleteFileSystem, + fs: CompleteFileSystem = defaultFS, ): Promise<Document[]> { const dataBuffer = await fs.readFile(file, "utf-8"); return [new Document({ text: dataBuffer, id_: file })]; @@ -66,7 +66,7 @@ export class SimpleDirectoryReader implements BaseReader { async loadData({ directoryPath, - fs = DEFAULT_FS as CompleteFileSystem, + fs = defaultFS, defaultReader = new TextFileReader(), fileExtToReader = FILE_EXT_TO_READER, }: SimpleDirectoryReaderLoadDataProps): Promise<Document[]> { diff --git a/packages/core/src/storage/FileSystem.ts b/packages/core/src/storage/FileSystem.ts index bb4adfc7fe94eab15c159eabcda912c2a011133a..e323352837a835f11757109bd80b22181cf5be06 100644 --- a/packages/core/src/storage/FileSystem.ts +++ b/packages/core/src/storage/FileSystem.ts @@ -1,34 +1,51 @@ import _ from "lodash"; +import type nodeFS from "node:fs/promises"; + /** * A filesystem interface that is meant to be compatible with * the 'fs' module from Node.js. * Allows for the use of similar inteface implementation on * browsers. */ - -export interface GenericFileSystem { - writeFile(path: string, content: string, options?: any): Promise<void>; - readFile(path: string, options?: any): Promise<string>; +export type GenericFileSystem = { + writeFile( + path: string, + content: string, + options?: Parameters<typeof nodeFS.writeFile>[2], + ): Promise<void>; + readFile( + path: string, + options?: Parameters<typeof nodeFS.readFile>[1], + ): Promise<string>; access(path: string): Promise<void>; - mkdir(path: string, options?: any): Promise<void>; -} + mkdir( + path: string, + options?: Parameters<typeof nodeFS.mkdir>[1], + ): Promise<void>; +}; -export interface WalkableFileSystem { +export type WalkableFileSystem = { readdir(path: string): Promise<string[]>; stat(path: string): Promise<any>; -} +}; + +export type CompleteFileSystem = GenericFileSystem & WalkableFileSystem; /** * A filesystem implementation that stores files in memory. */ -export class InMemoryFileSystem implements GenericFileSystem { +export class InMemoryFileSystem implements CompleteFileSystem { private files: Record<string, any> = {}; - async writeFile(path: string, content: string, options?: any): Promise<void> { + async writeFile( + path: string, + content: string, + options?: unknown, + ): Promise<void> { this.files[path] = _.cloneDeep(content); } - async readFile(path: string, options?: any): Promise<string> { + async readFile(path: string, options?: unknown): Promise<string> { if (!(path in this.files)) { throw new Error(`File ${path} does not exist`); } @@ -41,26 +58,18 @@ export class InMemoryFileSystem implements GenericFileSystem { } } - async mkdir(path: string, options?: any): Promise<void> { + async mkdir(path: string, options?: unknown): Promise<void> { this.files[path] = _.get(this.files, path, null); } -} -export type CompleteFileSystem = GenericFileSystem & WalkableFileSystem; - -export function getNodeFS(): CompleteFileSystem { - const fs = require("fs/promises"); - return fs; -} + async readdir(path: string): Promise<string[]> { + throw new Error("Not implemented"); + } -let fs = null; -try { - fs = getNodeFS(); -} catch (e) { - fs = new InMemoryFileSystem(); + async stat(path: string): Promise<any> { + throw new Error("Not implemented"); + } } -export const DEFAULT_FS: GenericFileSystem | CompleteFileSystem = - fs as GenericFileSystem; // FS utility functions @@ -92,12 +101,6 @@ export async function* walk( fs: WalkableFileSystem, dirPath: string, ): AsyncIterable<string> { - if (fs instanceof InMemoryFileSystem) { - throw new Error( - "The InMemoryFileSystem does not support directory traversal.", - ); - } - const entries = await fs.readdir(dirPath); for (const entry of entries) { const fullPath = `${dirPath}/${entry}`; diff --git a/packages/core/src/storage/StorageContext.ts b/packages/core/src/storage/StorageContext.ts index 5257cb0339d1e70fc793cbda656b1b608c198e64..06658ca20488e824572491f5b2d56a2de10aa6bb 100644 --- a/packages/core/src/storage/StorageContext.ts +++ b/packages/core/src/storage/StorageContext.ts @@ -1,10 +1,7 @@ import path from "path"; +import { defaultFS } from "../env"; import { GenericFileSystem } from "./FileSystem"; -import { - DEFAULT_FS, - DEFAULT_IMAGE_VECTOR_NAMESPACE, - DEFAULT_NAMESPACE, -} from "./constants"; +import { DEFAULT_IMAGE_VECTOR_NAMESPACE, DEFAULT_NAMESPACE } from "./constants"; import { SimpleDocumentStore } from "./docStore/SimpleDocumentStore"; import { BaseDocumentStore } from "./docStore/types"; import { SimpleIndexStore } from "./indexStore/SimpleIndexStore"; @@ -19,14 +16,14 @@ export interface StorageContext { imageVectorStore?: VectorStore; } -type BuilderParams = { - docStore?: BaseDocumentStore; - indexStore?: BaseIndexStore; - vectorStore?: VectorStore; - imageVectorStore?: VectorStore; - storeImages?: boolean; - persistDir?: string; - fs?: GenericFileSystem; +export type BuilderParams = { + docStore: BaseDocumentStore; + indexStore: BaseIndexStore; + vectorStore: VectorStore; + imageVectorStore: VectorStore; + storeImages: boolean; + persistDir: string; + fs: GenericFileSystem; }; export async function storageContextFromDefaults({ @@ -37,14 +34,14 @@ export async function storageContextFromDefaults({ storeImages, persistDir, fs, -}: BuilderParams): Promise<StorageContext> { +}: Partial<BuilderParams>): Promise<StorageContext> { if (!persistDir) { docStore = docStore || new SimpleDocumentStore(); indexStore = indexStore || new SimpleIndexStore(); vectorStore = vectorStore || new SimpleVectorStore(); imageVectorStore = storeImages ? new SimpleVectorStore() : imageVectorStore; } else { - fs = fs || DEFAULT_FS; + fs = fs || defaultFS; docStore = docStore || (await SimpleDocumentStore.fromPersistDir( diff --git a/packages/core/src/storage/constants.ts b/packages/core/src/storage/constants.ts index c4d965d2bf4843f0ecf2ee9e30df05dc226964a4..8d58a29a7af9a81f3f3dfa6610eb6c53bb7204fa 100644 --- a/packages/core/src/storage/constants.ts +++ b/packages/core/src/storage/constants.ts @@ -6,4 +6,3 @@ export const DEFAULT_VECTOR_STORE_PERSIST_FILENAME = "vector_store.json"; export const DEFAULT_GRAPH_STORE_PERSIST_FILENAME = "graph_store.json"; export const DEFAULT_NAMESPACE = "docstore"; export const DEFAULT_IMAGE_VECTOR_NAMESPACE = "images"; -export { DEFAULT_FS } from "./FileSystem"; diff --git a/packages/core/src/storage/docStore/SimpleDocumentStore.ts b/packages/core/src/storage/docStore/SimpleDocumentStore.ts index 784c763ac2ebc91318a7524d1604ea6f4d13152a..453d76a7c7e4ce28e4231667bc5b89acdcec2464 100644 --- a/packages/core/src/storage/docStore/SimpleDocumentStore.ts +++ b/packages/core/src/storage/docStore/SimpleDocumentStore.ts @@ -1,9 +1,9 @@ import _ from "lodash"; import path from "path"; +import { defaultFS } from "../../env"; import { GenericFileSystem } from "../FileSystem"; import { DEFAULT_DOC_STORE_PERSIST_FILENAME, - DEFAULT_FS, DEFAULT_NAMESPACE, DEFAULT_PERSIST_DIR, } from "../constants"; @@ -44,7 +44,7 @@ export class SimpleDocumentStore extends KVDocumentStore { namespace?: string, fs?: GenericFileSystem, ): Promise<SimpleDocumentStore> { - fs = fs || DEFAULT_FS; + fs = fs || defaultFS; const simpleKVStore = await SimpleKVStore.fromPersistPath(persistPath, fs); return new SimpleDocumentStore(simpleKVStore, namespace); } @@ -56,7 +56,7 @@ export class SimpleDocumentStore extends KVDocumentStore { ), fs?: GenericFileSystem, ): Promise<void> { - fs = fs || DEFAULT_FS; + fs = fs || defaultFS; if ( _.isObject(this.kvStore) && this.kvStore instanceof BaseInMemoryKVStore diff --git a/packages/core/src/storage/indexStore/SimpleIndexStore.ts b/packages/core/src/storage/indexStore/SimpleIndexStore.ts index 602a87119bab3c257f5289bc95ca15ffff6c0168..4ab7c0530548f325096ae4831df356e3c8679eb2 100644 --- a/packages/core/src/storage/indexStore/SimpleIndexStore.ts +++ b/packages/core/src/storage/indexStore/SimpleIndexStore.ts @@ -1,7 +1,7 @@ import path from "path"; +import { defaultFS } from "../../env"; import { GenericFileSystem } from "../FileSystem"; import { - DEFAULT_FS, DEFAULT_INDEX_STORE_PERSIST_FILENAME, DEFAULT_PERSIST_DIR, } from "../constants"; @@ -20,7 +20,7 @@ export class SimpleIndexStore extends KVIndexStore { static async fromPersistDir( persistDir: string = DEFAULT_PERSIST_DIR, - fs: GenericFileSystem = DEFAULT_FS, + fs: GenericFileSystem = defaultFS, ): Promise<SimpleIndexStore> { const persistPath = path.join( persistDir, @@ -31,7 +31,7 @@ export class SimpleIndexStore extends KVIndexStore { static async fromPersistPath( persistPath: string, - fs: GenericFileSystem = DEFAULT_FS, + fs: GenericFileSystem = defaultFS, ): Promise<SimpleIndexStore> { let simpleKVStore = await SimpleKVStore.fromPersistPath(persistPath, fs); return new SimpleIndexStore(simpleKVStore); @@ -39,7 +39,7 @@ export class SimpleIndexStore extends KVIndexStore { async persist( persistPath: string = DEFAULT_PERSIST_DIR, - fs: GenericFileSystem = DEFAULT_FS, + fs: GenericFileSystem = defaultFS, ): Promise<void> { await this.kvStore.persist(persistPath, fs); } diff --git a/packages/core/src/storage/kvStore/SimpleKVStore.ts b/packages/core/src/storage/kvStore/SimpleKVStore.ts index 3192f9e423bc40b3220803eddcffeb2d17641c37..6581d3711d7715875280fc58dabf8157590ecaa0 100644 --- a/packages/core/src/storage/kvStore/SimpleKVStore.ts +++ b/packages/core/src/storage/kvStore/SimpleKVStore.ts @@ -1,19 +1,18 @@ import _ from "lodash"; import path from "path"; +import { defaultFS } from "../../env"; import { GenericFileSystem, exists } from "../FileSystem"; -import { DEFAULT_COLLECTION, DEFAULT_FS } from "../constants"; +import { DEFAULT_COLLECTION } from "../constants"; import { BaseKVStore } from "./types"; export type DataType = Record<string, Record<string, any>>; export class SimpleKVStore extends BaseKVStore { - private data: DataType; private persistPath: string | undefined; private fs: GenericFileSystem | undefined; - constructor(data?: DataType) { + constructor(private data: DataType = {}) { super(); - this.data = data || {}; } async put( @@ -61,7 +60,7 @@ export class SimpleKVStore extends BaseKVStore { } async persist(persistPath: string, fs?: GenericFileSystem): Promise<void> { - fs = fs || DEFAULT_FS; + fs = fs || defaultFS; // TODO: decide on a way to polyfill path let dirPath = path.dirname(persistPath); if (!(await exists(fs, dirPath))) { @@ -74,7 +73,7 @@ export class SimpleKVStore extends BaseKVStore { persistPath: string, fs?: GenericFileSystem, ): Promise<SimpleKVStore> { - fs = fs || DEFAULT_FS; + fs = fs || defaultFS; let dirPath = path.dirname(persistPath); if (!(await exists(fs, dirPath))) { await fs.mkdir(dirPath); diff --git a/packages/core/src/storage/vectorStore/SimpleVectorStore.ts b/packages/core/src/storage/vectorStore/SimpleVectorStore.ts index c2ccd7bd865f032e8319f294ebd84d86cb2f9552..5a6679d8993c0eb81b08134161108f47000966a7 100644 --- a/packages/core/src/storage/vectorStore/SimpleVectorStore.ts +++ b/packages/core/src/storage/vectorStore/SimpleVectorStore.ts @@ -6,8 +6,9 @@ import { getTopKEmbeddingsLearner, getTopKMMREmbeddings, } from "../../embeddings"; +import { defaultFS } from "../../env"; import { GenericFileSystem, exists } from "../FileSystem"; -import { DEFAULT_FS, DEFAULT_PERSIST_DIR } from "../constants"; +import { DEFAULT_PERSIST_DIR } from "../constants"; import { VectorStore, VectorStoreQuery, @@ -31,17 +32,17 @@ class SimpleVectorStoreData { export class SimpleVectorStore implements VectorStore { storesText: boolean = false; private data: SimpleVectorStoreData = new SimpleVectorStoreData(); - private fs: GenericFileSystem = DEFAULT_FS; + private fs: GenericFileSystem = defaultFS; private persistPath: string | undefined; constructor(data?: SimpleVectorStoreData, fs?: GenericFileSystem) { this.data = data || new SimpleVectorStoreData(); - this.fs = fs || DEFAULT_FS; + this.fs = fs || defaultFS; } static async fromPersistDir( persistDir: string = DEFAULT_PERSIST_DIR, - fs: GenericFileSystem = DEFAULT_FS, + fs: GenericFileSystem = defaultFS, ): Promise<SimpleVectorStore> { let persistPath = `${persistDir}/vector_store.json`; return await SimpleVectorStore.fromPersistPath(persistPath, fs); @@ -160,7 +161,7 @@ export class SimpleVectorStore implements VectorStore { persistPath: string, fs?: GenericFileSystem, ): Promise<SimpleVectorStore> { - fs = fs || DEFAULT_FS; + fs = fs || defaultFS; let dirPath = path.dirname(persistPath); if (!(await exists(fs, dirPath))) { diff --git a/packages/core/src/tests/GenericFileSystem.test.ts b/packages/core/src/tests/GenericFileSystem.test.ts index b30702de4c2954674626c2ec7e8437f8059e7667..7b7b576e8a6e399f088013060e734b61437be20a 100644 --- a/packages/core/src/tests/GenericFileSystem.test.ts +++ b/packages/core/src/tests/GenericFileSystem.test.ts @@ -1,10 +1,10 @@ +import nodeFS from "node:fs/promises"; import os from "os"; import path from "path"; import { GenericFileSystem, InMemoryFileSystem, exists, - getNodeFS, walk, } from "../storage/FileSystem"; @@ -16,8 +16,6 @@ type FileSystemUnderTest = { tempDir: string; }; -const nodeFS = getNodeFS() as GenericFileSystem & any; - describe.each<FileSystemUnderTest>([ { name: "InMemoryFileSystem", @@ -102,14 +100,13 @@ describe.each<FileSystemUnderTest>([ }); describe("Test walk for Node.js fs", () => { - const fs = getNodeFS(); let tempDir: string; beforeAll(async () => { tempDir = await nodeFS.mkdtemp(path.join(os.tmpdir(), "jest-")); - await fs.writeFile(`${tempDir}/test.txt`, "Hello, world!"); - await fs.mkdir(`${tempDir}/subDir`); - await fs.writeFile(`${tempDir}/subDir/test2.txt`, "Hello, again!"); + await nodeFS.writeFile(`${tempDir}/test.txt`, "Hello, world!"); + await nodeFS.mkdir(`${tempDir}/subDir`); + await nodeFS.writeFile(`${tempDir}/subDir/test2.txt`, "Hello, again!"); }); it("walks directory", async () => { @@ -119,7 +116,7 @@ describe("Test walk for Node.js fs", () => { ]); const actualFiles = new Set<string>(); - for await (let file of walk(fs, tempDir)) { + for await (let file of walk(nodeFS, tempDir)) { expect(file).toBeTruthy(); actualFiles.add(file); }