noRealTemporaryDirectoryUnit tests must not touch real temp directories. Use memfs through an injected fs seam, or move the test to a *.integration.test.ts file.tmpdirsmall-rules/no-real-temporary-directoryDisallow real temp directories (os.tmpdir, fs.mkdtemp) in unit tests.
A unit test that writes to a real temp directory runs slower and leaves files behind when it fails. Tests
running in parallel can also collide there. The rule reports calls to tmpdir from os, and to mkdtemp or
mkdtempSync from fs, fs.promises, or fs/promises, with or without node:. Pass an in-memory file
system such as memfs through a parameter instead. A test that needs a real directory belongs in an
integration test, so enable this rule for unit test files only.
Scope analysis follows the binding through named, aliased, namespace, and default imports, require(),
await import(), and object destructuring. A local function or a memfs method with the same name passes.
additionalFunctions adds other functions that make a real temp directory, grouped by module. Write a
function inside a namespace as a dotted path. For example,
{ source: "tmp", functions: ["dirSync", "promises.dir"] } covers the tmp package.
noRealTemporaryDirectoryUnit tests must not touch real temp directories. Use memfs through an injected fs seam, or move the test to a *.integration.test.ts file.This rule accepts one options object after the severity.
import { mkdtemp } from "node:fs/promises";import { tmpdir } from "node:os";import { join } from "node:path";const directory = await mkdtemp(join(tmpdir(), "case-"));import { fs } from "memfs";
const directory = fs.mkdtempSync("/case-");