aboutsummaryrefslogtreecommitdiffstats
path: root/packages/test-utils/src/testIf.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/test-utils/src/testIf.ts')
-rw-r--r--packages/test-utils/src/testIf.ts70
1 files changed, 70 insertions, 0 deletions
diff --git a/packages/test-utils/src/testIf.ts b/packages/test-utils/src/testIf.ts
new file mode 100644
index 0000000..2309ddc
--- /dev/null
+++ b/packages/test-utils/src/testIf.ts
@@ -0,0 +1,70 @@
1/*
2 * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com>
3 *
4 * This file is part of Sophie.
5 *
6 * Sophie is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: AGPL-3.0-only
19 */
20
21import { test } from '@jest/globals';
22import type { Global } from '@jest/types';
23
24export interface TestIfConcurrent {
25 (condition: boolean): Global.ItConcurrentBase;
26
27 only(condition: boolean): Global.ItConcurrentBase;
28
29 skip(condition: boolean): Global.ItConcurrentBase;
30}
31
32export interface TestIf {
33 (condition: boolean): Global.ItBase;
34
35 only(condition: boolean): Global.ItBase;
36
37 skip(condition: boolean): Global.ItBase;
38
39 concurrent: TestIfConcurrent;
40}
41
42const testIfConcurrent: TestIfConcurrent = function concurrent(
43 condition: boolean,
44) {
45 return condition ? test.concurrent : test.concurrent.skip;
46};
47
48testIfConcurrent.only = function only() {
49 return test.concurrent.only;
50};
51
52testIfConcurrent.skip = function skip() {
53 return test.concurrent.skip;
54};
55
56const testIf: TestIf = function testIf(condition: boolean) {
57 return condition ? test : test.skip;
58};
59
60testIf.only = function only() {
61 return test.only;
62};
63
64testIf.skip = function skip() {
65 return test.skip;
66};
67
68testIf.concurrent = testIfConcurrent;
69
70export default testIf;