Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function loadConfig({configFile, resolveFrom = process.cwd(), defaults = {}} = {}) { // eslint-disable-line complexity
let packageConf = pkgConf.sync('ava', {cwd: resolveFrom});
const filepath = pkgConf.filepath(packageConf);
const projectDir = filepath === null ? resolveFrom : path.dirname(filepath);
const fileForErrorMessage = configFile || 'ava.config.js';
const allowConflictWithPackageJson = Boolean(configFile);
if (configFile) {
configFile = path.resolve(configFile); // Relative to CWD
if (path.basename(configFile) !== path.relative(projectDir, configFile)) {
throw new Error('Config files must be located next to the package.json file');
}
} else {
configFile = path.join(projectDir, 'ava.config.js');
}
let fileConf;
try {
test('test', t => {
const conf = pkgConf.sync('ava');
const pkgDir = path.dirname(pkgConf.filepath(conf));
t.is(process.cwd(), pkgDir);
});
import * as fs from 'fs'
import * as path from 'path'
import * as config from 'pkg-conf'
import playback from './playback'
import record from './record'
const avaConfing = config.sync<{ playbacks?: string }>('ava', { defaults: { playbacks: 'playbacks' } })
const projectPath = path.dirname(config.filepath(avaConfing))
const playbacksPath = path.join(projectPath, avaConfing.playbacks)
if (!fs.existsSync(playbacksPath)) fs.mkdirSync(playbacksPath)
const mode = process.env.AVA_PLAYBACK
if (mode === 'record') record(playbacksPath)
if (mode === 'play') playback(playbacksPath)