@poppinss/prompts
Advanced tools
Comparing version 3.1.0-1 to 3.1.0-2
@@ -0,1 +1,3 @@ | ||
/// <reference types="node" resolution-mode="require"/> | ||
import { AssertionError } from 'node:assert'; | ||
import { PromptChoice, ListPromptOptions, TextPromptOptions, TogglePromptOptions, ChoicePromptOptions, BooleanPromptOptions, MultiplePromptOptions, AutoCompletePromptOptions } from './types.js'; | ||
@@ -8,3 +10,3 @@ import { MockedPrompt } from './mocked_prompt.js'; | ||
prompt: MockedPrompt; | ||
triggerError: Error; | ||
triggerError: AssertionError; | ||
}>; | ||
@@ -11,0 +13,0 @@ verify: () => void; |
@@ -0,1 +1,2 @@ | ||
import { AssertionError } from 'node:assert'; | ||
import { ObjectBuilder } from '@poppinss/utils'; | ||
@@ -176,3 +177,5 @@ import { colors } from './colors.js'; | ||
trap(message) { | ||
const triggerError = new Error(`Expected prompt "${message}" to get triggered`); | ||
const triggerError = new AssertionError({ | ||
message: `Expected prompt "${message}" to get triggered`, | ||
}); | ||
const mockedPrompt = new MockedPrompt(); | ||
@@ -179,0 +182,0 @@ this.traps.prompts.set(message, { prompt: mockedPrompt, triggerError }); |
@@ -0,1 +1,3 @@ | ||
import { inspect } from 'node:util'; | ||
import { AssertionError } from 'node:assert'; | ||
export class MockedPrompt { | ||
@@ -75,2 +77,3 @@ #answer; | ||
result !== assertion.expectedErrorMessage) { | ||
assertion.error.actual = result; | ||
throw assertion.error; | ||
@@ -141,7 +144,30 @@ } | ||
assertFails(value, message) { | ||
const error = new Error(message | ||
? typeof message === 'string' | ||
? `Expected assertion to fail with message "${message}"` | ||
: `Expected assertion messages to match "${message}"` | ||
: 'Expected assertion to fail'); | ||
if (!message) { | ||
this.#assertions.push({ | ||
value, | ||
expectsError: true, | ||
expectedErrorMessage: message, | ||
error: new AssertionError({ | ||
message: 'Expected prompt validation to fail', | ||
stackStartFn: this.assertFails, | ||
}), | ||
}); | ||
return this; | ||
} | ||
if (typeof message === 'string') { | ||
const error = new AssertionError({ | ||
message: `Expected prompt validation message to equal ${inspect(message)}`, | ||
expected: message, | ||
operator: 'strictEqual', | ||
stackStartFn: this.assertFails, | ||
}); | ||
Object.defineProperty(error, 'showDiff', { value: true }); | ||
this.#assertions.push({ | ||
value, | ||
expectsError: true, | ||
expectedErrorMessage: message, | ||
error, | ||
}); | ||
return this; | ||
} | ||
this.#assertions.push({ | ||
@@ -151,3 +177,6 @@ value, | ||
expectedErrorMessage: message, | ||
error: error, | ||
error: new AssertionError({ | ||
message: `Expected prompt validation message to match ${inspect(message)}`, | ||
expected: message, | ||
}), | ||
}); | ||
@@ -157,3 +186,5 @@ return this; | ||
assertPasses(value) { | ||
const error = new Error('Expected assertion to pass, instead it failed'); | ||
const error = new AssertionError({ | ||
message: 'Expected assertion to pass, instead it failed', | ||
}); | ||
this.#assertions.push({ | ||
@@ -160,0 +191,0 @@ value, |
{ | ||
"name": "@poppinss/prompts", | ||
"version": "3.1.0-1", | ||
"version": "3.1.0-2", | ||
"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
37399
585