@poppinss/prompts
Advanced tools
Comparing version 3.1.0-0 to 3.1.0-1
@@ -5,4 +5,10 @@ import { PromptChoice, ListPromptOptions, TextPromptOptions, TogglePromptOptions, ChoicePromptOptions, BooleanPromptOptions, MultiplePromptOptions, AutoCompletePromptOptions } from './types.js'; | ||
#private; | ||
traps: { | ||
prompts: Map<string, { | ||
prompt: MockedPrompt; | ||
triggerError: Error; | ||
}>; | ||
verify: () => void; | ||
}; | ||
protected abstract prompt(options: any): Promise<any>; | ||
get traps(): string[]; | ||
ask<Result extends any = string>(title: string, options?: TextPromptOptions<Result>): Promise<Result>; | ||
@@ -9,0 +15,0 @@ list<Result extends any = string[]>(title: string, options?: ListPromptOptions<Result>): Promise<Result>; |
@@ -6,12 +6,19 @@ import { ObjectBuilder } from '@poppinss/utils'; | ||
export class BasePrompt { | ||
#mockedPrompts = new Map(); | ||
traps = { | ||
prompts: new Map(), | ||
verify() { | ||
this.prompts.forEach((entry) => { | ||
throw entry.triggerError; | ||
}); | ||
}, | ||
}; | ||
#handlePrompt(options) { | ||
let mockedPrompt; | ||
if (this.#mockedPrompts.has(options.name)) { | ||
mockedPrompt = this.#mockedPrompts.get(options.name); | ||
this.#mockedPrompts.delete(options.name); | ||
if (this.traps.prompts.has(options.name)) { | ||
mockedPrompt = this.traps.prompts.get(options.name).prompt; | ||
this.traps.prompts.delete(options.name); | ||
} | ||
else if (this.#mockedPrompts.has(options.message)) { | ||
mockedPrompt = this.#mockedPrompts.get(options.message); | ||
this.#mockedPrompts.delete(options.message); | ||
else if (this.traps.prompts.has(options.message)) { | ||
mockedPrompt = this.traps.prompts.get(options.message).prompt; | ||
this.traps.prompts.delete(options.message); | ||
} | ||
@@ -23,5 +30,2 @@ if (mockedPrompt) { | ||
} | ||
get traps() { | ||
return Array.from(this.#mockedPrompts.keys()); | ||
} | ||
async ask(title, options) { | ||
@@ -174,6 +178,7 @@ options = options || {}; | ||
trap(message) { | ||
const triggerError = new Error(`Expected prompt "${message}" to get triggered`); | ||
const mockedPrompt = new MockedPrompt(); | ||
this.#mockedPrompts.set(message, mockedPrompt); | ||
this.traps.prompts.set(message, { prompt: mockedPrompt, triggerError }); | ||
return mockedPrompt; | ||
} | ||
} |
{ | ||
"name": "@poppinss/prompts", | ||
"version": "3.1.0-0", | ||
"version": "3.1.0-1", | ||
"description": "Wrapper over enquirer with better support for testing", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36124
549