From ffb8d110bc02f2f9e941894001659f0e0dcc2784 Mon Sep 17 00:00:00 2001 From: David Konsumer Date: Mon, 4 Nov 2024 13:18:42 -0800 Subject: [PATCH] shows must create mounted dirs (related: #127) --- tests/common.ts | 4 ++-- tests/fs/readdir.test.ts | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/common.ts b/tests/common.ts index a67c1fdf..6b6bcbdc 100644 --- a/tests/common.ts +++ b/tests/common.ts @@ -1,5 +1,5 @@ import { join, resolve } from 'node:path'; -import { fs } from '../dist/index.js'; +import { fs, configure, InMemory } from '../dist/index.js'; const setupPath = resolve(process.env.SETUP || join(import.meta.dirname, 'setup/memory.ts')); @@ -8,4 +8,4 @@ await import(setupPath).catch(error => { throw error; }); -export { fs }; +export { fs, configure, InMemory }; diff --git a/tests/fs/readdir.test.ts b/tests/fs/readdir.test.ts index 72d00daa..f0cccdbb 100644 --- a/tests/fs/readdir.test.ts +++ b/tests/fs/readdir.test.ts @@ -1,6 +1,6 @@ import assert from 'node:assert'; import { suite, test } from 'node:test'; -import { fs } from '../common.js'; +import { fs, configure, InMemory } from '../common.js'; const testDir = 'test-dir'; const testFiles = ['file1.txt', 'file2.txt', 'file3.txt']; @@ -17,6 +17,20 @@ for (const dir of testDirectories) { } } +// must make any dirs that are mounted +fs.mkdirSync('/mnt/tester', { recursive: true }) +fs.mkdirSync('/deep/stuff/here', { recursive: true }) +fs.mkdirSync('/top') + +await configure({ + mounts: { + '/mnt/tester': InMemory, + '/deep/stuff/here': InMemory, + '/top': InMemory + } +}) +fs.writeFileSync('/deep/stuff/here/gotcha.txt', 'Hi!') + suite('readdir and readdirSync', () => { test('readdir returns files and directories', async () => { const dirents = await fs.promises.readdir(testDir, { withFileTypes: true }); @@ -84,4 +98,9 @@ suite('readdir and readdirSync', () => { fs.writeFileSync('/мой-файл.txt', 'HELLO!', 'utf-8'); assert(fs.readdirSync('/').includes('мой-файл.txt')); }); + + test('readdir from a new mount (recursive)', () => { + const entries = fs.readdirSync('/', {recursive: true}) + assert(entries.includes('deep/stuff/here/gotcha.txt')); + }); });