Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
Contexts are now fs module compatible
  • Loading branch information
james-pre committed Nov 30, 2024
1 parent 3501420 commit bfc5726
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtractProperties<typeof fs, (...args: any[]) => any>, 'mountObject'>;
type Fn_FS = ExtractProperties<typeof fs, (...args: any[]) => any>;
type Fn_Promises = ExtractProperties<typeof fs.promises, (...args: any[]) => any>;

/**
Expand Down Expand Up @@ -34,7 +34,7 @@ export type V_Context = void | (Partial<FSContext> & object);
* @experimental
*/
export interface BoundContext extends FSContext {
fs: Fn_FS & { promises: Fn_Promises };
fs: typeof fs;
}

/**
Expand All @@ -51,5 +51,5 @@ export function bindContext(root: string, credentials: CredentialInit = structur
const fn_fs = _bindFunctions<Fn_FS>(fs, ctx);
const fn_promises = _bindFunctions<Fn_Promises>(fs.promises, ctx);

return { ...ctx, fs: { ...fn_fs, promises: fn_promises } };
return { ...ctx, fs: { ...fs, ...fn_fs, promises: { ...fs.promises, ...fn_promises } } };
}
2 changes: 1 addition & 1 deletion tests/common/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
3 changes: 1 addition & 2 deletions tests/setup.ts
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/setup/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit bfc5726

Please sign in to comment.