UNPKG

@appsemble/node-utils

Version:

NodeJS utilities used by Appsemble internally.

42 lines 1.25 kB
import { createReadStream } from 'node:fs'; import { readFile } from 'node:fs/promises'; import { fileURLToPath } from 'node:url'; let baseDir; /** * Set the test fixture base path. This folder should contain a folder named `__fixtures__`. * * This is typically called in `vitest.setup.ts`. * * @param meta The module meta object * @example * ```ts * setFixtureBase(import.meta); * ``` */ export function setFixtureBase(meta) { baseDir = meta.url; } /** * Resolve the path to a test fixture. * * @param path The path to resolve relative to the fixture base. It will be normalized for the * operating system. * @returns The full path to the fixture path. */ export function resolveFixture(path) { return fileURLToPath(new URL(`__fixtures__/${path}`, baseDir)); } export function readFixture(path, encoding) { return readFile(resolveFixture(path), encoding); } /** * Create a read stream for a fixture. * * @param path The path to resolve relative to the fixture base. It will be normalized for the * operating system. * @returns A filesystem read stream for the fixture. */ export function createFixtureStream(path) { return createReadStream(resolveFixture(path)); } //# sourceMappingURL=testFixtures.js.map