@@ -58,6 +58,9 @@ export default class Trigger extends AuthCommand {
58
58
description : 'Always show the full logs of the checks.' ,
59
59
allowNo : true ,
60
60
} ) ,
61
+ 'fail-on-no-matching' : Flags . boolean ( {
62
+ description : 'Exit with a failing status code when there are no matching tests.' ,
63
+ } ) ,
61
64
reporter : Flags . string ( {
62
65
char : 'r' ,
63
66
description : 'A list of custom reporters for the test output.' ,
@@ -96,6 +99,7 @@ export default class Trigger extends AuthCommand {
96
99
tags : targetTags ,
97
100
timeout,
98
101
verbose : verboseFlag ,
102
+ 'fail-on-no-matching' : failOnNoMatchingFlag ,
99
103
record : shouldRecord ,
100
104
reporter : reporterFlag ,
101
105
env,
@@ -116,6 +120,7 @@ export default class Trigger extends AuthCommand {
116
120
privateRunLocation,
117
121
} )
118
122
const verbose = this . prepareVerboseFlag ( verboseFlag , checklyConfig ?. cli ?. verbose )
123
+ const failOnNoMatching = this . prepareFailOnNoMatching ( failOnNoMatchingFlag , checklyConfig ?. cli ?. failOnNoMatching )
119
124
const reporterTypes = this . prepareReportersTypes ( reporterFlag as ReporterType , checklyConfig ?. cli ?. reporters )
120
125
const reporters = createReporters ( reporterTypes , location , verbose )
121
126
const testRetryStrategy = this . prepareTestRetryStrategy ( retries , checklyConfig ?. cli ?. retries )
@@ -167,6 +172,9 @@ export default class Trigger extends AuthCommand {
167
172
if ( err instanceof NoMatchingChecksError ) {
168
173
// For consistency with `checkly test`, we log a message and exit with code 0.
169
174
this . log ( 'No matching checks were found.' )
175
+ if ( failOnNoMatching ) {
176
+ process . exitCode = 1
177
+ }
170
178
return
171
179
}
172
180
reporters . forEach ( r => r . onError ( err ) )
@@ -221,6 +229,10 @@ export default class Trigger extends AuthCommand {
221
229
return verboseFlag ?? cliVerboseFlag ?? false
222
230
}
223
231
232
+ prepareFailOnNoMatching ( failOnNoMatchingFlag ?: boolean , cliFailOnNoMatchingFlag ?: boolean ) {
233
+ return failOnNoMatchingFlag ?? cliFailOnNoMatchingFlag ?? false
234
+ }
235
+
224
236
prepareReportersTypes ( reporterFlag : ReporterType , cliReporters : ReporterType [ ] = [ ] ) : ReporterType [ ] {
225
237
if ( ! reporterFlag && ! cliReporters . length ) {
226
238
return [ isCI ? 'ci' : 'list' ]
0 commit comments