( ctx: Mocha.Context, unifiedSuite: uni.UnifiedSuite, test: uni.Test, skipFilter: uni.TestFilter = () => false )
| 53 | * or a skip reason if the test should be skipped |
| 54 | */ |
| 55 | async function runUnifiedTest( |
| 56 | ctx: Mocha.Context, |
| 57 | unifiedSuite: uni.UnifiedSuite, |
| 58 | test: uni.Test, |
| 59 | skipFilter: uni.TestFilter = () => false |
| 60 | ): Promise<void> { |
| 61 | class="cm">// Some basic expectations we can catch early |
| 62 | expect(test).to.exist; |
| 63 | expect(unifiedSuite).to.exist; |
| 64 | expect(ctx).to.exist; |
| 65 | expect(ctx.configuration).to.exist; |
| 66 | |
| 67 | expect(ctx.test, class="st">'encountered a unified test where the test is undefined').to.exist; |
| 68 | expect(ctx.currentTest, class="st">'`runUnifiedTest` can only be used inside of it blocks').to.be.undefined; |
| 69 | |
| 70 | const schemaVersion = patchVersion(unifiedSuite.schemaVersion); |
| 71 | expect(semverSatisfies(schemaVersion, uni.SupportedVersion)).to.be.true; |
| 72 | |
| 73 | const skipReason = test.skipReason ?? skipFilter(test, ctx.configuration); |
| 74 | |
| 75 | if (typeof skipReason === class="st">'string') { |
| 76 | if (skipReason.length === 0) { |
| 77 | expect.fail(`Test was skipped with an empty skip reason: ${test.description}`); |
| 78 | } |
| 79 | |
| 80 | ctx.test!.skipReason = skipReason; |
| 81 | |
| 82 | ctx.skip(); |
| 83 | } |
| 84 | |
| 85 | let utilClient: MongoClient; |
| 86 | if (ctx.configuration.isLoadBalanced) { |
| 87 | class="cm">// The util client can always point at the single mongos LB frontend. |
| 88 | utilClient = ctx.configuration.newClient(ctx.configuration.singleMongosLoadBalancerUri); |
| 89 | } else if (process.env.UTIL_CLIENT_USER && process.env.UTIL_CLIENT_PASSWORD) { |
| 90 | class="cm">// For OIDC tests the MONGODB_URI is the base admin URI that the util client will use. |
| 91 | utilClient = ctx.configuration.newClient(process.env.MONGODB_URI, { |
| 92 | auth: { |
| 93 | username: process.env.UTIL_CLIENT_USER, |
| 94 | password: process.env.UTIL_CLIENT_PASSWORD |
| 95 | } |
| 96 | }); |
| 97 | } else { |
| 98 | utilClient = ctx.configuration.newClient(); |
| 99 | } |
| 100 | |
| 101 | let entities: EntitiesMap | undefined; |
| 102 | try { |
| 103 | trace(class="st">'\n starting test:'); |
| 104 | try { |
| 105 | await utilClient.connect(); |
| 106 | } catch (error) { |
| 107 | console.error( |
| 108 | ejson`failed to connect utilClient ${utilClient.s.url} - ${utilClient.options}` |
| 109 | ); |
| 110 | throw error; |
| 111 | } |
| 112 |
no test coverage detected