-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: revert to original prompt implementation #968
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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
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,76 +1,73 @@ | ||
import {expect} from 'chai' | ||
import readline from 'node:readline' | ||
import {SinonSandbox, createSandbox} from 'sinon' | ||
import * as chai from 'chai' | ||
|
||
const {expect} = chai | ||
|
||
import {ux} from '../../src/cli-ux' | ||
import {fancy} from './fancy' | ||
|
||
describe('prompt', () => { | ||
let sandbox: SinonSandbox | ||
|
||
function stubReadline(answers: string[]) { | ||
let callCount = 0 | ||
sandbox.stub(readline, 'createInterface').returns({ | ||
// @ts-expect-error because we're stubbing | ||
async question(_message, opts, cb) { | ||
callCount += 1 | ||
cb(answers[callCount - 1]) | ||
}, | ||
close() {}, | ||
fancy | ||
.stdout() | ||
.stderr() | ||
.end('requires input', async () => { | ||
const promptPromise = ux.prompt('Require input?') | ||
process.stdin.emit('data', '') | ||
process.stdin.emit('data', 'answer') | ||
const answer = await promptPromise | ||
await ux.done() | ||
expect(answer).to.equal('answer') | ||
}) | ||
} | ||
|
||
beforeEach(() => { | ||
sandbox = createSandbox() | ||
}) | ||
|
||
afterEach(() => { | ||
sandbox.restore() | ||
}) | ||
|
||
it('should require input', async () => { | ||
stubReadline(['', '', 'answer']) | ||
const answer = await ux.prompt('Require input?') | ||
expect(answer).to.equal('answer') | ||
}) | ||
|
||
it('should not require input if required = false', async () => { | ||
stubReadline(['']) | ||
const answer = await ux.prompt('Require input?', {required: false}) | ||
expect(answer).to.equal('') | ||
}) | ||
|
||
it('should use default input', async () => { | ||
stubReadline(['']) | ||
const answer = await ux.prompt('Require input?', {default: 'default'}) | ||
expect(answer).to.equal('default') | ||
}) | ||
fancy | ||
.stdout() | ||
.stderr() | ||
.stdin('y') | ||
.end('confirm', async () => { | ||
const promptPromise = ux.confirm('yes/no?') | ||
const answer = await promptPromise | ||
await ux.done() | ||
expect(answer).to.equal(true) | ||
}) | ||
|
||
it('should timeout after provided timeout', async () => { | ||
stubReadline(['']) | ||
sandbox.stub(process, 'stdin').value({isTTY: true}) | ||
try { | ||
await ux.prompt('Require input?', {timeout: 10}) | ||
expect.fail('should have thrown') | ||
} catch (error: any) { | ||
expect(error.message).to.equal('Prompt timeout') | ||
} | ||
}) | ||
fancy | ||
.stdout() | ||
.stderr() | ||
.stdin('n') | ||
.end('confirm', async () => { | ||
const promptPromise = ux.confirm('yes/no?') | ||
const answer = await promptPromise | ||
await ux.done() | ||
expect(answer).to.equal(false) | ||
}) | ||
|
||
it('should confirm with y', async () => { | ||
stubReadline(['y']) | ||
const answer = await ux.confirm('yes/no?') | ||
expect(answer).to.equal(true) | ||
}) | ||
fancy | ||
.stdout() | ||
.stderr() | ||
.stdin('x') | ||
.end('gets anykey', async () => { | ||
const promptPromise = ux.anykey() | ||
const answer = await promptPromise | ||
await ux.done() | ||
expect(answer).to.equal('x') | ||
}) | ||
|
||
it('should confirm with n', async () => { | ||
stubReadline(['n']) | ||
const answer = await ux.confirm('yes/no?') | ||
expect(answer).to.equal(false) | ||
}) | ||
fancy | ||
.stdout() | ||
.stderr() | ||
.end('does not require input', async () => { | ||
const promptPromise = ux.prompt('Require input?', { | ||
required: false, | ||
}) | ||
process.stdin.emit('data', '') | ||
const answer = await promptPromise | ||
await ux.done() | ||
expect(answer).to.equal('') | ||
}) | ||
|
||
it('should get anykey', async () => { | ||
stubReadline(['x']) | ||
const answer = await ux.anykey() | ||
expect(answer).to.equal('x') | ||
}) | ||
fancy | ||
.stdout() | ||
.stderr() | ||
.it('timeouts with no input', async () => { | ||
await expect(ux.prompt('Require input?', {timeout: 1})).to.eventually.be.rejectedWith('Prompt timeout') | ||
}) | ||
}) |
Oops, something went wrong.
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.
suggestion:
external-test
could use the normal retries codesalesforcecli/github-workflows/.github/actions/retry instead of all of its consumers need to do this
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'll update this
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.
Hm, actually. I don't think this will work since
external-test.yml
usesworking-directory
. An external action (uses
) needs to support passing it in, which the retry action we use does not https://github.com/nick-fields/retryhttps://stackoverflow.com/questions/58139175/running-actions-in-another-directory#comment126980684_63122434
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.
@iowillhoit @mshanemc I don't think we can use the retry action since you need to be able to set theworking_directory
, which as far as I can tell isn't possible with that actionLooks like Eric beat me to it 😄
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.
haha exactly 😅 We were both looking at this at the same time ^