Skip to content

Commit 92d837e

Browse files
chore: create test matcher that can skip test suites with coverage (#1285)
1 parent b5e27d7 commit 92d837e

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

tests/specs/spa/harvesting.e2e.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { checkSpa } from '../../util/basic-checks'
22
import { testInteractionEventsRequest } from '../../../tools/testing-server/utils/expect-tests'
33
import { JSONPath } from 'jsonpath-plus'
44

5-
describe('spa harvesting', () => {
5+
describe.withoutCoverage()('spa harvesting', () => {
66
let interactionsCapture
77

88
beforeEach(async () => {

tools/wdio/plugins/browser-matcher.mjs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ import { getBrowserName, getBrowserVersion } from '../../browsers-lists/utils.mj
77
export 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) {

tools/wdio/plugins/testing-server/launcher.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ const log = logger('testing-server')
99
*/
1010
export default class TestingServerLauncher {
1111
#testingServer
12+
#collectCoverage
1213

1314
constructor (opts) {
1415
this.#testingServer = new TestServer({
1516
...opts,
1617
logger: log
1718
})
19+
this.#collectCoverage = opts.coverage
1820
}
1921

2022
async onPrepare (_, capabilities) {
@@ -25,9 +27,11 @@ export default class TestingServerLauncher {
2527
log.info(`Command server started on http://${this.#testingServer.commandServer.host}:${this.#testingServer.commandServer.port}`)
2628

2729
capabilities.forEach((capability) => {
30+
/** these props will be deleted later before sending to LT */
2831
capability.assetServer = serialize({ host: this.#testingServer.assetServer.host, port: this.#testingServer.assetServer.port })
2932
capability.bamServer = serialize({ host: this.#testingServer.bamServer.host, port: this.#testingServer.bamServer.port })
3033
capability.commandServer = serialize({ host: this.#testingServer.commandServer.host, port: this.#testingServer.commandServer.port })
34+
capability.collectCoverage = this.#collectCoverage
3135
})
3236
}
3337

0 commit comments

Comments
 (0)