A utility for Vitest to create isolated test directories
📦 Installation
npm install vitest-testdirs --save-dev
🚀 Usage
// index.test.ts
import { readFile } from "node:fs/promises";
import { readFileSync } from "node:fs";
import { testdir, testdirSync } from "vitest-testdirs";
import { describe, expect, vi } from "vitest";
describe("testdir", () => {
it("isolated-test", async () => {
const path = await testdir({
"file1.txt": "Hello, World!",
"file2.txt": "Hello, Vitest!",
});
expect(path).toBeDefined();
expect(path).toContain(".vitest-testdirs/vitest-testdir-isolated-test");
const file = await readFile(`${path}/file1.txt`, "utf8");
expect(file).toBe("Hello, World!");
});
});
describe("testdirSync", () => {
it("isolated-test", () => {
const path = testdirSync({
"file1.txt": "Hello, World!",
"file2.txt": "Hello, Vitest!",
});
expect(path).toBeDefined();
expect(path).toContain(".vitest-testdirs/vitest-testdirSync-isolated-test");
const file = readFileSync(`${path}/file1.txt`, "utf8");
expect(file).toBe("Hello, World!");
});
});
📄 License
Published under MIT License.