Skip to content

Commit 5701e8a

Browse files
chore: enhance skip reason filtering in unified runner
1 parent fe7c102 commit 5701e8a

File tree

1 file changed

+58
-3
lines changed

1 file changed

+58
-3
lines changed

test/tools/unified-spec-runner/runner.ts

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,50 @@ async function terminateOpenTransactions(client: MongoClient) {
3636
}
3737
}
3838

39+
export async function runUnifiedTest(
40+
ctx: Mocha.Context,
41+
unifiedSuite: uni.UnifiedSuite,
42+
test: uni.Test
43+
): Promise<void>;
44+
45+
/**
46+
* @deprecated use the overload that provides a function filter instead
47+
*/
3948
export async function runUnifiedTest(
4049
ctx: Mocha.Context,
4150
unifiedSuite: uni.UnifiedSuite,
4251
test: uni.Test,
4352
testsToSkip?: string[]
53+
): Promise<void>;
54+
55+
/**
56+
*
57+
* @param skipFilter - a function that returns true if the test should be skipped
58+
*/
59+
export async function runUnifiedTest(
60+
ctx: Mocha.Context,
61+
unifiedSuite: uni.UnifiedSuite,
62+
test: uni.Test,
63+
skipFilter?: (test: uni.Test) => boolean
64+
): Promise<void>;
65+
66+
export async function runUnifiedTest(
67+
ctx: Mocha.Context,
68+
unifiedSuite: uni.UnifiedSuite,
69+
test: uni.Test,
70+
testsToSkipOrFilter?: string[] | ((test: uni.Test) => boolean)
4471
): Promise<void> {
4572
// Some basic expectations we can catch early
4673
expect(test).to.exist;
4774
expect(unifiedSuite).to.exist;
4875
expect(ctx).to.exist;
4976
expect(ctx.configuration).to.exist;
5077

78+
if (Array.isArray(testsToSkipOrFilter)) {
79+
const testsToSkip = testsToSkipOrFilter;
80+
testsToSkipOrFilter = (test: uni.Test) => testsToSkip.includes(test.description);
81+
}
82+
5183
const schemaVersion = patchVersion(unifiedSuite.schemaVersion);
5284
expect(semverSatisfies(schemaVersion, uni.SupportedVersion)).to.be.true;
5385

@@ -58,7 +90,7 @@ export async function runUnifiedTest(
5890
ctx.skip();
5991
}
6092

61-
if (testsToSkip?.includes(test.description)) {
93+
if (testsToSkipOrFilter?.(test)) {
6294
ctx.skip();
6395
}
6496

@@ -236,12 +268,35 @@ export async function runUnifiedTest(
236268
}
237269
}
238270

239-
export function runUnifiedSuite(specTests: uni.UnifiedSuite[], testsToSkip?: string[]): void {
271+
export function runUnifiedSuite(specTests: uni.UnifiedSuite[]): void;
272+
273+
/**
274+
* @deprecated use the overload that provides a function filter instead
275+
*/
276+
export function runUnifiedSuite(specTests: uni.UnifiedSuite[], testsToSkip?: string[]): void;
277+
278+
/**
279+
*
280+
* @param skipFilter - a function that returns true if the test should be skipped
281+
*/
282+
export function runUnifiedSuite(
283+
specTests: uni.UnifiedSuite[],
284+
skipFilter?: (test: uni.Test) => boolean
285+
): void;
286+
287+
export function runUnifiedSuite(
288+
specTests: uni.UnifiedSuite[],
289+
testsToSkipOrFilter?: string[] | ((test: uni.Test) => boolean)
290+
): void {
240291
for (const unifiedSuite of specTests) {
241292
context(String(unifiedSuite.description), function () {
242293
for (const test of unifiedSuite.tests) {
243294
it(String(test.description), async function () {
244-
await runUnifiedTest(this, unifiedSuite, test, testsToSkip);
295+
if (Array.isArray(testsToSkipOrFilter)) {
296+
await runUnifiedTest(this, unifiedSuite, test, testsToSkipOrFilter);
297+
} else {
298+
await runUnifiedTest(this, unifiedSuite, test, testsToSkipOrFilter);
299+
}
245300
});
246301
}
247302
});

0 commit comments

Comments
 (0)