Skip to content

Latest commit

 

History

History

seeder-sftp

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Seeder.js / SFTP

NPM Version

The SFTP implementation for Seeder.js.

Getting Started

Install Seeder.js:

npm install -D @chehsunliu/seeder @chehsunliu/seeder-sftp

Use Docker Compose to serve an SFTP server:

services:
  sftp:
    image: atmoz/sftp:alpine
    restart: always
    ports:
      - "127.0.0.1:2222:22"
    command:
      - "foo:bar:1000:1000:upload"

Configure the seeders in setup.ts, which should be loaded in Jest setupFilesAfterEnv or in Vitest setupFiles:

import { seederManager } from "@chehsunliu/seeder";
import { SftpSeeder } from "@chehsunliu/seeder-sftp";

seederManager.configure([
  new SftpSeeder({
    connection: {
      host: "127.0.0.1",
      port: 2222,
      username: "foo",
      password: "bar",
    },
    localSrcDir: "sftp",
    sftpDestDir: "/upload",
  }),
]);

afterAll(async () => {
  await seederManager.release();
});

Put some test data in data:

mkdir -p data/sftp
echo "123" > data/sftp/a.txt
echo "abc" > data/sftp/b.txt

Invoke the seeders in tests:

import { seederManager } from "@chehsunliu/seeder";

beforeEach(async () => {
  await seederManager.truncate();
  await seederManager.seed(path.join(__dirname, "data"));
});

test("blah blah blah", () => {
  // Data should be available in:
  //   - /upload/a.txt
  //   - /upload/b.txt
});