1'use strict'; 2 3const path = require('path'); 4const fs = require('fs'); 5const { pathToFileURL } = require('url'); 6 7const fixturesDir = path.join(__dirname, '..', 'fixtures'); 8 9function fixturesPath(...args) { 10 return path.join(fixturesDir, ...args); 11} 12 13function fixturesFileURL(...args) { 14 return pathToFileURL(fixturesPath(...args)); 15} 16 17function readFixtureSync(args, enc) { 18 if (Array.isArray(args)) 19 return fs.readFileSync(fixturesPath(...args), enc); 20 return fs.readFileSync(fixturesPath(args), enc); 21} 22 23function readFixtureKey(name, enc) { 24 return fs.readFileSync(fixturesPath('keys', name), enc); 25} 26 27function readFixtureKeys(enc, ...names) { 28 return names.map((name) => readFixtureKey(name, enc)); 29} 30 31module.exports = { 32 fixturesDir, 33 path: fixturesPath, 34 fileURL: fixturesFileURL, 35 readSync: readFixtureSync, 36 readKey: readFixtureKey, 37 readKeys: readFixtureKeys, 38}; 39