-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Read "precise-watcher" property in package.json by default
ENH: Add src/lib/read-config.js TST: Test setting config via package.json in test/integration/src.test.js
- Loading branch information
1 parent
2ba2428
commit 2f147da
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
}) | ||
}) |