* Helper function to enable testing interactive CLI. Retrieves testInput from * the DATAFORM_CLI_TEST_INPUTS environment variable. * @param questionText The exact question text displayed to the user. * @returns Test input for the provided question.
(questionText: string)
| 73 | * @returns Test input for the provided question. |
| 74 | */ |
| 75 | function getTestInput(questionText: string): string { |
| 76 | const envVar = process.env.DATAFORM_CLI_TEST_INPUTS; |
| 77 | if(!envVar) { |
| 78 | throw new Error("Environment variable DATAFORM_CLI_TEST_INPUTS not set."); |
| 79 | } |
| 80 | |
| 81 | try { |
| 82 | const parsed = JSON.parse(envVar); |
| 83 | if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) { |
| 84 | const inputs = new Map<string, string>(Object.entries(parsed).map(([key, value]) => [key, String(value)])); |
| 85 | const trimmedQuestion = questionText.trim(); |
| 86 | const answer = inputs.get(trimmedQuestion); |
| 87 | |
| 88 | if (answer !== undefined) { |
| 89 | print(`[TEST_INPUT for "${trimmedQuestion}"]: "${answer}"`); |
| 90 | return answer; |
| 91 | } else { |
| 92 | throw new Error(`[MISSING TEST_INPUT for "${trimmedQuestion}"]`); |
| 93 | } |
| 94 | } else { |
| 95 | throw new Error(`Failed to parse DATAFORM_CLI_TEST_INPUTS: Expected a JSON object, but got ${typeof parsed}.`); |
| 96 | } |
| 97 | } catch (e) { |
| 98 | throw new Error(`Failed to parse DATAFORM_CLI_TEST_INPUTS: ${e.message || e}`); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | |
| 103 | export function passwordQuestion(questionText: string) { |
no test coverage detected