Skip to content

Commit 60b1b2f

Browse files
chore: enhance skip function to return the skip reason
1 parent 5701e8a commit 60b1b2f

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ export async function runUnifiedTest(
6060
ctx: Mocha.Context,
6161
unifiedSuite: uni.UnifiedSuite,
6262
test: uni.Test,
63-
skipFilter?: (test: uni.Test) => boolean
63+
skipFilter?: uni.TestFilter
6464
): Promise<void>;
6565

6666
export async function runUnifiedTest(
6767
ctx: Mocha.Context,
6868
unifiedSuite: uni.UnifiedSuite,
6969
test: uni.Test,
70-
testsToSkipOrFilter?: string[] | ((test: uni.Test) => boolean)
70+
testsToSkipOrFilter?: string[] | uni.TestFilter
7171
): Promise<void> {
7272
// Some basic expectations we can catch early
7373
expect(test).to.exist;
@@ -77,7 +77,8 @@ export async function runUnifiedTest(
7777

7878
if (Array.isArray(testsToSkipOrFilter)) {
7979
const testsToSkip = testsToSkipOrFilter;
80-
testsToSkipOrFilter = (test: uni.Test) => testsToSkip.includes(test.description);
80+
testsToSkipOrFilter = ({ description }) =>
81+
testsToSkip.includes(description) ? 'Test was filtered without a skip reason' : null;
8182
}
8283

8384
const schemaVersion = patchVersion(unifiedSuite.schemaVersion);
@@ -90,6 +91,16 @@ export async function runUnifiedTest(
9091
ctx.skip();
9192
}
9293

94+
const skipReason = testsToSkipOrFilter?.(test);
95+
96+
if (typeof skipReason === 'string') {
97+
if (skipReason.length === 0) {
98+
expect.fail(`Test was skipped with an empty skip reason: ${test.description}`);
99+
}
100+
ctx.skipReason = skipReason;
101+
ctx.skip();
102+
}
103+
93104
if (testsToSkipOrFilter?.(test)) {
94105
ctx.skip();
95106
}
@@ -279,14 +290,11 @@ export function runUnifiedSuite(specTests: uni.UnifiedSuite[], testsToSkip?: str
279290
*
280291
* @param skipFilter - a function that returns true if the test should be skipped
281292
*/
282-
export function runUnifiedSuite(
283-
specTests: uni.UnifiedSuite[],
284-
skipFilter?: (test: uni.Test) => boolean
285-
): void;
293+
export function runUnifiedSuite(specTests: uni.UnifiedSuite[], skipFilter?: uni.TestFilter): void;
286294

287295
export function runUnifiedSuite(
288296
specTests: uni.UnifiedSuite[],
289-
testsToSkipOrFilter?: string[] | ((test: uni.Test) => boolean)
297+
testsToSkipOrFilter?: string[] | uni.TestFilter
290298
): void {
291299
for (const unifiedSuite of specTests) {
292300
context(String(unifiedSuite.description), function () {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,8 @@ export interface ExpectedError {
236236
errorLabelsOmit?: string[];
237237
expectResult?: unknown;
238238
}
239+
240+
/**
241+
* A type that represents the test filter provided to the unifed runner.
242+
*/
243+
export type TestFilter = (test: Test) => null | string;

0 commit comments

Comments
 (0)