Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

temp-sandbox

chrisblossom304MIT4.0.1TypeScript support: included

Create a predictable temporary directory that makes it easy to create, list, and delete files.

sandbox, temp, tmp, test

readme

temp-sandbox

npm Linux Build Status Windows Build Status Code Coverage

About

Create a predictable temporary directory that makes it easy to create, list, and delete files inside of the sandbox.

Installation

npm install --save-dev temp-sandbox

Usage

// index.test.js
import { TempSandbox } from 'temp-sandbox';

// Create sandbox with a predictable directory name
const sandbox = new TempSandbox();

// Create sandbox with randomized directory name
// Typically used inside of a beforeEach
let sandboxRandom = new TempSandbox({ randomDir: true });

beforeEach(async () => {
    sandboxRandom = new TempSandbox({ randomDir: true });

    // Remove all files/directories inside sandbox
    await sandbox.clean();
    sandbox.cleanSync();
});

afterAll(async () => {
    // delete sandbox and sandbox instance
    await sandbox.destroySandbox();
    sandbox.destroySandboxSync();
});

test('create file', async () => {
    // Get absolute path of <SANDBOX>/file1.js
    sandbox.path.resolve('file1.js');

    // Get relative path of <SANDBOX>/nested/file1.js
    sandbox.path.relative('<SANDBOX>/nested/file1.js');

    // Get relative path of <SANDBOX>/nested/file1.js from <SANDBOX>/nested directory
    sandbox.path.relative('nested', '<SANDBOX>/nested/file1.js'); // file1.js

    // Create directory <SANDBOX>/nested/dir
    await sandbox.createDir('nested/dir');
    sandbox.createDirSync('nested/dir');

    // Create file <SANDBOX>/file1.js with contents: // file1.js
    await sandbox.createFile('file1.js', '// file1.js');
    sandbox.createFileSync('file1.js', '// file1.js');

    // Read <SANDBOX>/file1.js contents
    await sandbox.readFile('file1.js');
    sandbox.readFileSync('file1.js');

    // Delete file/folders <SANDBOX>/file1.js
    await sandbox.delete('file1.js');
    sandbox.deleteSync('file1.js');

    // List all files inside sandbox
    const fileList = await sandbox.getFileList();
    const fileListSync = sandbox.getFileListSync();

    // List all files and their checksum
    const fileHashes = await sandbox.getAllFilesHash();
    const fileHashesSync = sandbox.getAllFilesHashSync();

    // Get checksum of file1.js
    const file1Hash = await sandbox.getFileHash('file1.js');
    const file1HashSync = sandbox.getFileHashSync('file1.js');
});

changelog

Change Log

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[Unreleased]

[3.0.0] - 2019-05-18

  • Breaking: Remove node 6 support

[2.0.0] - 2019-04-22

Changed

  • Breaking: replace default export with named export TempSandbox

[1.0.18] - 2019-04-22

Changed

  • Internal: package updates