Skip to content

Commit

Permalink
shows must create mounted dirs (related: #127)
Browse files Browse the repository at this point in the history
  • Loading branch information
konsumer committed Nov 4, 2024
1 parent 611b15a commit ffb8d11
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 2 additions & 2 deletions tests/common.ts
Original file line number Diff line number Diff line change
@@ -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 };
21 changes: 20 additions & 1 deletion tests/fs/readdir.test.ts
Original file line number Diff line number Diff line change
@@ -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'));
});
});

0 comments on commit ffb8d11

Please sign in to comment.