diff --git a/src/index.js b/src/index.js index 5493c47..20b3be0 100644 --- a/src/index.js +++ b/src/index.js @@ -1,2 +1,19 @@ -module.exports = () => { +const readConfig = require('./lib/read-config') + +module.exports = (options) => { + const { + cwd, + config: configFilename = 'package.json', + } = Object(options); + let config = readConfig(configFilename, {cwd}) + + if (configFilename === 'package.json') { + config = Object(config)['precise-watcher'] + } + + if (!config) { + return false + } + + return true } diff --git a/src/lib/read-config.js b/src/lib/read-config.js new file mode 100644 index 0000000..5fdd8b0 --- /dev/null +++ b/src/lib/read-config.js @@ -0,0 +1,8 @@ +const path = require('path') + +module.exports = (filename, {cwd}) => { + const userDirectory = cwd || process.cwd() + const filepath = path.resolve(userDirectory, filename) + + return require(filepath) +} diff --git a/test/integration/src.test.js b/test/integration/src.test.js new file mode 100644 index 0000000..737e46a --- /dev/null +++ b/test/integration/src.test.js @@ -0,0 +1,13 @@ +describe('/src', () => { + const preciseWatcher = require('../../src') + + it('Should read config from "precise-watcher" property located in ' + + 'users\' package.json, by default', async () => { + // Should return early (returning false). + jest.doMock('../../package.json', () => ({ + 'precise-watcher': true + }), { virtual: true }) + + expect(preciseWatcher()).toBe(true) + }) +})