From bfc5726d0c62eda98edeb903f6e18549879f0fb6 Mon Sep 17 00:00:00 2001 From: James Prevett Date: Sat, 30 Nov 2024 17:42:21 -0600 Subject: [PATCH] Update tests Contexts are now fs module compatible --- src/context.ts | 6 +++--- tests/common/context.test.ts | 2 +- tests/setup.ts | 3 +-- tests/setup/context.ts | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/context.ts b/src/context.ts index ab00f5ee..089cc7fa 100644 --- a/src/context.ts +++ b/src/context.ts @@ -3,7 +3,7 @@ import { type ExtractProperties } from 'utilium'; import { createCredentials, credentials as defaultCredentials, type CredentialInit, type Credentials } from './credentials.js'; import * as fs from './emulation/index.js'; -type Fn_FS = Omit any>, 'mountObject'>; +type Fn_FS = ExtractProperties any>; type Fn_Promises = ExtractProperties any>; /** @@ -34,7 +34,7 @@ export type V_Context = void | (Partial & object); * @experimental */ export interface BoundContext extends FSContext { - fs: Fn_FS & { promises: Fn_Promises }; + fs: typeof fs; } /** @@ -51,5 +51,5 @@ export function bindContext(root: string, credentials: CredentialInit = structur const fn_fs = _bindFunctions(fs, ctx); const fn_promises = _bindFunctions(fs.promises, ctx); - return { ...ctx, fs: { ...fn_fs, promises: fn_promises } }; + return { ...ctx, fs: { ...fs, ...fn_fs, promises: { ...fs.promises, ...fn_promises } } }; } diff --git a/tests/common/context.test.ts b/tests/common/context.test.ts index 2a38f56f..5f782fff 100644 --- a/tests/common/context.test.ts +++ b/tests/common/context.test.ts @@ -4,7 +4,7 @@ import { bindContext } from '../../dist/context.js'; import * as fs from '../../dist/emulation/index.js'; fs.mkdirSync('/new_root'); -const c_fs = bindContext('/new_root'); +const { fs: c_fs } = bindContext('/new_root'); suite('Context', () => { test('create a file', () => { diff --git a/tests/setup.ts b/tests/setup.ts index c1d328b4..b423a648 100644 --- a/tests/setup.ts +++ b/tests/setup.ts @@ -1,7 +1,6 @@ import { join, relative } from 'node:path'; import { statSync, readFileSync, readdirSync, existsSync, mkdirSync } from 'node:fs'; import { fs as _fs } from '../dist/index.js'; -import type { BoundContext } from '../dist/context.js'; export const data = join(import.meta.dirname, 'data'); @@ -11,7 +10,7 @@ if (!existsSync(tmp)) { mkdirSync(tmp); } -export function copy(_path: string, fs: typeof _fs | BoundContext = _fs) { +export function copy(_path: string, fs: typeof _fs = _fs) { const path = relative(data, _path) || '/'; const stats = statSync(_path); diff --git a/tests/setup/context.ts b/tests/setup/context.ts index 72e6e53a..af69eba6 100644 --- a/tests/setup/context.ts +++ b/tests/setup/context.ts @@ -4,6 +4,6 @@ import { copy, data } from '../setup.js'; _fs.mkdirSync('/new_root'); -export const fs = bindContext('/new_root'); +export const { fs } = bindContext('/new_root'); copy(data, fs);