Skip to content

Commit 663dd91

Browse files
vincentriemerfacebook-github-bot
authored andcommitted
Add the ability for tests to be marked as 'skipped'
Summary: Changelog: [RNTester][Internal] - Add the ability for platform tests to be marked as skipped There are some properties/tests in the web platform tests that we don't want to especially priorities (especially if they aren't especially relevant to the specification and just legacy browser compat) so this adds the ability for us to mark these tests as skipped. This is so that we can ensure that our platform tests are "complete" while decreasing the noise and distraction from failing tests that don't really apply to RN. Reviewed By: lunaleaps Differential Revision: D37889470 fbshipit-source-id: 6516ac90c242d662518a95cb9ba8ce643f6bb09c
1 parent 966f800 commit 663dd91

File tree

7 files changed

+184
-70
lines changed

7 files changed

+184
-70
lines changed

packages/rn-tester/js/examples/Experimental/PlatformTest/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function ExampleTestCase ({ harness }) { /* ... */ }
2424

2525
As of writting this README there are 2 different types of tests that the `harness` prop provides:
2626

27-
### `test(testcase: (TestContext) => void, testName: string)`
27+
### `test(testcase: (TestContext) => void, testName: string, options?: TestOptions)`
2828

2929
This is a method to create "regular" test reminicent of other frameworks such as Jest. These are meant to be run imperatively, and while that means that they technically could work in a `useEffect` hook as a way to run the test "on mount" — it is instead recommended to try and keep these tests in callbacks instead. A good alternative to running the test on mount would be to instead put the test in a callback and render a "Start Test" button which executes the callback.
3030

@@ -35,6 +35,10 @@ The first argument is the closure in which you will run your test and make asser
3535
* `assert_greater_than_equal(a: number, b: number, description: string): void`
3636
* `assert_less_than_equal(a: number, b: number, description: string): void`
3737

38+
An optional third argument can be used for specifying additional options to the test — that object currently has the following properties (all of which are optional themselves):
39+
40+
* `skip: boolean`: In cases where we want the test to be registered but we don't want it to contribute to the pass/fail count.
41+
3842
Here's what a basic/contrived example which verifies the layout of a basic view:
3943

