Easily create test fixtures at a temporary file-system path

Overview

fs-fixture

Easily create test fixtures at a temporary file-system path.

Support this project by ⭐️ starring and sharing it. Follow me to see what other cool projects I'm working on! ❤️

Usage

JSON input

Pass in an object representing the test fixture.

import { createFixture } from 'fs-fixture'

test('my test using json fixture', async () => {
    // Pass in a JSON representing the test fixture
    const fixture = await createFixture({
        // Nested directory syntax
        directoryA: {
            directoryB: {
                fileNameA: 'fileContent'
            }
        },

        // Directory path syntax - Same as above
        'directoryA/directoryB/fileNameB': 'fileContent'
    })

    /*
    Your test code here...

    // Log fixture path
    console.log(fixture.path)

    // Check if relative path exists
    console.log(await fixture.exists('./file'))
    */

    // Cleanup fixture
    await fixture.rm()
})

Template path input

Pass in a path to a test fixture template directory to make a copy of it.

test('my test using template path', async () => {
    // Pass in a path to a fixture template path, and it will make a copy of it
    const fixture = await createFixture('./fixtures/template-a')

    /* Your test code here... */

    // Cleanup fixture
    await fixture.rm()
})

API

createFixture(source)

An async function that creates a fixture from the source you pass in, and returns a FsFixture instance.

source

Type: string | FileTree

Path to a template fixture path, or a FileTree object that represents the fixture content.

Types

FileTree

type FileTree = {
    [path: string]: string | FileTree
}

FsFixture

class FsFixture {
    /**
    Path to the fixture directory.
    */
    path: string

    /**
    Create a Fixture instance from a path. Does not create the fixture directory.
    */
    constructor(fixturePath: string)

    /**
    Check if the fixture exists. Pass in a subpath to check if it exists.
    */
    exists(subpath?: string): Promise<boolean>

    /**
    Delete the fixture directory. Pass in a subpath to delete it.
    */
    rm(subpath?: string): Promise<void>

    /**
    Create a file in the fixture directory.
    */
    writeFile(filePath: string, content: string): Promise<void>

    /**
    Create a JSON file in the fixture directory.
    */
    writeJson(filePath: string, json: any): Promise<void>

    /**
    Read a file from the fixture directory.
    */
    readFile(filePath: string, encoding?: BufferEncoding): Promise<string | Buffer>
}
You might also like...

This package enables you to mount your Remix app at a different path than root

This package enables you to mount your Remix app at a different path than root

Remix Mount Routes This package enables you to mount your Remix app at a different path than root. 🛠 Installation npm install -D remix-mount-routes

Dec 17, 2022

Detect the executable python interpreter cmd in $PATH.

detect-python-interpreter Detect the executable python interpreter cmd in $PATH. Installation $ npm install --save detect-python-interpreter Usage con

Apr 12, 2022

Path-finding & Sorting algorithms Visualizer

Update - Changelog 📋 09.05.2022 AlgoVision is now fully mobile-responsive for all its features ! On mobile, the 'Mouse Chase' option in Dynamic Mode

Dec 18, 2022

Userland module that implements the module path mapping that Node.js does with "exports" in package.json

exports-map Userland module that implements the module path mapping that Node.js does with "exports" in package.json npm install exports-map Usage co

May 31, 2022

Sort imports by path - VS Code extension

Import sort by absolute path The sorting algorithm will group each item in the array and sort (alphabetically) its children that starts with the path

Feb 2, 2022

A Multi-Agent Path Finding visualization website.

A Multi-Agent Path Finding visualization website.

MAPF Visualizer A visualization tool for multi-agent path finding algorithms. About The Project This project provides a visualization tool for Multi-A

Dec 29, 2022

A third-party messenger application for Path of Exile.

A third-party messenger application for Path of Exile.

PoE Instant Messenger Download (Windows) The latest release can be downloaded here Tool showcase Theme Setup Notifier Messenger Settings Light Dark Co

Jul 29, 2022

Ready to manipulate partitions file? Create a custom partition, apply custom security system, hide the partition and share your hidden data on the www

Ready to manipulate partitions file? Create a custom partition, apply custom security system, hide the partition and share your hidden data on the www

Paranoia 💊 Ready to manipulate partitions file? Create a custom partition, apply custom security system, hide the partition and share your hidden dat

Dec 29, 2022

This tool allows you to test your chains.json file to see if your chains are available, syncing, or in sync.

Chains Tester This tool allows you to test your chains.json file to see if your chains are available, syncing, or in sync. This is an open source tool

Nov 4, 2022
Releases(v1.2.0)
Owner
hiroki osame
I'm on a mission to open source my solutions 🚀
hiroki osame
A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM deffiniation and appropriate file structure.

Welcome to function-stencil ?? A quickstart AWS Lambda function code generator. Downloads a template function code file, test harness file, sample SAM

Ben Smith 21 Jun 20, 2022
Serve file server with single zip file as file system in Deno.

zipland Serve file server with one-single zip file in Deno. Support zip just zip32 with deflated or uncompressed serving plaintext deflate Examples Yo

Yongwook Choi 18 Nov 2, 2022
The Frontend of Escobar's Inventory Management System, Employee Management System, Ordering System, and Income & Expense System

Usage Create an App # with npx $ npx create-nextron-app my-app --example with-javascript # with yarn $ yarn create nextron-app my-app --example with-

Viver Bungag 4 Jan 2, 2023
A completely decentralized way of sharing temporary messages.

Debin A completely decentralized way of sharing temporary and permanent messages. Debin uses Waku and IPFS decentralized networks to temporarily or pe

Paolo D'Amico 5 Jun 29, 2022
Web client with support for secret chats. Made as a temporary solution

Arcanugram – Unofficial Telegram Web App with support for secret chats ⚠️ Made as a temporary solution for use on devices that do not have any clients

null 12 Sep 19, 2022
a temporary solution to revert to the old ui. the new ui was put into effect since april

Revert-YouTube-UI a temporary solution to revert to the old ui. the new ui was put into effect since april and is slowly rolling out to users. Feature

a person 8 May 10, 2023
Find and parse the tsconfig.json file from a directory path

get-tsconfig Find and parse tsconfig.json files. Features Zero dependencies (not even TypeScript) Tested against TypeScript for accuracy Supports comm

hiroki osame 66 Jan 2, 2023
Feel free to create new file, don't hesitate to pull your code, the most important thing is that the file name here must match your nickname so that file does not conflict with other people.

Hacktoberfest Indonesia Apa Itu Hacktoberfest ? Hacktoberfest adalah acara tahunan yang bertujuan untuk mendorong berkontribusi kedalam ekosistem open

Juan Daniel 5 Dec 15, 2022
Jester is a test-generation tool to create integration test code.

Code Generator for Integration Tests Introduction Welcome to Jester: An easy-to-use web application that helps you create and implement integration te

OSLabs Beta 54 Dec 12, 2022
SWC plugin for transforming import path.

swc-plugin-transform-import Inspired from babel-plugin-transform-imports Installation npm i -D swc-plugin-transform-import Uses with webpack-config //

Ankit Chouhan 35 Dec 24, 2022