-
Notifications
You must be signed in to change notification settings - Fork 237
Defer Ink teardown in prompt components #7121
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,11 @@ | ||||||||||||||||||||||||||||
| import {DangerousConfirmationPrompt} from './DangerousConfirmationPrompt.js' | ||||||||||||||||||||||||||||
| import {getLastFrameAfterUnmount, sendInputAndWaitForChange, waitForInputsToBeReady, render} from '../../testing/ui.js' | ||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||
| getLastFrameAfterUnmount, | ||||||||||||||||||||||||||||
| sendInputAndWaitForChange, | ||||||||||||||||||||||||||||
| waitForContent, | ||||||||||||||||||||||||||||
| waitForInputsToBeReady, | ||||||||||||||||||||||||||||
| render, | ||||||||||||||||||||||||||||
| } from '../../testing/ui.js' | ||||||||||||||||||||||||||||
| import {unstyled} from '../../../../public/node/output.js' | ||||||||||||||||||||||||||||
| import React from 'react' | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -61,7 +67,13 @@ describe('DangerousConfirmationPrompt', () => { | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| await waitForInputsToBeReady() | ||||||||||||||||||||||||||||
| await sendInputAndWaitForChange(renderInstance, 'yes') | ||||||||||||||||||||||||||||
| await sendInputAndWaitForChange(renderInstance, ENTER) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| const renderPromise = renderInstance.waitUntilExit() | ||||||||||||||||||||||||||||
| await waitForContent(renderInstance, '✔', () => renderInstance.stdin.write(ENTER)) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| expect(renderPromise.isFulfilled()).toBe(false) | ||||||||||||||||||||||||||||
|
Comment on lines
+71
to
+74
|
||||||||||||||||||||||||||||
| const renderPromise = renderInstance.waitUntilExit() | |
| await waitForContent(renderInstance, '✔', () => renderInstance.stdin.write(ENTER)) | |
| expect(renderPromise.isFulfilled()).toBe(false) | |
| let exitSettled = false | |
| const renderPromise = renderInstance.waitUntilExit().then(() => { | |
| exitSettled = true | |
| }) | |
| await waitForContent(renderInstance, '✔', () => { | |
| expect(exitSettled).toBe(false) | |
| renderInstance.stdin.write(ENTER) | |
| }) |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,5 +1,11 @@ | ||||
| import {SelectPrompt} from './SelectPrompt.js' | ||||
| import {getLastFrameAfterUnmount, sendInputAndWaitForChange, waitForInputsToBeReady, render} from '../../testing/ui.js' | ||||
| import { | ||||
| getLastFrameAfterUnmount, | ||||
| sendInputAndWaitForChange, | ||||
| waitForContent, | ||||
| waitForInputsToBeReady, | ||||
| render, | ||||
| } from '../../testing/ui.js' | ||||
| import {unstyled} from '../../../../public/node/output.js' | ||||
| import {Stdout} from '../../ui.js' | ||||
| import {AbortController} from '../../../../public/node/abort.js' | ||||
|
|
@@ -53,8 +59,13 @@ describe('SelectPrompt', async () => { | |||
|
|
||||
| await waitForInputsToBeReady() | ||||
| await sendInputAndWaitForChange(renderInstance, ARROW_DOWN) | ||||
| await sendInputAndWaitForChange(renderInstance, ENTER) | ||||
|
|
||||
| const renderPromise = renderInstance.waitUntilExit() | ||||
| await waitForContent(renderInstance, '✔', () => renderInstance.stdin.write(ENTER)) | ||||
|
|
||||
| expect(renderPromise.isFulfilled()).toBe(false) | ||||
|
|
||||
|
Comment on lines
+66
to
+67
|
||||
| expect(renderPromise.isFulfilled()).toBe(false) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| import {TextPrompt} from './TextPrompt.js' | ||
| import {getLastFrameAfterUnmount, sendInputAndWaitForChange, waitForInputsToBeReady, render} from '../../testing/ui.js' | ||
| import { | ||
| getLastFrameAfterUnmount, | ||
| sendInputAndWaitForChange, | ||
| waitForContent, | ||
| waitForInputsToBeReady, | ||
| render, | ||
| } from '../../testing/ui.js' | ||
| import {unstyled} from '../../../../public/node/output.js' | ||
| import {AbortController} from '../../../../public/node/abort.js' | ||
| import colors from '../../../../public/node/colors.js' | ||
|
|
@@ -72,7 +78,13 @@ describe('TextPrompt', () => { | |
|
|
||
| await waitForInputsToBeReady() | ||
| await sendInputAndWaitForChange(renderInstance, 'A') | ||
| await sendInputAndWaitForChange(renderInstance, ENTER) | ||
|
|
||
| const renderPromise = renderInstance.waitUntilExit() | ||
| await waitForContent(renderInstance, '✔', () => renderInstance.stdin.write(ENTER)) | ||
|
|
||
| expect(renderPromise.isFulfilled()).toBe(false) | ||
|
|
||
| await renderPromise | ||
|
Comment on lines
+82
to
+87
|
||
| expect(onSubmit).toHaveBeenCalledWith('A') | ||
| expect(unstyled(getLastFrameAfterUnmount(renderInstance)!)).toMatchInlineSnapshot(` | ||
| "? Test question: | ||
|
|
@@ -86,7 +98,13 @@ describe('TextPrompt', () => { | |
| const renderInstance = render(<TextPrompt onSubmit={onSubmit} message="Test question" defaultValue="A" />) | ||
|
|
||
| await waitForInputsToBeReady() | ||
| await sendInputAndWaitForChange(renderInstance, ENTER) | ||
|
|
||
| const renderPromise = renderInstance.waitUntilExit() | ||
| await waitForContent(renderInstance, '✔', () => renderInstance.stdin.write(ENTER)) | ||
|
|
||
| expect(renderPromise.isFulfilled()).toBe(false) | ||
|
|
||
| await renderPromise | ||
| expect(onSubmit).toHaveBeenCalledWith('A') | ||
| expect(unstyled(getLastFrameAfterUnmount(renderInstance)!)).toMatchInlineSnapshot(` | ||
| "? Test question: | ||
|
|
@@ -102,7 +120,13 @@ describe('TextPrompt', () => { | |
| ) | ||
|
|
||
| await waitForInputsToBeReady() | ||
| await sendInputAndWaitForChange(renderInstance, ENTER) | ||
|
|
||
| const renderPromise = renderInstance.waitUntilExit() | ||
| await waitForContent(renderInstance, '✔', () => renderInstance.stdin.write(ENTER)) | ||
|
|
||
| expect(renderPromise.isFulfilled()).toBe(false) | ||
|
|
||
| await renderPromise | ||
| expect(onSubmit).toHaveBeenCalledWith('') | ||
| expect(unstyled(getLastFrameAfterUnmount(renderInstance)!)).toMatchInlineSnapshot(` | ||
| "? Test question: | ||
|
|
@@ -124,7 +148,13 @@ describe('TextPrompt', () => { | |
| ) | ||
|
|
||
| await waitForInputsToBeReady() | ||
| await sendInputAndWaitForChange(renderInstance, ENTER) | ||
|
|
||
| const renderPromise = renderInstance.waitUntilExit() | ||
| await waitForContent(renderInstance, '✔', () => renderInstance.stdin.write(ENTER)) | ||
|
|
||
| expect(renderPromise.isFulfilled()).toBe(false) | ||
|
|
||
| await renderPromise | ||
| expect(onSubmit).toHaveBeenCalledWith('A') | ||
| expect(unstyled(getLastFrameAfterUnmount(renderInstance)!)).toMatchInlineSnapshot(` | ||
| "? Test question: | ||
|
|
@@ -151,7 +181,8 @@ describe('TextPrompt', () => { | |
| }) | ||
|
|
||
| test("masking the input if it's a password", async () => { | ||
| const renderInstance = render(<TextPrompt onSubmit={() => {}} message="Test question" password />) | ||
| const onSubmit = vi.fn() | ||
| const renderInstance = render(<TextPrompt onSubmit={onSubmit} message="Test question" password />) | ||
|
|
||
| await waitForInputsToBeReady() | ||
| await sendInputAndWaitForChange(renderInstance, 'ABC') | ||
|
|
@@ -162,7 +193,13 @@ describe('TextPrompt', () => { | |
| " | ||
| `) | ||
|
|
||
| await sendInputAndWaitForChange(renderInstance, ENTER) | ||
| const renderPromise = renderInstance.waitUntilExit() | ||
| await waitForContent(renderInstance, '✔', () => renderInstance.stdin.write(ENTER)) | ||
|
|
||
| expect(renderPromise.isFulfilled()).toBe(false) | ||
|
|
||
| await renderPromise | ||
| expect(onSubmit).toHaveBeenCalledWith('ABC') | ||
| expect(unstyled(getLastFrameAfterUnmount(renderInstance)!)).toMatchInlineSnapshot(` | ||
| "? Test question: | ||
| ✔ *** | ||
|
|
||
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.
waitForContentyields viasetImmediate, anduseDeferredUnmountschedulesexitviasetImmediateas well. That means by the timewaitForContentresolves,renderPromisemay already be fulfilled while the last frame still includes✔, causing this assertion to be timing-sensitive. Consider asserting the ordering between “✔observed” and “exit resolved” directly (e.g., by racing those two conditions) instead of checkingisFulfilled()afterwaitForContentcompletes.