4044
```js

packages/rn-tester/js/examples/Experimental/PlatformTest/RNTesterPlatformTestMinimizedResultView.js

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';
1212

13+
import RNTesterPlatformTestResultsText from './RNTesterPlatformTestResultsText';
14+
1315
import * as React from 'react';
1416
import {View, Text, StyleSheet, TouchableHighlight} from 'react-native';
1517

@@ -18,6 +20,7 @@ type Props = $ReadOnly<{|
1820
numError: number,
1921
numPass: number,
2022
numPending: number,
23+
numSkipped: number,
2124
onPress?: () => void,
2225
style?: ?ViewStyleProp,
2326
|}>;
@@ -26,26 +29,22 @@ export default function RNTesterPlatformTestMinimizedResultView({
2629
numError,
2730
numPass,
2831
numPending,
32+
numSkipped,
2933
onPress,
3034
style,
3135
}: Props): React.MixedElement {
3236
return (
3337
<TouchableHighlight onPress={onPress} style={[styles.root, style]}>
3438
<View style={styles.innerContainer}>
35-
<View style={styles.statsContainer}>
36-
<Text style={styles.summaryText}>
37-
{numPass} <Text style={styles.passText}>Pass</Text>
38-
</Text>
39-
<Text style={styles.summaryText}>
40-
{numFail} <Text style={styles.failText}>Fail</Text>
41-
</Text>
42-
<Text style={styles.summaryText}>
43-
{numError} <Text style={styles.errorText}>Error</Text>
44-
</Text>
45-
<Text style={styles.summaryText}>
46-
{numPending} <Text style={styles.pendingText}>Pending</Text>
47-
</Text>
48-
</View>
39+
<Text style={styles.statsContainer}>
40+
<RNTesterPlatformTestResultsText
41+
numError={numError}
42+
numFail={numFail}
43+
numPass={numPass}
44+
numPending={numPending}
45+
numSkipped={numSkipped}
46+
/>
47+
</Text>
4948
<Text style={styles.caret}></Text>
5049
</View>
5150
</TouchableHighlight>
@@ -59,12 +58,6 @@ const styles = StyleSheet.create({
5958
marginEnd: 8,
6059
opacity: 0.5,
6160
},
62-
errorText: {
63-
color: 'orange',
64-
},
65-
failText: {
66-
color: 'red',
67-
},
6861
innerContainer: {
6962
width: '100%',
7063
height: '100%',
@@ -74,12 +67,6 @@ const styles = StyleSheet.create({
7467
paddingHorizontal: 8,
7568
backgroundColor: 'white',
7669
},
77-
passText: {
78-
color: 'green',
79-
},
80-
pendingText: {
81-
color: 'gray',
82-
},
8370
root: {
8471
borderTopColor: 'rgb(171, 171, 171)',
8572
borderTopWidth: StyleSheet.hairlineWidth,
@@ -89,8 +76,6 @@ const styles = StyleSheet.create({
8976
flexDirection: 'row',
9077
alignItems: 'center',
9178
justifyContent: 'flex-start',
92-
},
93-
summaryText: {
9479
marginStart: 8,
9580
},
9681
});

packages/rn-tester/js/examples/Experimental/PlatformTest/RNTesterPlatformTestResultView.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
} from './RNTesterPlatformTestTypes';
2020

2121
import RNTesterPlatformTestMinimizedResultView from './RNTesterPlatformTestMinimizedResultView';
22+
import RNTesterPlatformTestResultsText from './RNTesterPlatformTestResultsText';
2223

2324
import * as React from 'react';
2425
import {useMemo, useState, useCallback} from 'react';
@@ -40,6 +41,7 @@ const DISPLAY_STATUS_MAPPING: {[PlatformTestResultStatus]: string} = {
4041
PASS: 'Pass',
4142
FAIL: 'Fail',
4243
ERROR: 'Error',
44+
SKIPPED: 'Skipped',
4345
};
4446

4547
type FilterModalProps = $ReadOnly<{
@@ -183,7 +185,7 @@ export default function RNTesterPlatformTestResultView(
183185
);
184186
}, [filterText, results]);
185187

186-
const {numPass, numFail, numError} = useMemo(
188+
const {numPass, numFail, numError, numSkipped} = useMemo(
187189
() =>
188190
filteredResults.reduce(
189191
(acc, result) => {
@@ -194,12 +196,15 @@ export default function RNTesterPlatformTestResultView(
194196
return {...acc, numFail: acc.numFail + 1};
195197
case 'ERROR':
196198
return {...acc, numError: acc.numError + 1};
199+
case 'SKIPPED':
200+
return {...acc, numSkipped: acc.numSkipped + 1};
197201
}
198202
},
199203
{
200204
numPass: 0,
201205
numFail: 0,
202206
numError: 0,
207+
numSkipped: 0,
203208
},
204209
),
205210
[filteredResults],
@@ -228,6 +233,7 @@ export default function RNTesterPlatformTestResultView(
228233
numError={numError}
229234
numPass={numPass}
230235
numPending={numPending}
236+
numSkipped={numSkipped}
231237
onPress={handleMinimizedPress}
232238
style={style}
233239
/>
@@ -250,26 +256,13 @@ export default function RNTesterPlatformTestResultView(
250256
</Text>
251257
) : null}
252258
<Text style={styles.summaryContainer}>
253-
<Text>
254-
{numPass} <Text style={styles.passText}>Pass</Text>
255-
</Text>
256-
{' '}
257-
<Text>
258-
{numFail} <Text style={styles.failText}>Fail</Text>
259-
</Text>
260-
{' '}
261-
<Text>
262-
{numError} <Text style={styles.errorText}>Error</Text>
263-
</Text>
264-
{numPending > 0 ? (
265-
<>
266-
{' '}
267-
<Text>
268-
{numPending}{' '}
269-
<Text style={styles.pendingText}>Pending</Text>
270-
</Text>
271-
</>
272-
) : null}
259+
<RNTesterPlatformTestResultsText
260+
numError={numError}
261+
numFail={numFail}
262+
numPass={numPass}
263+
numPending={numPending}
264+
numSkipped={numSkipped}
265+
/>
273266
</Text>
274267
</View>
275268
<View style={styles.actionsContainer}>
@@ -399,6 +392,9 @@ const styles = StyleSheet.create({
399392
paddingTop: 8,
400393
flex: 0,
401394
},
395+
skippedText: {
396+
color: 'blue',
397+
},
402398
table: {
403399
flex: 1,
404400
},
@@ -446,4 +442,5 @@ const STATUS_TEXT_STYLE_MAPPING: {[PlatformTestResultStatus]: TextStyle} = {
446442
PASS: styles.passText,
447443
FAIL: styles.failText,
448444
ERROR: styles.errorText,
445+
SKIPPED: styles.skippedText,
449446
};
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @flow
9+
*/
10+
11+
import {Text, StyleSheet} from 'react-native';
12+
import * as React from 'react';
13+
14+
type Props = $ReadOnly<{
15+
numPass: number,
16+
numFail: number,
17+
numError: number,
18+
numPending: number,
19+
numSkipped: number,
20+
}>;
21+
export default function RNTesterPlatformTestResultsText(
22+
props: Props,
23+
): React.MixedElement {
24+
const {numPass, numFail, numError, numPending, numSkipped} = props;
25+
return (
26+
<>
27+
<Text>
28+
{numPass} <Text style={styles.passText}>Pass</Text>
29+
</Text>
30+
{' '}
31+
<Text>
32+
{numFail} <Text style={styles.failText}>Fail</Text>
33+
</Text>
34+
{numSkipped > 0 ? (
35+
<>
36+
{' '}
37+
<Text>
38+
{numSkipped} <Text style={styles.skippedText}>Skipped</Text>
39+
</Text>
40+
</>
41+
) : null}
42+
{numError > 0 ? (
43+
<>
44+
{' '}
45+
<Text>
46+
{numError} <Text style={styles.errorText}>Error</Text>
47+
</Text>
48+
</>
49+
) : null}
50+
{numPending > 0 ? (
51+
<>
52+
{' '}
53+
<Text>
54+
{numPending} <Text style={styles.pendingText}>Pending</Text>
55+
</Text>
56+
</>
57+
) : null}
58+
</>
59+
);
60+
}
61+
62+
const styles = StyleSheet.create({
63+
errorText: {
64+
color: 'orange',
65+
},
66+
failText: {
67+
color: 'red',
68+
},
69+
passText: {
70+
color: 'green',
71+
},
72+
pendingText: {
73+
color: 'gray',
74+
},
75+
skippedText: {
76+
color: 'blue',
77+
},
78+
});

packages/rn-tester/js/examples/Experimental/PlatformTest/RNTesterPlatformTestTypes.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export type PlatformTestAssertionResult =
2828
| PassingPlatformTestAssertionResult
2929
| FailingPlatformTestAssertionResult;
3030

31-
export type PlatformTestResultStatus = 'PASS' | 'FAIL' | 'ERROR';
31+
export type PlatformTestResultStatus = 'PASS' | 'FAIL' | 'ERROR' | 'SKIPPED';
3232

3333
export type PlatformTestResult = $ReadOnly<{|
3434
name: string,
@@ -50,8 +50,16 @@ export type AsyncPlatformTest = $ReadOnly<{|
5050
done(): void,
5151
|}>;
5252

53+
export type SyncTestOptions = $ReadOnly<{|
54+
skip?: boolean,
55+
|}>;
56+
5357
export type PlatformTestHarness = $ReadOnly<{|
54-
test(testcase: PlatformTestCase, name: string): void,
58+
test(
59+
testcase: PlatformTestCase,
60+
name: string,
61+
options?: SyncTestOptions,
62+
): void,
5563
useAsyncTest(description: string, timeout?: number): AsyncPlatformTest,
5664
|}>;
5765

packages/rn-tester/js/examples/Experimental/PlatformTest/usePlatformTestHarness.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
PlatformTestCase,
1717
PlatformTestAssertionResult,
1818
PlatformTestContext,
19+
SyncTestOptions,
1920
} from './RNTesterPlatformTestTypes';
2021

2122
type AsyncTestStatus = 'NOT_RAN' | 'COMPLETED' | 'TIMED_OUT';
@@ -174,7 +175,23 @@ export default function usePlatformTestHarness(): PlatformTestHarnessHookResult
174175
}, []);
175176

176177
const testFunction: PlatformTestHarness['test'] = useCallback(
177-
(testCase: PlatformTestCase, name: string): void => {
178+
(
179+
testCase: PlatformTestCase,
180+
name: string,
181+
options?: SyncTestOptions,
182+
): void => {
183+
const {skip = false} = options ?? {};
184+
185+
if (skip) {
186+
addTestResult({
187+
name,
188+
status: 'SKIPPED',
189+
assertions: [],
190+
error: null,
191+
});
192+
return;
193+
}
194+
178195
const assertionResults: Array<PlatformTestAssertionResult> = [];
179196

180197
const baseAssert = (

0 commit comments

Comments
 (0)