Skip to content

Commit 0fc7a29

Browse files
Improve apptesting error logging (#9187)
1 parent a540fde commit 0fc7a29

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
- The `experimental:mcp` command has been renamed to `mcp`. The old name is now an alias.
22
- `firebase_update_environment` MCP tool supports accepting Gemini in Firebase Terms of Service.
33
- Fixed a bug when `firebase init dataconnect` failed to create a React app when launched from VS Code extension (#9171).
4+
- Improved the clarity of the `firebase apptesting:execute` command when you have zero or multiple apps.

src/commands/apptesting-execute.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { FirebaseError } from "../error";
1111
import { marked } from "marked";
1212
import { needProjectId } from "../projectUtils";
1313
import { consoleUrl } from "../utils";
14-
import { AppPlatform, listFirebaseApps } from "../management/apps";
14+
import { AppPlatform, listFirebaseApps, checkForApps } from "../management/apps";
1515

1616
export const command = new Command("apptesting:execute <target>")
1717
.description("Run automated tests written in natural language driven by AI")
@@ -32,13 +32,28 @@ export const command = new Command("apptesting:execute <target>")
3232
.before(requireConfig)
3333
.action(async (target: string, options: any) => {
3434
const projectId = needProjectId(options);
35-
const appList = await listFirebaseApps(projectId, AppPlatform.WEB);
36-
let app = appList.find((a) => a.appId === options.app);
37-
if (!app && appList.length === 1) {
38-
app = appList[0];
39-
logger.info(`No app specified, defaulting to ${app.appId}`);
40-
} else if (!app) {
41-
throw new FirebaseError("Invalid app id");
35+
const apps = await listFirebaseApps(projectId, AppPlatform.WEB);
36+
// Fail out early if there's no apps.
37+
checkForApps(apps, AppPlatform.WEB);
38+
39+
let app = apps.find((a) => a.appId === options.app);
40+
if (!app) {
41+
if (options.app) {
42+
// An app ID was provided, but it's invalid.
43+
throw new FirebaseError(
44+
`App with ID '${options.app}' was not found in project ${projectId}. You can list available apps with 'firebase apps:list'.`,
45+
);
46+
}
47+
// if there's only one app, we don't need to prompt interactively
48+
if (apps.length === 1) {
49+
// If there's only one, use it.
50+
app = apps[0];
51+
} else {
52+
// If there's > 1, fail
53+
throw new FirebaseError(
54+
`Project ${projectId} has multiple apps, must specify a web app id with '--app', you can list available apps with 'firebase apps:list'.`,
55+
);
56+
}
4257
}
4358

4459
const testDir = options.config.src.apptesting?.testDir || "tests";

src/management/apps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ export function checkForApps(apps: AppMetadata[], appPlatform: AppPlatform): voi
197197
if (!apps.length) {
198198
throw new FirebaseError(
199199
`There are no ${appPlatform === AppPlatform.ANY ? "" : appPlatform + " "}apps ` +
200-
"associated with this Firebase project",
200+
"associated with this Firebase project.\n" +
201+
"You can create an app for this project with 'firebase apps:create'",
201202
);
202203
}
203204
}

0 commit comments

Comments
 (0)