Skip to content

Commit 0b852e1

Browse files
authored
fix: do nothing if spinner already stopped and stop called (#382)
1 parent 4255673 commit 0b852e1

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

.changeset/short-squids-battle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clack/prompts": patch
3+
---
4+
5+
Handle `stop` calls on spinners which have not yet been started.

packages/prompts/src/spinner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export const spinner = ({
159159
};
160160

161161
const stop = (msg = '', code = 0): void => {
162+
if (!isSpinnerActive) return;
162163
isSpinnerActive = false;
163164
clearInterval(loop);
164165
clearPrevMessage();

packages/prompts/test/spinner.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ describe.each(['true', 'false'])('spinner (isCI = %s)', (isCI) => {
163163

164164
expect(output.buffer).toMatchSnapshot();
165165
});
166+
167+
test('does not throw if called before start', () => {
168+
const result = prompts.spinner({ output });
169+
170+
expect(() => result.stop()).not.toThrow();
171+
});
166172
});
167173

168174
describe('message', () => {

0 commit comments

Comments
 (0)