MCPcopy
hub / github.com/harttle/liquidjs / mock

Function mock

test/stub/mockfs.ts:13–44  ·  view source on GitHub ↗
(options: { [path: string]: (string | FileDescriptor) })

Source from the content-addressed store, hash-verified

11const { readFile, exists, readFileSync, existsSync, contains, containsSync } = fs
12
13export function mock (options: { [path: string]: (string | FileDescriptor) }) {
14 forOwn(options, (val, key) => {
15 files[resolve(key)] = isString(val)
16 ? { mode: '33188', content: val }
17 : val as FileDescriptor
18 });
19 (fs as any).readFile = async function (path: string) {
20 return fs.readFileSync(path)
21 };
22 (fs as any).readFileSync = function (path: string) {
23 const file = files[path]
24 if (file === undefined) throw new Error('ENOENT')
25 if (file.mode === '0000') throw new Error('EACCES')
26 return file.content
27 };
28 (fs as any).exists = async function (path: string) {
29 return fs.existsSync(path)
30 };
31 (fs as any).existsSync = function (path: string) {
32 return !!files[path]
33 };
34 (fs as any).contains = async (root: string, file: string) => {
35 root = resolve(root)
36 if (!root.endsWith(sep)) root += sep
37 return file.startsWith(root)
38 };
39 (fs as any).containsSync = (root: string, file: string) => {
40 root = resolve(root)
41 if (!root.endsWith(sep)) root += sep
42 return file.startsWith(root)
43 }
44}
45
46export function restore () {
47 files = {};

Callers 8

error.spec.tsFile · 0.90
cache.spec.tsFile · 0.90
liquid.spec.tsFile · 0.90
dos.spec.tsFile · 0.90
render.spec.tsFile · 0.90
include.spec.tsFile · 0.90
layout.spec.tsFile · 0.90
for.spec.tsFile · 0.90

Calls 5

forOwnFunction · 0.90
isStringFunction · 0.90
resolveFunction · 0.85
readFileSyncMethod · 0.80
existsSyncMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…