@@ -33,7 +33,7 @@ const matchesUrlPart = normalizedName => {
3333/**
3434 * Skips the current test based on the browser, platform or url.
3535 */
36- export const skipOn = name => {
36+ export const skipOn = ( name , cb ) => {
3737 if ( ! _ . isString ( name ) || '' ) {
3838 throw new Error (
3939 'Invalid syntax: cy.skipOn(<name>), for example cy.skipOn("linux")'
@@ -46,31 +46,52 @@ export const skipOn = name => {
4646 }
4747
4848 const normalizedName = normalizeName ( name )
49- cy . log ( `skipOn **${ normalizedName } **` )
5049
51- if ( isPlatform ( normalizedName ) ) {
52- if ( Cypress . platform === normalizedName ) {
53- skip ( )
50+ if ( cb ) {
51+ if ( isPlatform ( normalizedName ) ) {
52+ if ( Cypress . platform !== normalizedName ) {
53+ return cb ( )
54+ }
55+ return
5456 }
55- return
56- }
5757
58- if ( isBrowser ( normalizedName ) ) {
59- if ( Cypress . browser . name === normalizedName ) {
60- skip ( )
58+ if ( isBrowser ( normalizedName ) ) {
59+ if ( Cypress . browser . name !== normalizedName ) {
60+ return cb ( )
61+ }
62+ return
63+ }
64+
65+ if ( ! matchesUrlPart ( normalizedName ) ) {
66+ return cb ( )
67+ }
68+ } else {
69+ cy . log ( `skipOn **${ normalizedName } **` )
70+
71+ if ( isPlatform ( normalizedName ) ) {
72+ if ( Cypress . platform === normalizedName ) {
73+ skip ( )
74+ }
75+ return
76+ }
77+
78+ if ( isBrowser ( normalizedName ) ) {
79+ if ( Cypress . browser . name === normalizedName ) {
80+ skip ( )
81+ }
82+ return
6183 }
62- return
63- }
6484
65- if ( matchesUrlPart ( normalizedName ) ) {
66- return skip ( )
85+ if ( matchesUrlPart ( normalizedName ) ) {
86+ return skip ( )
87+ }
6788 }
6889}
6990
7091/**
7192 * Runs the current test only in the specified browser, platform or against url.
7293 */
73- export const onlyOn = name => {
94+ export const onlyOn = ( name , cb ) => {
7495 if ( ! _ . isString ( name ) || '' ) {
7596 throw new Error (
7697 'Invalid syntax: cy.onlyOn(<name>), for example cy.onlyOn("linux")'
@@ -79,24 +100,38 @@ export const onlyOn = name => {
79100
80101 const normalizedName = normalizeName ( name )
81102
82- cy . log ( `onlyOn **${ normalizedName } **` )
103+ if ( cb ) {
104+ if ( isPlatform ( normalizedName ) && Cypress . platform === normalizedName ) {
105+ return cb ( )
106+ }
83107
84- if ( isPlatform ( normalizedName ) ) {
85- if ( Cypress . platform !== normalizedName ) {
86- skip ( )
108+ if ( isBrowser ( normalizedName ) && Cypress . browser . name === normalizedName ) {
109+ return cb ( )
87110 }
88- return
89- }
90111
91- if ( isBrowser ( normalizedName ) ) {
92- if ( Cypress . browser . name !== normalizedName ) {
93- skip ( )
112+ if ( matchesUrlPart ( normalizedName ) ) {
113+ return cb ( )
114+ }
115+ } else {
116+ cy . log ( `onlyOn **${ normalizedName } **` )
117+
118+ if ( isPlatform ( normalizedName ) ) {
119+ if ( Cypress . platform !== normalizedName ) {
120+ skip ( )
121+ }
122+ return
94123 }
95- return
96- }
97124
98- if ( ! matchesUrlPart ( normalizedName ) ) {
99- return skip ( )
125+ if ( isBrowser ( normalizedName ) ) {
126+ if ( Cypress . browser . name !== normalizedName ) {
127+ skip ( )
128+ }
129+ return
130+ }
131+
132+ if ( ! matchesUrlPart ( normalizedName ) ) {
133+ return skip ( )
134+ }
100135 }
101136}
102137
0 commit comments