Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
using-temporary-files
Advanced tools
usingTemporaryFiles() - a utility for testing code that accesses the file system
A utility for working with tests that need to write to / read from the file system.
It creates a temporary directory, copies the specified files into it, provides some functions for working with files in the temporary directory, and then deletes the directory when the callback returns or an error occurs.
npm install --save-dev using-temporary-files
import { usingTemporaryFiles } from "using-temporary-files";
await usingTemporaryFiles(async ({ path, add, addDirectory, remove }) => {
path("."); // full path to the temporary directory
path("file.txt"); // full path to a particular file
await add("file.txt", "content"); // add a file
const text = await read("file.txt" /*, encoding (optional) */); // read the contents of a file
await addDirectory("dir"); // add a directory
await remove("file.txt"); // remove a file
});
This code was extracted from Counterfact so that it can be
used in other projects. The original function was named withTemporaryFiles()
. It was renamed to
usingTemporaryFiles
so that it resembles the
Explicit Resource Management proposal.
To understand how it's used in practice, see the tests in Counterfact
Note that until I get around to updating Counterfact to use this package, the API for withTemporaryFiles()
has a few minor differences. Mainly extra arguments that we can do without.
Yes, it is. And that's what I do most of the time. But it's good to have a couple of end-to-end tests that exercise the real file system. This utility makes it easier to write those tests.
FAQs
usingTemporaryFiles() - a utility for testing code that accesses the file system
We found that using-temporary-files demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.