From b4cba63397e8e66bc5a70f2adc572af39af1a8fe Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Sat, 7 Sep 2024 15:54:51 -0300 Subject: [PATCH] add test to test AbortSignal for PromptModule with modern prompt (#1535) Co-authored-by: Simon Boudrias --- packages/inquirer/inquirer.test.mts | 18 ++++++++++++++++++ packages/inquirer/package.json | 1 + yarn.lock | 1 + 3 files changed, 20 insertions(+) diff --git a/packages/inquirer/inquirer.test.mts b/packages/inquirer/inquirer.test.mts index 589c07285..391dbc61f 100644 --- a/packages/inquirer/inquirer.test.mts +++ b/packages/inquirer/inquirer.test.mts @@ -9,6 +9,7 @@ import stream from 'node:stream'; import tty from 'node:tty'; import { vi, expect, beforeEach, afterEach, describe, it, expectTypeOf } from 'vitest'; import { of } from 'rxjs'; +import { AbortPromptError, createPrompt } from '@inquirer/core'; import type { InquirerReadline } from '@inquirer/type'; import inquirer, { type QuestionMap } from './src/index.mjs'; import type { Answers } from './src/types.mjs'; @@ -758,6 +759,23 @@ describe('inquirer.prompt(...)', () => { }); }); +describe('AbortSignal support', () => { + it('modern prompts can be aborted through PromptModule constructor', async () => { + const abortController = new AbortController(); + const localPrompt = inquirer.createPromptModule({ + signal: abortController.signal, + }); + localPrompt.registerPrompt( + 'stub', + createPrompt(() => 'dummy prompt'), + ); + + const promise = localPrompt({ type: 'stub', name: 'q1', message: 'message' }); + abortController.abort(); + await expect(promise).rejects.toThrow(AbortPromptError); + }); +}); + describe('Non-TTY checks', () => { let original: boolean; diff --git a/packages/inquirer/package.json b/packages/inquirer/package.json index cda33b5d8..48a21e199 100644 --- a/packages/inquirer/package.json +++ b/packages/inquirer/package.json @@ -55,6 +55,7 @@ }, "license": "MIT", "dependencies": { + "@inquirer/core": "^9.1.0", "@inquirer/prompts": "^5.5.0", "@inquirer/type": "^1.5.3", "@types/mute-stream": "^0.0.4", diff --git a/yarn.lock b/yarn.lock index b9869e1e7..7606e70f5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4549,6 +4549,7 @@ __metadata: version: 0.0.0-use.local resolution: "inquirer@workspace:packages/inquirer" dependencies: + "@inquirer/core": "npm:^9.1.0" "@inquirer/prompts": "npm:^5.5.0" "@inquirer/type": "npm:^1.5.3" "@types/mute-stream": "npm:^0.0.4"