New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

file-mock

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

file-mock

A module which handle all your files creation and deletion for your tests

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
Source

File mock

file-mock is a tool that will handle file's creation and deletion automatically for your tests.

You have to specify, which file in which location you want and file mock will create all directories and files.

Mock

const fmock = require('file-mock')

fmock.mock({
  'server/uploads/test.png': 'File content',
  '/path/to/file.jpg': 'File content',
  '/path': {
    'to': {
      'myfile.png': 'File content'
    },
    'to1': {
      'myfile.png': 'File content'
    }
  }
})

Warning
If your path starts with a /, it will let it like this. In this example we have

  • /path/to/file.jpg
  • /path/to/myfile.jpg
  • /path/to1/myfile.jpg If it does not start with a /, the first part of the path will be the result of the process.cwd() function (usually the root of your repository).

Restore

To restore as before, you can use the restore function.

fmock.restore()

This function will delete all files and directories that have been created by the mock function.

This will never remove a directory that already exists

Keywords

fs

FAQs

Package last updated on 11 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts