this
Version:
Traverses up the directory tree and returns the first module found
20 lines (15 loc) • 430 B
JavaScript
import test from 'ava';
const cwd = process.cwd();
const pkgPath = require.resolve('../');
test.afterEach.always(() => {
process.chdir(cwd);
delete require.cache[pkgPath];
});
test.serial(`exports root module`, t => {
process.chdir('test/helpers/package');
t.is(require(pkgPath), 'package');
});
test.serial(`exports undfined if there's no root module`, t => {
process.chdir('/');
t.is(require(pkgPath), undefined);
});