@@ -80,6 +80,8 @@ const isBrowser = (name) => ['electron', 'chrome', 'firefox'].includes(name)
8080const isHeadedName = ( name ) => [ 'headed' , 'headless' ] . includes ( name )
8181const isEnvironmentSet = ( ) =>
8282 typeof Cypress . env ( 'ENVIRONMENT' ) === 'string' && Cypress . env ( 'ENVIRONMENT' )
83+ const isAsyncFn = ( name ) =>
84+ Object . prototype . toString . call ( name ) === '[object AsyncFunction]'
8385
8486const headedMatches = ( name ) => {
8587 if ( name === 'headed' ) {
@@ -129,12 +131,22 @@ const skipOnBool = (flag, cb) => {
129131
130132/**
131133 * Skips the current test based on the browser, platform or url.
134+ * @param {string|boolean|Function } name - condition, could be platform, browser name, url or true|false.
135+ * @param {() => void } cb - Optional, run the given callback if the condition passes
132136 */
133137const skipOn = ( name , cb ) => {
134138 if ( _ . isBoolean ( name ) ) {
135139 return skipOnBool ( name , cb )
136140 }
137141
142+ if ( isAsyncFn ( name ) ) {
143+ return name ( ) . then ( ( result ) => onlyOnBool ( result , cb ) )
144+ }
145+
146+ if ( _ . isFunction ( name ) ) {
147+ return onlyOnBool ( name ( ) , cb )
148+ }
149+
138150 if ( ! _ . isString ( name ) || '' ) {
139151 throw new Error (
140152 'Invalid syntax: cy.skipOn(<name>), for example cy.skipOn("linux")'
@@ -226,7 +238,7 @@ const onlyOnBool = (flag, cb) => {
226238
227239/**
228240 * Runs the current test only in the specified browser, platform or against url.
229- * @param {string|boolean } name - condition, could be platform, browser name, url or true|false.
241+ * @param {string|boolean|Function } name - condition, could be platform, browser name, url or true|false.
230242 * @param {() => void } cb - Optional, run the given callback if the condition passes
231243 */
232244const onlyOn = ( name , cb ) => {
@@ -240,6 +252,14 @@ const onlyOn = (name, cb) => {
240252 )
241253 }
242254
255+ if ( isAsyncFn ( name ) ) {
256+ return name ( ) . then ( ( result ) => onlyOnBool ( result , cb ) )
257+ }
258+
259+ if ( _ . isFunction ( name ) ) {
260+ return onlyOnBool ( name ( ) , cb )
261+ }
262+
243263 if ( cb ) {
244264 if ( isOn ( name ) ) {
245265 return cb ( )
0 commit comments