This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Remove process exit from config commands - closes #580 #586
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -18,20 +18,17 @@ import os from 'os'; | |
import lockfile from 'lockfile'; | ||
import { getConfig, setConfig } from '../../src/utils/config'; | ||
import * as fsUtils from '../../src/utils/fs'; | ||
import logger from '../../src/utils/logger'; | ||
import defaultConfig from '../../default_config.json'; | ||
|
||
describe('config utils', () => { | ||
const configDirName = '.lisk-commander'; | ||
const configDirName = '.lisk'; | ||
const configFileName = 'config.json'; | ||
const lockfileName = 'config.lock'; | ||
|
||
const defaultPath = `${os.homedir()}/${configDirName}`; | ||
|
||
beforeEach(() => { | ||
sandbox.stub(fsUtils, 'writeJSONSync'); | ||
sandbox.stub(logger, 'error'); | ||
sandbox.stub(process, 'exit'); | ||
return Promise.resolve(); | ||
}); | ||
|
||
|
@@ -55,10 +52,8 @@ describe('config utils', () => { | |
|
||
it('should log error when it fails to write', () => { | ||
fs.mkdirSync.throws(new Error('failed to create folder')); | ||
getConfig(defaultPath); | ||
expect(process.exit).to.be.calledWithExactly(1); | ||
return expect(logger.error).to.be.calledWithExactly( | ||
`ERROR: Could not write to \`${defaultPath}\`. Your configuration will not be persisted.`, | ||
return expect(() => getConfig(defaultPath)).to.throw( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In other test suite, we do something like |
||
`Could not write to \`${defaultPath}\`. Your configuration will not be persisted.`, | ||
); | ||
}); | ||
}); | ||
|
@@ -79,10 +74,8 @@ describe('config utils', () => { | |
|
||
it('should log error when it fails to write', () => { | ||
fsUtils.writeJSONSync.throws(new Error('failed to write to the file')); | ||
getConfig(defaultPath); | ||
expect(process.exit).to.be.calledWithExactly(1); | ||
return expect(logger.error).to.be.calledWithExactly( | ||
`ERROR: Could not write to \`${defaultPath}/${configFileName}\`. Your configuration will not be persisted.`, | ||
return expect(() => getConfig(defaultPath)).to.throw( | ||
`Could not write to \`${defaultPath}/${configFileName}\`. Your configuration will not be persisted.`, | ||
); | ||
}); | ||
}); | ||
|
@@ -106,18 +99,14 @@ describe('config utils', () => { | |
|
||
it('should log error and exit when it fails to read', () => { | ||
fsUtils.readJSONSync.throws(new Error('failed to read to the file')); | ||
getConfig(defaultPath); | ||
expect(process.exit).to.be.calledWithExactly(1); | ||
return expect(logger.error).to.be.calledWithExactly( | ||
return expect(() => getConfig(defaultPath)).to.throw( | ||
`Config file cannot be read or is not valid JSON. Please check ${defaultPath}/${configFileName} or delete the file so we can create a new one from defaults.`, | ||
); | ||
}); | ||
|
||
it('should log error and exit when it has invalid keys', () => { | ||
fsUtils.readJSONSync.returns({ random: 'values' }); | ||
getConfig(defaultPath); | ||
expect(process.exit).to.be.calledWithExactly(1); | ||
return expect(logger.error).to.be.calledWithExactly( | ||
return expect(() => getConfig(defaultPath)).to.throw( | ||
`Config file seems to be corrupted: missing required keys. Please check ${defaultPath}/${configFileName} or delete the file so we can create a new one from defaults.`, | ||
); | ||
}); | ||
|
@@ -140,9 +129,7 @@ describe('config utils', () => { | |
describe('when lockfile exists', () => { | ||
it('should log error and exit', () => { | ||
lockfile.checkSync.returns(true); | ||
setConfig(defaultPath, newConfigValue); | ||
expect(process.exit).to.be.calledWithExactly(1); | ||
return expect(logger.error).to.be.calledWithExactly( | ||
return expect(() => setConfig(defaultPath, newConfigValue)).to.throw( | ||
`Config lockfile at ${defaultPath}/${lockfileName} found. Are you running Lisk Commander in another process?`, | ||
); | ||
}); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was actually the only place the
logger
was used.Since we use the logger from the
oclif
now, i think we are good to delete this function