Simple mock ftp server to add in your unit tests
npm install @aitrs/simple-mock-ftp-server ``typescript
import { createMockFilesystem } from 'simple-mock-ftp-server';
const fs = createMockFilesystem({
folder1: {
fooFile: {
___contents: Buffer.from('bar'),
___mode: 755,
},
childFolder: {
barFile: {
___contents: Buffer.from('baz'),
},
},
},
bazFile: {
___mode: 755,
___target: '/path/to/a/real/file',
},
});
`
Files are the subobjects of the definition that got the '___contents' or '___target' attributes.
Please notice the 3 underscores preceding their names, they are there to prevent collision with the most possible directory names one can want to provide.
Any other subobject is considered a folder.
#### ___contents
Must be a Buffer representing the binary contents of the mocked file in the mocked filesystem.
#### ___target
Specifies a path on the real filesystem to get contents of an existing file as part of what's in the mocked filesystem.
#### ___mode
Specifies the mode of the current file or folder. If not specified, defaults to 777 (all access).
typescript
import { createMockFtpServer, createMockFilesystem } from 'simple-mock-ftp-server';const { server, abortController } = createMockFtpServer({
host: '127.0.0.1',
port: '12345',
user: 'yourUserName',
password: 'yourPassword',
mockFilesystem: createMockFilesystem({
folder1: {
foo: {
___contents: Buffer.from('bar'),
},
},
bar: {
___target: './path/to/a/file',
___mode: 755,
},
}),
});
``