Skip to content

Commit 52aa4a1

Browse files
code cleanup
1 parent 2a1a704 commit 52aa4a1

File tree

12 files changed

+924
-784
lines changed

12 files changed

+924
-784
lines changed

src/cli.ts

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import MaestroOptions, {
2222
} from './models/maestro_options';
2323
import Maestro from './providers/maestro';
2424
import Login from './providers/login';
25+
import TestingBotError from './models/testingbot_error';
2526

2627
const program = new Command();
2728

@@ -137,9 +138,15 @@ const espressoCommand = program
137138
)
138139
// CI/CD metadata
139140
.option('--commit-sha <sha>', 'The commit SHA of this upload.')
140-
.option('--pull-request-id <id>', 'The ID of the pull request this upload originated from.')
141+
.option(
142+
'--pull-request-id <id>',
143+
'The ID of the pull request this upload originated from.',
144+
)
141145
.option('--repo-name <name>', 'Repository name (e.g., GitHub repo slug).')
142-
.option('--repo-owner <owner>', 'Repository owner (e.g., GitHub organization or user slug).')
146+
.option(
147+
'--repo-owner <owner>',
148+
'Repository owner (e.g., GitHub organization or user slug).',
149+
)
143150
// Authentication
144151
.option('--api-key <key>', 'TestingBot API key.')
145152
.option('--api-secret <secret>', 'TestingBot API secret.')
@@ -155,14 +162,14 @@ const espressoCommand = program
155162
}
156163

157164
const metadata =
158-
args.commitSha || args.pullRequestId || args.repoName || args.repoOwner
159-
? {
160-
commitSha: args.commitSha,
161-
pullRequestId: args.pullRequestId,
162-
repoName: args.repoName,
163-
repoOwner: args.repoOwner,
164-
}
165-
: undefined;
165+
args.commitSha || args.pullRequestId || args.repoName || args.repoOwner
166+
? {
167+
commitSha: args.commitSha,
168+
pullRequestId: args.pullRequestId,
169+
repoName: args.repoName,
170+
repoOwner: args.repoOwner,
171+
}
172+
: undefined;
166173

