MCPcopy Create free account
hub / github.com/dataform-co/dataform / getTestInput

Function getTestInput

cli/console.ts:75–100  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

73 * @returns Test input for the provided question.
74 */
75function 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
103export function passwordQuestion(questionText: string) {

Callers 1

interactiveQuestionFunction · 0.85

Calls 3

getMethod · 0.80
printFunction · 0.70
parseMethod · 0.45

Tested by

no test coverage detected