Browse Source

Allow exceptions to be propagated (#15)

master
dword-design 5 years ago
committed by Luke Childs
parent
commit
468acf9b69
  1. 8
      src/index.js
  2. 14
      test/exceptions.js
  3. 1
      test/helpers/package-with-exception/index.js
  4. 1
      test/helpers/package-with-exception/package.json

8
src/index.js

@ -2,8 +2,6 @@
const pkgDir = require('pkg-dir'); const pkgDir = require('pkg-dir');
try { const packageDir = pkgDir.sync();
module.exports = require(pkgDir.sync());
} catch (err) { module.exports = packageDir === null ? undefined : require(packageDir);
module.exports = undefined;
}

14
test/exceptions.js

@ -0,0 +1,14 @@
import test from 'ava';
const cwd = process.cwd();
const pkgPath = require.resolve('../');
test.afterEach.always(() => {
process.chdir(cwd);
delete require.cache[pkgPath];
});
test.serial(`throws exceptions`, t => {
process.chdir('test/helpers/package-with-exception');
t.throws(() => require(pkgPath));
});

1
test/helpers/package-with-exception/index.js

@ -0,0 +1 @@
throw new Error('error');

1
test/helpers/package-with-exception/package.json

@ -0,0 +1 @@
{}
Loading…
Cancel
Save