167174
const options = new EspressoOptions(app, testApp, args.device, {
168175
version: args.platformVersion,
@@ -195,7 +202,7 @@ const espressoCommand = program
195202
apiSecret: args.apiSecret,
196203
});
197204
if (credentials === null) {
198-
throw new Error(
205+
throw new TestingBotError(
199206
'No TestingBot credentials found. Please authenticate using one of these methods:\n' +
200207
' 1. Run "testingbot login" to authenticate via browser (recommended)\n' +
201208
' 2. Use --api-key and --api-secret options\n' +
@@ -333,9 +340,15 @@ const maestroCommand = program
333340
)
334341
// CI/CD metadata
335342
.option('--commit-sha <sha>', 'The commit SHA of this upload.')
336-
.option('--pull-request-id <id>', 'The ID of the pull request this upload originated from.')
343+
.option(
344+
'--pull-request-id <id>',
345+
'The ID of the pull request this upload originated from.',
346+
)
337347
.option('--repo-name <name>', 'Repository name (e.g., GitHub repo slug).')
338-
.option('--repo-owner <owner>', 'Repository owner (e.g., GitHub organization or user slug).')
348+
.option(
349+
'--repo-owner <owner>',
350+
'Repository owner (e.g., GitHub organization or user slug).',
351+
)
339352
// Authentication
340353
.option('--api-key <key>', 'TestingBot API key.')
341354
.option('--api-secret <secret>', 'TestingBot API secret.')
@@ -373,14 +386,14 @@ const maestroCommand = program
373386
}
374387

375388
const metadata =
376-
args.commitSha || args.pullRequestId || args.repoName || args.repoOwner
377-
? {
378-
commitSha: args.commitSha,
379-
pullRequestId: args.pullRequestId,
380-
repoName: args.repoName,
381-
repoOwner: args.repoOwner,
382-
}
383-
: undefined;
389+
args.commitSha || args.pullRequestId || args.repoName || args.repoOwner
390+
? {
391+
commitSha: args.commitSha,
392+
pullRequestId: args.pullRequestId,
393+
repoName: args.repoName,
394+
repoOwner: args.repoOwner,
395+
}
396+
: undefined;
384397

385398
const options = new MaestroOptions(app, flows, args.device, {
386399
includeTags: args.includeTags,
@@ -414,7 +427,7 @@ const maestroCommand = program
414427
apiSecret: args.apiSecret,
415428
});
416429
if (credentials === null) {
417-
throw new Error(
430+
throw new TestingBotError(
418431
'No TestingBot credentials found. Please authenticate using one of these methods:\n' +
419432
' 1. Run "testingbot login" to authenticate via browser (recommended)\n' +
420433
' 2. Use --api-key and --api-secret options\n' +
@@ -500,9 +513,15 @@ const xcuitestCommand = program
500513
)
501514
// CI/CD metadata
502515
.option('--commit-sha <sha>', 'The commit SHA of this upload.')
503-
.option('--pull-request-id <id>', 'The ID of the pull request this upload originated from.')
516+
.option(
517+
'--pull-request-id <id>',
518+
'The ID of the pull request this upload originated from.',
519+
)
504520
.option('--repo-name <name>', 'Repository name (e.g., GitHub repo slug).')
505-
.option('--repo-owner <owner>', 'Repository owner (e.g., GitHub organization or user slug).')
521+
.option(
522+
'--repo-owner <owner>',
523+
'Repository owner (e.g., GitHub organization or user slug).',
524+
)
506525
// Authentication
507526
.option('--api-key <key>', 'TestingBot API key.')
508527
.option('--api-secret <secret>', 'TestingBot API secret.')
@@ -518,14 +537,14 @@ const xcuitestCommand = program
518537
}
519538

520539
const metadata =
521-
args.commitSha || args.pullRequestId || args.repoName || args.repoOwner
522-
? {
523-
commitSha: args.commitSha,
524-
pullRequestId: args.pullRequestId,
525-
repoName: args.repoName,
526-
repoOwner: args.repoOwner,
527-
}
528-
: undefined;
540+
args.commitSha || args.pullRequestId || args.repoName || args.repoOwner
541+
? {
542+
commitSha: args.commitSha,
543+
pullRequestId: args.pullRequestId,
544+
repoName: args.repoName,
545+
repoOwner: args.repoOwner,
546+
}
547+
: undefined;
529548

530549
const options = new XCUITestOptions(app, testApp, args.device, {
531550
version: args.platformVersion,
@@ -551,7 +570,7 @@ const xcuitestCommand = program
551570
apiSecret: args.apiSecret,
552571
});
553572
if (credentials === null) {
554-
throw new Error(
573+
throw new TestingBotError(
555574
'No TestingBot credentials found. Please authenticate using one of these methods:\n' +
556575
' 1. Run "testingbot login" to authenticate via browser (recommended)\n' +
557576
' 2. Use --api-key and --api-secret options\n' +

src/models/espresso_options.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import TestingBotError from './testingbot_error';
2+
13
export type TestSize = 'small' | 'medium' | 'large';
24
export type ReportFormat = 'html' | 'junit';
35
export type ThrottleNetwork = '4G' | '3G' | 'Edge' | 'airplane';
@@ -119,6 +121,14 @@ export default class EspressoOptions {
119121
this._realDevice = options?.realDevice ?? false;
120122
this._tabletOnly = options?.tabletOnly ?? false;
121123
this._phoneOnly = options?.phoneOnly ?? false;
124+
125+
// Validate contradictory options
126+
if (this._tabletOnly && this._phoneOnly) {
127+
throw new TestingBotError(
128+
'Cannot specify both --phone-only and --tablet-only options',
129+
);
130+
}
131+
122132
this._name = options?.name;
123133
this._build = options?.build;
124134
this._testRunner = options?.testRunner;

src/models/xcuitest_options.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import TestingBotError from './testingbot_error';
2+
13
export type Orientation = 'PORTRAIT' | 'LANDSCAPE';
24
export type ReportFormat = 'html' | 'junit';
35
export type ThrottleNetwork = '4G' | '3G' | 'Edge' | 'airplane';
@@ -99,6 +101,14 @@ export default class XCUITestOptions {
99101
this._realDevice = options?.realDevice ?? false;
100102
this._tabletOnly = options?.tabletOnly ?? false;
101103
this._phoneOnly = options?.phoneOnly ?? false;
104+
105+
// Validate contradictory options
106+
if (this._tabletOnly && this._phoneOnly) {
107+
throw new TestingBotError(
108+
'Cannot specify both --phone-only and --tablet-only options',
109+
);
110+
}
111+
102112
this._name = options?.name;
103113
this._build = options?.build;
104114
this._orientation = options?.orientation;

0 commit comments

Comments
 (0)