-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New command that allows for a user to run mobile tests that are defined as yaml. #9626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jrothfeder
wants to merge
14
commits into
main
Choose a base branch
from
test-schema
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+409
−42
Open
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7b9e146
WIP
ae07bd4
WIP
fb8b5ae
WIP
efbdf28
Update src/apptesting/parseTestFiles.ts
jrothfeder e5654a8
Apply suggestion from @gemini-code-assist[bot]
jrothfeder ad7d56d
Merge branch 'main' into test-schema
jrothfeder 1b7d6a4
Remove accidently committed test directory.
ff27bfe
Fix ordering of params.
87a08e6
Remove MATA experiment and instead roll this functionality under exis…
463ad1e
Merge branch 'main' into test-schema
jrothfeder 8ebaa0d
Merge branch 'main' into test-schema
jrothfeder d36742e
Merge branch 'main' into test-schema
jrothfeder df382b6
Add support to specify devices.
4b7de39
Add support for prerequisite tests (#9651)
tagboola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { requireAuth } from "../requireAuth"; | ||
| import { Command } from "../command"; | ||
| import { logger } from "../logger"; | ||
| import * as clc from "colorette"; | ||
| import { parseTestFiles } from "../apptesting/parseTestFiles"; | ||
| import * as ora from "ora"; | ||
| import { TestCaseInvocation } from "../apptesting/types"; | ||
| import { FirebaseError, getError } from "../error"; | ||
| import { marked } from "marked"; | ||
| import { AppDistributionClient } from "../appdistribution/client"; | ||
| import { Distribution, upload } from "../appdistribution/distribution"; | ||
| import { AIInstruction, ReleaseTest } from "../appdistribution/types"; | ||
| import { getAppName } from "../appdistribution/options-parser-util"; | ||
|
|
||
| // TODO rothbutter add ability to specify devices | ||
| const defaultDevices = [ | ||
| { | ||
| model: "MediumPhone.arm", | ||
| version: "30", | ||
| locale: "en_US", | ||
| orientation: "portrait", | ||
| }, | ||
| ]; | ||
|
|
||
| export const command = new Command("apptesting:mobile-execute <target>") | ||
| .description("Run mobile automated tests written in natural language driven by AI") | ||
| .option( | ||
| "--app <app_id>", | ||
| "The app id of your Firebase web app. Optional if the project contains exactly one web app.", | ||
| ) | ||
| .option( | ||
| "--test-file-pattern <pattern>", | ||
| "Test file pattern. Only tests contained in files that match this pattern will be executed.", | ||
| ) | ||
| .option( | ||
| "--test-name-pattern <pattern>", | ||
| "Test name pattern. Only tests with names that match this pattern will be executed.", | ||
| ) | ||
| .option("--test-dir <test_dir>", "Directory where tests can be found.") | ||
| .before(requireAuth) | ||
| .action(async (target: string, options: any) => { | ||
| const appName = getAppName(options); | ||
|
|
||
| const testDir = options.testDir || "tests"; | ||
| const tests = await parseTestFiles( | ||
| testDir, | ||
| undefined, | ||
| options.testFilePattern, | ||
| options.testNamePattern, | ||
| ); | ||
|
|
||
| if (!tests.length) { | ||
| throw new FirebaseError("No tests found"); | ||
| } | ||
|
|
||
| const invokeSpinner = ora("Requesting test execution"); | ||
|
|
||
| let testInvocations; | ||
| let releaseId; | ||
| try { | ||
| const client = new AppDistributionClient(); | ||
| releaseId = await upload(client, appName, new Distribution(target)); | ||
|
|
||
| invokeSpinner.start(); | ||
| testInvocations = await invokeMataTests(client, releaseId, tests); | ||
| invokeSpinner.text = "Test execution requested"; | ||
| invokeSpinner.succeed(); | ||
| } catch (ex) { | ||
| invokeSpinner.fail("Failed to request test execution"); | ||
| throw ex; | ||
| } | ||
|
|
||
| logger.info( | ||
| clc.bold(`\n${clc.white("===")} Running ${pluralizeTests(testInvocations.length)}`), | ||
| ); | ||
| logger.info(await marked(`View progress and results in the [Firebase Console]`)); | ||
| }); | ||
|
|
||
| function pluralizeTests(numTests: number) { | ||
| return `${numTests} test${numTests === 1 ? "" : "s"}`; | ||
| } | ||
|
|
||
| async function invokeMataTests( | ||
| client: AppDistributionClient, | ||
| releaseName: string, | ||
| testDefs: TestCaseInvocation[], | ||
| ) { | ||
| try { | ||
| const testInvocations: ReleaseTest[] = []; | ||
| for (const testDef of testDefs) { | ||
| const aiInstruction: AIInstruction = { | ||
| steps: testDef.testCase.instructions.steps, | ||
| }; | ||
| testInvocations.push( | ||
| await client.createReleaseTest(releaseName, defaultDevices, aiInstruction), | ||
| ); | ||
| } | ||
| return testInvocations; | ||
| } catch (err: unknown) { | ||
| throw new FirebaseError("Test invocation failed", { original: getError(err) }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you consider putting this under the app distribution namespace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. We went back and forth on that.