fixtures-directory.js
This file
Path
test/helpers/fixtures-directory.js
27 lines · 1.0 KiB · JavaScript
Last changed by
Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454
History of this fileTake it
12345678910111213141516171819202122232425262728import path from 'node:path';import process from 'node:process';import {fileURLToPath} from 'node:url';import logProcessErrors from 'log-process-errors';import pathKey from 'path-key';
// Make tests fail if any warning (such as a deprecation warning) is emitted// eslint-disable-next-line unicorn/no-top-level-side-effects -- must run as soon as this helper is importedlogProcessErrors({ onError(error, event) { if (event === 'warning') { throw error; } },});
export const PATH_KEY = pathKey();export const FIXTURES_DIRECTORY_URL = new URL('../fixtures/', import.meta.url);// @todo: use import.meta.dirname after dropping support for Node <20.11.0export const FIXTURES_DIRECTORY = path.resolve(fileURLToPath(FIXTURES_DIRECTORY_URL));
// Add the fixtures directory to PATH so fixtures can be executed without adding// `node`. This is only meant to make writing tests simpler.export const setFixtureDirectory = () => { process.env[PATH_KEY] = FIXTURES_DIRECTORY + path.delimiter + process.env[PATH_KEY];};