-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(generic): refactor confirm prompts into a helper for interac…
…tive mode
- Loading branch information
1 parent
0923ac1
commit b495012
Showing
6 changed files
with
64 additions
and
29 deletions.
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
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
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,12 @@ | ||
import inquirer from 'inquirer'; | ||
|
||
export default async (interactive, message, defaultValue = true) => { | ||
if (interactive) { | ||
return (await inquirer.createPromptModule()({ | ||
type: 'confirm', | ||
name: 'confirm', | ||
message, | ||
})).confirm; | ||
} | ||
return defaultValue; | ||
}; |
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,36 @@ | ||
import { expect } from 'chai'; | ||
import inquirer from 'inquirer'; | ||
import sinon from 'sinon'; | ||
|
||
import confirmIfInteractive from '../../src/util/confirm-if-interactive'; | ||
|
||
describe('confirm if interactive', () => { | ||
describe('if interactive=true', () => { | ||
let createPromptModuleSpy; | ||
|
||
beforeEach(() => { | ||
createPromptModuleSpy = sinon.stub(inquirer, 'createPromptModule'); | ||
createPromptModuleSpy.returns(() => Promise.resolve({ confirm: 'resolved' })); | ||
}); | ||
|
||
it('should call inquirer prompt', async () => { | ||
const val = await confirmIfInteractive(true, 'Please say yes?'); | ||
expect(createPromptModuleSpy.callCount).to.equal(1); | ||
expect(val).to.equal('resolved'); | ||
}); | ||
|
||
afterEach(() => { | ||
createPromptModuleSpy.restore(); | ||
}); | ||
}); | ||
|
||
describe('if interactive=false', () => { | ||
it('should return true', async () => { | ||
expect(await confirmIfInteractive(false, 'Yolo!')).to.equal(true); | ||
}); | ||
|
||
it('should return the defaultValue if provided', async () => { | ||
expect(await confirmIfInteractive(false, 'Yolo!', 'default_value')).to.equal('default_value'); | ||
}); | ||
}); | ||
}); |