-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
266 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {IFsWithVolume, memfs} from '../..'; | ||
import {nodeToFsa} from '../../node-to-fsa'; | ||
import {FsaNodeFs} from '../FsaNodeFs'; | ||
|
||
const setup = () => { | ||
const mfs = memfs({ mountpoint: null }) as IFsWithVolume; | ||
const dir = nodeToFsa(mfs, '/mountpoint', {mode: 'readwrite'}); | ||
const fs = new FsaNodeFs(dir); | ||
return { fs, mfs, dir }; | ||
}; | ||
|
||
describe('.mkdir()', () => { | ||
test('can create a sub-folder', async () => { | ||
const { fs, mfs } = setup(); | ||
await new Promise<void>((resolve, reject) => fs.mkdir('/test', (err) => { | ||
if (err) return reject(err); | ||
return resolve(); | ||
})); | ||
expect(mfs.statSync('/mountpoint/test').isDirectory()).toBe(true); | ||
}); | ||
|
||
test('throws when creating sub-sub-folder', async () => { | ||
const { fs } = setup(); | ||
try { | ||
await new Promise<void>((resolve, reject) => fs.mkdir('/test/subtest', (err) => { | ||
if (err) return reject(err); | ||
return resolve(); | ||
})); | ||
throw new Error('Expected error'); | ||
} catch (error) { | ||
expect(error.code).toBe('ENOTDIR'); | ||
} | ||
}); | ||
|
||
test('can create sub-sub-folder with "recursive" flag', async () => { | ||
const { fs, mfs } = setup(); | ||
await new Promise<void>((resolve, reject) => fs.mkdir('/test/subtest', {recursive: true}, (err) => { | ||
if (err) return reject(err); | ||
return resolve(); | ||
})); | ||
expect(mfs.statSync('/mountpoint/test/subtest').isDirectory()).toBe(true); | ||
}); | ||
|
||
test('can create sub-sub-folder with "recursive" flag with Promises API', async () => { | ||
const { fs, mfs } = setup(); | ||
await fs.promises.mkdir('/test/subtest', {recursive: true}); | ||
expect(mfs.statSync('/mountpoint/test/subtest').isDirectory()).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Default modes for opening files. | ||
export const enum MODE { | ||
FILE = 0o666, | ||
DIR = 0o777, | ||
DEFAULT = MODE.FILE, | ||
} | ||
|
||
export const ERRSTR = { | ||
PATH_STR: 'path must be a string or Buffer', | ||
// FD: 'file descriptor must be a unsigned 32-bit integer', | ||
FD: 'fd must be a file descriptor', | ||
MODE_INT: 'mode must be an int', | ||
CB: 'callback must be a function', | ||
UID: 'uid must be an unsigned int', | ||
GID: 'gid must be an unsigned int', | ||
LEN: 'len must be an integer', | ||
ATIME: 'atime must be an integer', | ||
MTIME: 'mtime must be an integer', | ||
PREFIX: 'filename prefix is required', | ||
BUFFER: 'buffer must be an instance of Buffer or StaticBuffer', | ||
OFFSET: 'offset must be an integer', | ||
LENGTH: 'length must be an integer', | ||
POSITION: 'position must be an integer', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type * as opts from "./types/options"; | ||
import { MODE } from './constants'; | ||
|
||
const mkdirDefaults: opts.IMkdirOptions = { | ||
mode: MODE.DIR, | ||
recursive: false, | ||
}; | ||
|
||
export const getMkdirOptions = (options): opts.IMkdirOptions => { | ||
if (typeof options === 'number') return Object.assign({}, mkdirDefaults, { mode: options }); | ||
return Object.assign({}, mkdirDefaults, options); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.