@@ -7,10 +7,15 @@ import { getBrowserName, getBrowserVersion } from '../../browsers-lists/utils.mj
77export default class BrowserMatcher {
88 #browserName
99 #browserVersion
10+ #collectCoverage
1011
1112 async beforeSession ( _ , capabilities ) {
1213 this . #browserName = getBrowserName ( capabilities )
1314 this . #browserVersion = getBrowserVersion ( capabilities )
15+
16+ this . #collectCoverage = capabilities . collectCoverage
17+ delete capabilities . collectCoverage
18+
1419 this . #setupMochaGlobals( )
1520 }
1621
@@ -50,6 +55,32 @@ export default class BrowserMatcher {
5055 return this . #wrapFnWithBrowserMatcher( matcher , originalGlobal )
5156 }
5257 } )
58+
59+ Object . defineProperty ( originalGlobal , 'withoutCoverage' , {
60+ value : ( ) => {
61+ return this . #wrapFnWithCoverageCheck( originalGlobal )
62+ }
63+ } )
64+ }
65+
66+ #wrapFnWithCoverageCheck ( originalGlobal ) {
67+ const skip = ! ! this . #collectCoverage
68+
69+ return function ( ...args ) {
70+ /*
71+ We only call global.it for tests that are not skipped.
72+ The test will skip if coverage flag is passed is on and the test is marked as 'withoutCoverage'. This registers the test
73+ with the mocha engine. When all tests in a file are skipped, WDIO will not launch
74+ a browser in LambdaTest.
75+
76+ Do not use global.it.skip. This still registers the test with mocha and will cause
77+ WDIO to launch a browser in LambdaTest. If all the tests are skipped in a file, this
78+ is a waste of time.
79+ */
80+ if ( ! skip ) {
81+ originalGlobal . apply ( this , args )
82+ }
83+ }
5384 }
5485
5586 #wrapFnWithBrowserMatcher ( matcher , originalGlobal ) {
0 commit comments