Skip to content

Commit

Permalink
add test to test AbortSignal for PromptModule with modern prompt (#1535)
Browse files Browse the repository at this point in the history
Co-authored-by: Simon Boudrias <admin@simonboudrias.com>
  • Loading branch information
mshima and SBoudrias authored Sep 7, 2024
1 parent 4937ea3 commit b4cba63
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/inquirer/inquirer.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<TestQuestions>({
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;

Expand Down
1 change: 1 addition & 0 deletions packages/inquirer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b4cba63

Please sign in to comment.