Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/appdistribution/yaml_helper.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as jsYaml from "js-yaml";
import { getErrMsg, FirebaseError } from "../error";
import { TestCase } from "./types";
import { TestCase, AiStep } from "./types";

declare interface YamlStep {
/** An AI test step in YAML format. */
export declare interface YamlStep {
goal?: string;
hint?: string;
finalScreenAssertion?: string;
Expand Down Expand Up @@ -45,6 +46,7 @@ function toYamlTestCases(testCases: TestCase[]): YamlTestCase[] {
}));
}

/** Converts a list of test cases to YAML format. */
export function toYaml(testCases: TestCase[]): string {
return jsYaml.safeDump({ tests: toYamlTestCases(testCases) });
}
Expand All @@ -64,22 +66,25 @@ function checkAllowedKeys(allowedKeys: Set<string>, o: object) {
}
}

/** Converts an AI test step from YAML format. */
export function fromYamlStep(yamlStep: YamlStep): AiStep {
checkAllowedKeys(ALLOWED_YAML_STEP_KEYS, yamlStep);
return {
goal: castExists(yamlStep.goal, "goal"),
...(yamlStep.hint && { hint: yamlStep.hint }),
...(yamlStep.finalScreenAssertion && {
successCriteria: yamlStep.finalScreenAssertion,
}),
};
}

function fromYamlTestCases(appName: string, yamlTestCases: YamlTestCase[]): TestCase[] {
return yamlTestCases.map((yamlTestCase) => {
checkAllowedKeys(ALLOWED_YAML_TEST_CASE_KEYS, yamlTestCase);
return {
displayName: castExists(yamlTestCase.displayName, "displayName"),
aiInstructions: {
steps: castExists(yamlTestCase.steps, "steps").map((yamlStep) => {
checkAllowedKeys(ALLOWED_YAML_STEP_KEYS, yamlStep);
return {
goal: castExists(yamlStep.goal, "goal"),
...(yamlStep.hint && { hint: yamlStep.hint }),
...(yamlStep.finalScreenAssertion && {
successCriteria: yamlStep.finalScreenAssertion,
}),
};
}),
steps: castExists(yamlTestCase.steps, "steps").map((yamlStep) => fromYamlStep(yamlStep)),
},
...(yamlTestCase.id && {
name: `${appName}/testCases/${yamlTestCase.id}`,
Expand All @@ -91,6 +96,7 @@ function fromYamlTestCases(appName: string, yamlTestCases: YamlTestCase[]): Test
});
}

/** Converts a list of test cases from YAML format. */
export function fromYaml(appName: string, yaml: string): TestCase[] {
let parsedYaml: unknown;
try {
Expand Down
4 changes: 2 additions & 2 deletions src/apptesting/invokeTests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe("invokeTests", () => {
testCase: {
startUri: "https://www.example.com",
displayName: "testName2",
steps: [{ goal: "retest it", finalScreenAssertion: "a dialog appears" }],
steps: [{ goal: "retest it", successCriteria: "a dialog appears" }],
},
testExecution: [{ config: { browser: Browser.CHROME } }],
},
Expand Down Expand Up @@ -89,7 +89,7 @@ describe("invokeTests", () => {
steps: [
{
goal: "retest it",
finalScreenAssertion: "a dialog appears",
successCriteria: "a dialog appears",
},
],
startUri: "https://www.example.com",
Expand Down
2 changes: 1 addition & 1 deletion src/apptesting/parseTestFiles.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe("parseTestFiles", () => {
{
goal: "View the provided application",
hint: "No additional actions should be necessary",
finalScreenAssertion: "The application should load with no obvious errors",
successCriteria: "The application should load with no obvious errors",
},
],
},
Expand Down
3 changes: 2 additions & 1 deletion src/apptesting/parseTestFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { logger } from "../logger";
import { Browser, TestCaseInvocation, TestStep } from "./types";
import { readFileFromDirectory, wrappedSafeLoad } from "../utils";
import { FirebaseError, getErrMsg, getError } from "../error";
import { fromYamlStep, YamlStep } from "../appdistribution/yaml_helper";

export async function parseTestFiles(
dir: string,
Expand Down Expand Up @@ -143,7 +144,7 @@ function toTestCaseInvocation(
prerequisiteTestCaseId: testDef.prerequisiteTestCaseId,
startUri: targetUri + route,
displayName: testDef.displayName,
steps: steps,
steps: steps.map((step: YamlStep) => fromYamlStep(step)),
},
testExecution: browsers.map((browser) => ({ config: { browser } })),
};
Expand Down
2 changes: 1 addition & 1 deletion src/apptesting/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface TestStep {
goal: string;
finalScreenAssertion?: string;
successCriteria?: string;
hint?: string;
}

Expand Down
Loading