@@ -11,7 +11,7 @@ import { FirebaseError } from "../error";
11
11
import { marked } from "marked" ;
12
12
import { needProjectId } from "../projectUtils" ;
13
13
import { consoleUrl } from "../utils" ;
14
- import { AppPlatform , listFirebaseApps } from "../management/apps" ;
14
+ import { AppPlatform , listFirebaseApps , checkForApps } from "../management/apps" ;
15
15
16
16
export const command = new Command ( "apptesting:execute <target>" )
17
17
. description ( "Run automated tests written in natural language driven by AI" )
@@ -32,13 +32,28 @@ export const command = new Command("apptesting:execute <target>")
32
32
. before ( requireConfig )
33
33
. action ( async ( target : string , options : any ) => {
34
34
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
+ }
42
57
}
43
58
44
59
const testDir = options . config . src . apptesting ?. testDir || "tests" ;
0 commit comments