@testing-library/react-native 12.4.1 → 12.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/user-event/event-builder/index.d.ts +1 -1
- package/build/user-event/event-builder/scroll-view.d.ts +19 -6
- package/build/user-event/event-builder/scroll-view.js +12 -9
- package/build/user-event/event-builder/scroll-view.js.map +1 -1
- package/build/user-event/scroll/scroll-to.d.ts +13 -2
- package/build/user-event/scroll/scroll-to.js +11 -10
- package/build/user-event/scroll/scroll-to.js.map +1 -1
- package/build/user-event/utils/dispatch-event.d.ts +2 -2
- package/build/user-event/utils/dispatch-event.js +3 -3
- package/build/user-event/utils/dispatch-event.js.map +1 -1
- package/package.json +41 -35
|
@@ -77,7 +77,7 @@ export declare const EventBuilder: {
|
|
|
77
77
|
};
|
|
78
78
|
};
|
|
79
79
|
ScrollView: {
|
|
80
|
-
scroll: (offset?: import("./scroll-view").ContentOffset) => {
|
|
80
|
+
scroll: (offset?: import("./scroll-view").ContentOffset, options?: import("./scroll-view").ScrollEventOptions | undefined) => {
|
|
81
81
|
nativeEvent: {
|
|
82
82
|
contentInset: {
|
|
83
83
|
bottom: number;
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Experimental values:
|
|
3
|
-
* - iOS: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 5.333333333333333}, "contentSize": {"height": 1676.6666259765625, "width": 390}, "layoutMeasurement": {"height": 753, "width": 390}, "zoomScale": 1}`
|
|
4
|
-
* - Android: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 31.619047164916992}, "contentSize": {"height": 1624.761962890625, "width": 411.4285583496094}, "layoutMeasurement": {"height": 785.5238037109375, "width": 411.4285583496094}, "responderIgnoreScroll": true, "target": 139, "velocity": {"x": -1.3633992671966553, "y": -1.3633992671966553}}`
|
|
5
|
-
*/
|
|
6
1
|
/**
|
|
7
2
|
* Scroll position of a scrollable element.
|
|
8
3
|
*/
|
|
@@ -10,8 +5,26 @@ export interface ContentOffset {
|
|
|
10
5
|
y: number;
|
|
11
6
|
x: number;
|
|
12
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Other options for constructing a scroll event.
|
|
10
|
+
*/
|
|
11
|
+
export type ScrollEventOptions = {
|
|
12
|
+
contentSize?: {
|
|
13
|
+
height: number;
|
|
14
|
+
width: number;
|
|
15
|
+
};
|
|
16
|
+
layoutMeasurement?: {
|
|
17
|
+
height: number;
|
|
18
|
+
width: number;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Experimental values:
|
|
23
|
+
* - iOS: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 5.333333333333333}, "contentSize": {"height": 1676.6666259765625, "width": 390}, "layoutMeasurement": {"height": 753, "width": 390}, "zoomScale": 1}`
|
|
24
|
+
* - Android: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 31.619047164916992}, "contentSize": {"height": 1624.761962890625, "width": 411.4285583496094}, "layoutMeasurement": {"height": 785.5238037109375, "width": 411.4285583496094}, "responderIgnoreScroll": true, "target": 139, "velocity": {"x": -1.3633992671966553, "y": -1.3633992671966553}}`
|
|
25
|
+
*/
|
|
13
26
|
export declare const ScrollViewEventBuilder: {
|
|
14
|
-
scroll: (offset?: ContentOffset) => {
|
|
27
|
+
scroll: (offset?: ContentOffset, options?: ScrollEventOptions) => {
|
|
15
28
|
nativeEvent: {
|
|
16
29
|
contentInset: {
|
|
17
30
|
bottom: number;
|
|
@@ -5,20 +5,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.ScrollViewEventBuilder = void 0;
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* - iOS: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 5.333333333333333}, "contentSize": {"height": 1676.6666259765625, "width": 390}, "layoutMeasurement": {"height": 753, "width": 390}, "zoomScale": 1}`
|
|
10
|
-
* - Android: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 31.619047164916992}, "contentSize": {"height": 1624.761962890625, "width": 411.4285583496094}, "layoutMeasurement": {"height": 785.5238037109375, "width": 411.4285583496094}, "responderIgnoreScroll": true, "target": 139, "velocity": {"x": -1.3633992671966553, "y": -1.3633992671966553}}`
|
|
8
|
+
* Scroll position of a scrollable element.
|
|
11
9
|
*/
|
|
12
10
|
|
|
13
11
|
/**
|
|
14
|
-
*
|
|
12
|
+
* Other options for constructing a scroll event.
|
|
15
13
|
*/
|
|
16
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Experimental values:
|
|
17
|
+
* - iOS: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 5.333333333333333}, "contentSize": {"height": 1676.6666259765625, "width": 390}, "layoutMeasurement": {"height": 753, "width": 390}, "zoomScale": 1}`
|
|
18
|
+
* - Android: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 31.619047164916992}, "contentSize": {"height": 1624.761962890625, "width": 411.4285583496094}, "layoutMeasurement": {"height": 785.5238037109375, "width": 411.4285583496094}, "responderIgnoreScroll": true, "target": 139, "velocity": {"x": -1.3633992671966553, "y": -1.3633992671966553}}`
|
|
19
|
+
*/
|
|
17
20
|
const ScrollViewEventBuilder = exports.ScrollViewEventBuilder = {
|
|
18
21
|
scroll: (offset = {
|
|
19
22
|
y: 0,
|
|
20
23
|
x: 0
|
|
21
|
-
}) => {
|
|
24
|
+
}, options) => {
|
|
22
25
|
return {
|
|
23
26
|
nativeEvent: {
|
|
24
27
|
contentInset: {
|
|
@@ -32,12 +35,12 @@ const ScrollViewEventBuilder = exports.ScrollViewEventBuilder = {
|
|
|
32
35
|
x: offset.x
|
|
33
36
|
},
|
|
34
37
|
contentSize: {
|
|
35
|
-
height: 0,
|
|
36
|
-
width: 0
|
|
38
|
+
height: options?.contentSize?.height ?? 0,
|
|
39
|
+
width: options?.contentSize?.width ?? 0
|
|
37
40
|
},
|
|
38
41
|
layoutMeasurement: {
|
|
39
|
-
height: 0,
|
|
40
|
-
width: 0
|
|
42
|
+
height: options?.layoutMeasurement?.height ?? 0,
|
|
43
|
+
width: options?.layoutMeasurement?.width ?? 0
|
|
41
44
|
},
|
|
42
45
|
responderIgnoreScroll: true,
|
|
43
46
|
target: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll-view.js","names":["ScrollViewEventBuilder","exports","scroll","offset","y","x","nativeEvent","contentInset","bottom","left","right","top","contentOffset","contentSize","height","width","layoutMeasurement","responderIgnoreScroll","target","velocity","currentTarget"],"sources":["../../../src/user-event/event-builder/scroll-view.ts"],"sourcesContent":["/**\n * Experimental values:\n * - iOS: `{\"contentInset\": {\"bottom\": 0, \"left\": 0, \"right\": 0, \"top\": 0}, \"contentOffset\": {\"x\": 0, \"y\": 5.333333333333333}, \"contentSize\": {\"height\": 1676.6666259765625, \"width\": 390}, \"layoutMeasurement\": {\"height\": 753, \"width\": 390}, \"zoomScale\": 1}`\n * - Android: `{\"contentInset\": {\"bottom\": 0, \"left\": 0, \"right\": 0, \"top\": 0}, \"contentOffset\": {\"x\": 0, \"y\": 31.619047164916992}, \"contentSize\": {\"height\": 1624.761962890625, \"width\": 411.4285583496094}, \"layoutMeasurement\": {\"height\": 785.5238037109375, \"width\": 411.4285583496094}, \"responderIgnoreScroll\": true, \"target\": 139, \"velocity\": {\"x\": -1.3633992671966553, \"y\": -1.3633992671966553}}`\n */\
|
|
1
|
+
{"version":3,"file":"scroll-view.js","names":["ScrollViewEventBuilder","exports","scroll","offset","y","x","options","nativeEvent","contentInset","bottom","left","right","top","contentOffset","contentSize","height","width","layoutMeasurement","responderIgnoreScroll","target","velocity","currentTarget"],"sources":["../../../src/user-event/event-builder/scroll-view.ts"],"sourcesContent":["/**\n * Scroll position of a scrollable element.\n */\nexport interface ContentOffset {\n y: number;\n x: number;\n}\n\n/**\n * Other options for constructing a scroll event.\n */\nexport type ScrollEventOptions = {\n contentSize?: {\n height: number;\n width: number;\n };\n layoutMeasurement?: {\n height: number;\n width: number;\n };\n};\n\n/**\n * Experimental values:\n * - iOS: `{\"contentInset\": {\"bottom\": 0, \"left\": 0, \"right\": 0, \"top\": 0}, \"contentOffset\": {\"x\": 0, \"y\": 5.333333333333333}, \"contentSize\": {\"height\": 1676.6666259765625, \"width\": 390}, \"layoutMeasurement\": {\"height\": 753, \"width\": 390}, \"zoomScale\": 1}`\n * - Android: `{\"contentInset\": {\"bottom\": 0, \"left\": 0, \"right\": 0, \"top\": 0}, \"contentOffset\": {\"x\": 0, \"y\": 31.619047164916992}, \"contentSize\": {\"height\": 1624.761962890625, \"width\": 411.4285583496094}, \"layoutMeasurement\": {\"height\": 785.5238037109375, \"width\": 411.4285583496094}, \"responderIgnoreScroll\": true, \"target\": 139, \"velocity\": {\"x\": -1.3633992671966553, \"y\": -1.3633992671966553}}`\n */\nexport const ScrollViewEventBuilder = {\n scroll: (\n offset: ContentOffset = { y: 0, x: 0 },\n options?: ScrollEventOptions\n ) => {\n return {\n nativeEvent: {\n contentInset: { bottom: 0, left: 0, right: 0, top: 0 },\n contentOffset: { y: offset.y, x: offset.x },\n contentSize: {\n height: options?.contentSize?.height ?? 0,\n width: options?.contentSize?.width ?? 0,\n },\n layoutMeasurement: {\n height: options?.layoutMeasurement?.height ?? 0,\n width: options?.layoutMeasurement?.width ?? 0,\n },\n responderIgnoreScroll: true,\n target: 0,\n velocity: { y: 0, x: 0 },\n },\n currentTarget: {},\n target: {},\n };\n },\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;;AAMA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACO,MAAMA,sBAAsB,GAAAC,OAAA,CAAAD,sBAAA,GAAG;EACpCE,MAAM,EAAEA,CACNC,MAAqB,GAAG;IAAEC,CAAC,EAAE,CAAC;IAAEC,CAAC,EAAE;EAAE,CAAC,EACtCC,OAA4B,KACzB;IACH,OAAO;MACLC,WAAW,EAAE;QACXC,YAAY,EAAE;UAAEC,MAAM,EAAE,CAAC;UAAEC,IAAI,EAAE,CAAC;UAAEC,KAAK,EAAE,CAAC;UAAEC,GAAG,EAAE;QAAE,CAAC;QACtDC,aAAa,EAAE;UAAET,CAAC,EAAED,MAAM,CAACC,CAAC;UAAEC,CAAC,EAAEF,MAAM,CAACE;QAAE,CAAC;QAC3CS,WAAW,EAAE;UACXC,MAAM,EAAET,OAAO,EAAEQ,WAAW,EAAEC,MAAM,IAAI,CAAC;UACzCC,KAAK,EAAEV,OAAO,EAAEQ,WAAW,EAAEE,KAAK,IAAI;QACxC,CAAC;QACDC,iBAAiB,EAAE;UACjBF,MAAM,EAAET,OAAO,EAAEW,iBAAiB,EAAEF,MAAM,IAAI,CAAC;UAC/CC,KAAK,EAAEV,OAAO,EAAEW,iBAAiB,EAAED,KAAK,IAAI;QAC9C,CAAC;QACDE,qBAAqB,EAAE,IAAI;QAC3BC,MAAM,EAAE,CAAC;QACTC,QAAQ,EAAE;UAAEhB,CAAC,EAAE,CAAC;UAAEC,CAAC,EAAE;QAAE;MACzB,CAAC;MACDgB,aAAa,EAAE,CAAC,CAAC;MACjBF,MAAM,EAAE,CAAC;IACX,CAAC;EACH;AACF,CAAC"}
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import { ReactTestInstance } from 'react-test-renderer';
|
|
2
2
|
import { UserEventInstance } from '../setup';
|
|
3
|
-
|
|
3
|
+
interface CommonScrollToOptions {
|
|
4
|
+
contentSize?: {
|
|
5
|
+
height: number;
|
|
6
|
+
width: number;
|
|
7
|
+
};
|
|
8
|
+
layoutMeasurement?: {
|
|
9
|
+
height: number;
|
|
10
|
+
width: number;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface VerticalScrollToOptions extends CommonScrollToOptions {
|
|
4
14
|
y: number;
|
|
5
15
|
momentumY?: number;
|
|
6
16
|
x?: never;
|
|
7
17
|
momentumX?: never;
|
|
8
18
|
}
|
|
9
|
-
export interface HorizontalScrollToOptions {
|
|
19
|
+
export interface HorizontalScrollToOptions extends CommonScrollToOptions {
|
|
10
20
|
x: number;
|
|
11
21
|
momentumX?: number;
|
|
12
22
|
y?: never;
|
|
@@ -14,3 +24,4 @@ export interface HorizontalScrollToOptions {
|
|
|
14
24
|
}
|
|
15
25
|
export type ScrollToOptions = VerticalScrollToOptions | HorizontalScrollToOptions;
|
|
16
26
|
export declare function scrollTo(this: UserEventInstance, element: ReactTestInstance, options: ScrollToOptions): Promise<void>;
|
|
27
|
+
export {};
|
|
@@ -17,56 +17,57 @@ async function scrollTo(element, options) {
|
|
|
17
17
|
throw new _errors.ErrorWithStack(`scrollTo() works only with host "ScrollView" elements. Passed element has type "${element.type}".`, scrollTo);
|
|
18
18
|
}
|
|
19
19
|
ensureScrollViewDirection(element, options);
|
|
20
|
+
(0, _utils.dispatchEvent)(element, 'contentSizeChange', options.contentSize?.width ?? 0, options.contentSize?.height ?? 0);
|
|
20
21
|
const initialPosition = (0, _state.getElementScrollOffset)(element);
|
|
21
22
|
const dragSteps = (0, _utils2.createScrollSteps)({
|
|
22
23
|
y: options.y,
|
|
23
24
|
x: options.x
|
|
24
25
|
}, initialPosition, _utils2.linearInterpolator);
|
|
25
|
-
await emitDragScrollEvents(this.config, element, dragSteps);
|
|
26
|
+
await emitDragScrollEvents(this.config, element, dragSteps, options);
|
|
26
27
|
const momentumStart = dragSteps.at(-1) ?? initialPosition;
|
|
27
28
|
const momentumSteps = (0, _utils2.createScrollSteps)({
|
|
28
29
|
y: options.momentumY,
|
|
29
30
|
x: options.momentumX
|
|
30
31
|
}, momentumStart, _utils2.inertialInterpolator);
|
|
31
|
-
await emitMomentumScrollEvents(this.config, element, momentumSteps);
|
|
32
|
+
await emitMomentumScrollEvents(this.config, element, momentumSteps, options);
|
|
32
33
|
const finalPosition = momentumSteps.at(-1) ?? dragSteps.at(-1) ?? initialPosition;
|
|
33
34
|
(0, _state.setElementScrollOffset)(element, finalPosition);
|
|
34
35
|
}
|
|
35
|
-
async function emitDragScrollEvents(config, element, scrollSteps) {
|
|
36
|
+
async function emitDragScrollEvents(config, element, scrollSteps, scrollOptions) {
|
|
36
37
|
if (scrollSteps.length === 0) {
|
|
37
38
|
return;
|
|
38
39
|
}
|
|
39
40
|
await (0, _utils.wait)(config);
|
|
40
|
-
(0, _utils.dispatchEvent)(element, 'scrollBeginDrag', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[0]));
|
|
41
|
+
(0, _utils.dispatchEvent)(element, 'scrollBeginDrag', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[0], scrollOptions));
|
|
41
42
|
|
|
42
43
|
// Note: experimentally, in case of drag scroll the last scroll step
|
|
43
44
|
// will not trigger `scroll` event.
|
|
44
45
|
// See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events
|
|
45
46
|
for (let i = 1; i < scrollSteps.length - 1; i += 1) {
|
|
46
47
|
await (0, _utils.wait)(config);
|
|
47
|
-
(0, _utils.dispatchEvent)(element, 'scroll', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[i]));
|
|
48
|
+
(0, _utils.dispatchEvent)(element, 'scroll', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions));
|
|
48
49
|
}
|
|
49
50
|
await (0, _utils.wait)(config);
|
|
50
51
|
const lastStep = scrollSteps.at(-1);
|
|
51
|
-
(0, _utils.dispatchEvent)(element, 'scrollEndDrag', _eventBuilder.EventBuilder.ScrollView.scroll(lastStep));
|
|
52
|
+
(0, _utils.dispatchEvent)(element, 'scrollEndDrag', _eventBuilder.EventBuilder.ScrollView.scroll(lastStep, scrollOptions));
|
|
52
53
|
}
|
|
53
|
-
async function emitMomentumScrollEvents(config, element, scrollSteps) {
|
|
54
|
+
async function emitMomentumScrollEvents(config, element, scrollSteps, scrollOptions) {
|
|
54
55
|
if (scrollSteps.length === 0) {
|
|
55
56
|
return;
|
|
56
57
|
}
|
|
57
58
|
await (0, _utils.wait)(config);
|
|
58
|
-
(0, _utils.dispatchEvent)(element, 'momentumScrollBegin', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[0]));
|
|
59
|
+
(0, _utils.dispatchEvent)(element, 'momentumScrollBegin', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[0], scrollOptions));
|
|
59
60
|
|
|
60
61
|
// Note: experimentally, in case of momentum scroll the last scroll step
|
|
61
62
|
// will trigger `scroll` event.
|
|
62
63
|
// See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events
|
|
63
64
|
for (let i = 1; i < scrollSteps.length; i += 1) {
|
|
64
65
|
await (0, _utils.wait)(config);
|
|
65
|
-
(0, _utils.dispatchEvent)(element, 'scroll', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[i]));
|
|
66
|
+
(0, _utils.dispatchEvent)(element, 'scroll', _eventBuilder.EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions));
|
|
66
67
|
}
|
|
67
68
|
await (0, _utils.wait)(config);
|
|
68
69
|
const lastStep = scrollSteps.at(-1);
|
|
69
|
-
(0, _utils.dispatchEvent)(element, 'momentumScrollEnd', _eventBuilder.EventBuilder.ScrollView.scroll(lastStep));
|
|
70
|
+
(0, _utils.dispatchEvent)(element, 'momentumScrollEnd', _eventBuilder.EventBuilder.ScrollView.scroll(lastStep, scrollOptions));
|
|
70
71
|
}
|
|
71
72
|
function ensureScrollViewDirection(element, options) {
|
|
72
73
|
const isVerticalScrollView = element.props.horizontal !== true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll-to.js","names":["_jestMatcherUtils","require","_eventBuilder","_errors","_hostComponentNames","_object","_utils","_utils2","_state","scrollTo","element","options","isHostScrollView","ErrorWithStack","type","ensureScrollViewDirection","initialPosition","getElementScrollOffset","dragSteps","createScrollSteps","y","x","linearInterpolator","emitDragScrollEvents","config","momentumStart","at","momentumSteps","momentumY","momentumX","inertialInterpolator","emitMomentumScrollEvents","finalPosition","setElementScrollOffset","scrollSteps","length","wait","dispatchEvent","EventBuilder","ScrollView","scroll","i","lastStep","isVerticalScrollView","props","horizontal","hasHorizontalScrollOptions","undefined","stringify","pick","hasVerticalScrollOptions"],"sources":["../../../src/user-event/scroll/scroll-to.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { stringify } from 'jest-matcher-utils';\nimport { UserEventConfig, UserEventInstance } from '../setup';\nimport { EventBuilder } from '../event-builder';\nimport { ErrorWithStack } from '../../helpers/errors';\nimport { isHostScrollView } from '../../helpers/host-component-names';\nimport { pick } from '../../helpers/object';\nimport { dispatchEvent, wait } from '../utils';\nimport { ContentOffset } from '../event-builder/scroll-view';\nimport {\n createScrollSteps,\n inertialInterpolator,\n linearInterpolator,\n} from './utils';\nimport { getElementScrollOffset, setElementScrollOffset } from './state';\n\nexport interface VerticalScrollToOptions {\n y: number;\n momentumY?: number;\n\n // Vertical scroll should not contain horizontal scroll part.\n x?: never;\n momentumX?: never;\n}\n\nexport interface HorizontalScrollToOptions {\n x: number;\n momentumX?: number;\n\n // Horizontal scroll should not contain vertical scroll part.\n y?: never;\n momentumY?: never;\n}\n\nexport type ScrollToOptions =\n | VerticalScrollToOptions\n | HorizontalScrollToOptions;\n\nexport async function scrollTo(\n this: UserEventInstance,\n element: ReactTestInstance,\n options: ScrollToOptions\n): Promise<void> {\n if (!isHostScrollView(element)) {\n throw new ErrorWithStack(\n `scrollTo() works only with host \"ScrollView\" elements. Passed element has type \"${element.type}\".`,\n scrollTo\n );\n }\n\n ensureScrollViewDirection(element, options);\n\n const initialPosition = getElementScrollOffset(element);\n const dragSteps = createScrollSteps(\n { y: options.y, x: options.x },\n initialPosition,\n linearInterpolator\n );\n await emitDragScrollEvents(this.config, element, dragSteps);\n\n const momentumStart = dragSteps.at(-1) ?? initialPosition;\n const momentumSteps = createScrollSteps(\n { y: options.momentumY, x: options.momentumX },\n momentumStart,\n inertialInterpolator\n );\n await emitMomentumScrollEvents(this.config, element, momentumSteps);\n\n const finalPosition =\n momentumSteps.at(-1) ?? dragSteps.at(-1) ?? initialPosition;\n setElementScrollOffset(element, finalPosition);\n}\n\nasync function emitDragScrollEvents(\n config: UserEventConfig,\n element: ReactTestInstance,\n scrollSteps: ContentOffset[]\n) {\n if (scrollSteps.length === 0) {\n return;\n }\n\n await wait(config);\n dispatchEvent(\n element,\n 'scrollBeginDrag',\n EventBuilder.ScrollView.scroll(scrollSteps[0])\n );\n\n // Note: experimentally, in case of drag scroll the last scroll step\n // will not trigger `scroll` event.\n // See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events\n for (let i = 1; i < scrollSteps.length - 1; i += 1) {\n await wait(config);\n dispatchEvent(\n element,\n 'scroll',\n EventBuilder.ScrollView.scroll(scrollSteps[i])\n );\n }\n\n await wait(config);\n const lastStep = scrollSteps.at(-1);\n dispatchEvent(\n element,\n 'scrollEndDrag',\n EventBuilder.ScrollView.scroll(lastStep)\n );\n}\n\nasync function emitMomentumScrollEvents(\n config: UserEventConfig,\n element: ReactTestInstance,\n scrollSteps: ContentOffset[]\n) {\n if (scrollSteps.length === 0) {\n return;\n }\n\n await wait(config);\n dispatchEvent(\n element,\n 'momentumScrollBegin',\n EventBuilder.ScrollView.scroll(scrollSteps[0])\n );\n\n // Note: experimentally, in case of momentum scroll the last scroll step\n // will trigger `scroll` event.\n // See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events\n for (let i = 1; i < scrollSteps.length; i += 1) {\n await wait(config);\n dispatchEvent(\n element,\n 'scroll',\n EventBuilder.ScrollView.scroll(scrollSteps[i])\n );\n }\n\n await wait(config);\n const lastStep = scrollSteps.at(-1);\n dispatchEvent(\n element,\n 'momentumScrollEnd',\n EventBuilder.ScrollView.scroll(lastStep)\n );\n}\n\nfunction ensureScrollViewDirection(\n element: ReactTestInstance,\n options: ScrollToOptions\n) {\n const isVerticalScrollView = element.props.horizontal !== true;\n\n const hasHorizontalScrollOptions =\n options.x !== undefined || options.momentumX !== undefined;\n if (isVerticalScrollView && hasHorizontalScrollOptions) {\n throw new ErrorWithStack(\n `scrollTo() expected only vertical scroll options: \"y\" and \"momentumY\" for vertical \"ScrollView\" element but received ${stringify(\n pick(options, ['x', 'momentumX'])\n )}`,\n scrollTo\n );\n }\n\n const hasVerticalScrollOptions =\n options.y !== undefined || options.momentumY !== undefined;\n if (!isVerticalScrollView && hasVerticalScrollOptions) {\n throw new ErrorWithStack(\n `scrollTo() expected only horizontal scroll options: \"x\" and \"momentumX\" for horizontal \"ScrollView\" element but received ${stringify(\n pick(options, ['y', 'momentumY'])\n )}`,\n scrollTo\n );\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AAEA,IAAAM,OAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA;AAwBO,eAAeQ,QAAQA,CAE5BC,OAA0B,EAC1BC,OAAwB,EACT;EACf,IAAI,CAAC,IAAAC,oCAAgB,EAACF,OAAO,CAAC,EAAE;IAC9B,MAAM,IAAIG,sBAAc,CACrB,mFAAkFH,OAAO,CAACI,IAAK,IAAG,EACnGL,QACF,CAAC;EACH;EAEAM,yBAAyB,CAACL,OAAO,EAAEC,OAAO,CAAC;EAE3C,MAAMK,eAAe,GAAG,IAAAC,6BAAsB,EAACP,OAAO,CAAC;EACvD,MAAMQ,SAAS,GAAG,IAAAC,yBAAiB,EACjC;IAAEC,CAAC,EAAET,OAAO,CAACS,CAAC;IAAEC,CAAC,EAAEV,O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,UAAU,KAAK,IAAI;EAE9D,MAAMC,0BAA0B,GAC9BnC,OAAO,CAACU,CAAC,KAAK0B,SAAS,IAAIpC,OAAO,CAACkB,SAAS,KAAKkB,SAAS;EAC5D,IAAIJ,oBAAoB,IAAIG,0BAA0B,EAAE;IACtD,MAAM,IAAIjC,sBAAc,CACrB,wHAAuH,IAAAmC,2BAAS,EAC/H,IAAAC,YAAI,EAACtC,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,CAClC,CAAE,EAAC,EACHF,QACF,CAAC;EACH;EAEA,MAAMyC,wBAAwB,GAC5BvC,OAAO,CAACS,CAAC,KAAK2B,SAAS,IAAIpC,OAAO,CAACiB,SAAS,KAAKmB,SAAS;EAC5D,IAAI,CAACJ,oBAAoB,IAAIO,wBAAwB,EAAE;IACrD,MAAM,IAAIrC,sBAAc,CACrB,4HAA2H,IAAAmC,2BAAS,EACnI,IAAAC,YAAI,EAACtC,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,CAClC,CAAE,EAAC,EACHF,QACF,CAAC;EACH;AACF"}
|
|
1
|
+
{"version":3,"file":"scroll-to.js","names":["_jestMatcherUtils","require","_eventBuilder","_errors","_hostComponentNames","_object","_utils","_utils2","_state","scrollTo","element","options","isHostScrollView","ErrorWithStack","type","ensureScrollViewDirection","dispatchEvent","contentSize","width","height","initialPosition","getElementScrollOffset","dragSteps","createScrollSteps","y","x","linearInterpolator","emitDragScrollEvents","config","momentumStart","at","momentumSteps","momentumY","momentumX","inertialInterpolator","emitMomentumScrollEvents","finalPosition","setElementScrollOffset","scrollSteps","scrollOptions","length","wait","EventBuilder","ScrollView","scroll","i","lastStep","isVerticalScrollView","props","horizontal","hasHorizontalScrollOptions","undefined","stringify","pick","hasVerticalScrollOptions"],"sources":["../../../src/user-event/scroll/scroll-to.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport { stringify } from 'jest-matcher-utils';\nimport { UserEventConfig, UserEventInstance } from '../setup';\nimport { EventBuilder } from '../event-builder';\nimport { ErrorWithStack } from '../../helpers/errors';\nimport { isHostScrollView } from '../../helpers/host-component-names';\nimport { pick } from '../../helpers/object';\nimport { ContentOffset } from '../event-builder/scroll-view';\nimport { dispatchEvent, wait } from '../utils';\nimport {\n createScrollSteps,\n inertialInterpolator,\n linearInterpolator,\n} from './utils';\nimport { getElementScrollOffset, setElementScrollOffset } from './state';\n\ninterface CommonScrollToOptions {\n contentSize?: {\n height: number;\n width: number;\n };\n layoutMeasurement?: {\n height: number;\n width: number;\n };\n}\n\nexport interface VerticalScrollToOptions extends CommonScrollToOptions {\n y: number;\n momentumY?: number;\n\n // Vertical scroll should not contain horizontal scroll part.\n x?: never;\n momentumX?: never;\n}\n\nexport interface HorizontalScrollToOptions extends CommonScrollToOptions {\n x: number;\n momentumX?: number;\n\n // Horizontal scroll should not contain vertical scroll part.\n y?: never;\n momentumY?: never;\n}\n\nexport type ScrollToOptions =\n | VerticalScrollToOptions\n | HorizontalScrollToOptions;\n\nexport async function scrollTo(\n this: UserEventInstance,\n element: ReactTestInstance,\n options: ScrollToOptions\n): Promise<void> {\n if (!isHostScrollView(element)) {\n throw new ErrorWithStack(\n `scrollTo() works only with host \"ScrollView\" elements. Passed element has type \"${element.type}\".`,\n scrollTo\n );\n }\n\n ensureScrollViewDirection(element, options);\n\n dispatchEvent(\n element,\n 'contentSizeChange',\n options.contentSize?.width ?? 0,\n options.contentSize?.height ?? 0\n );\n\n const initialPosition = getElementScrollOffset(element);\n const dragSteps = createScrollSteps(\n { y: options.y, x: options.x },\n initialPosition,\n linearInterpolator\n );\n await emitDragScrollEvents(this.config, element, dragSteps, options);\n\n const momentumStart = dragSteps.at(-1) ?? initialPosition;\n const momentumSteps = createScrollSteps(\n { y: options.momentumY, x: options.momentumX },\n momentumStart,\n inertialInterpolator\n );\n await emitMomentumScrollEvents(this.config, element, momentumSteps, options);\n\n const finalPosition =\n momentumSteps.at(-1) ?? dragSteps.at(-1) ?? initialPosition;\n setElementScrollOffset(element, finalPosition);\n}\n\nasync function emitDragScrollEvents(\n config: UserEventConfig,\n element: ReactTestInstance,\n scrollSteps: ContentOffset[],\n scrollOptions: ScrollToOptions\n) {\n if (scrollSteps.length === 0) {\n return;\n }\n\n await wait(config);\n dispatchEvent(\n element,\n 'scrollBeginDrag',\n EventBuilder.ScrollView.scroll(scrollSteps[0], scrollOptions)\n );\n\n // Note: experimentally, in case of drag scroll the last scroll step\n // will not trigger `scroll` event.\n // See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events\n for (let i = 1; i < scrollSteps.length - 1; i += 1) {\n await wait(config);\n dispatchEvent(\n element,\n 'scroll',\n EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions)\n );\n }\n\n await wait(config);\n const lastStep = scrollSteps.at(-1);\n dispatchEvent(\n element,\n 'scrollEndDrag',\n EventBuilder.ScrollView.scroll(lastStep, scrollOptions)\n );\n}\n\nasync function emitMomentumScrollEvents(\n config: UserEventConfig,\n element: ReactTestInstance,\n scrollSteps: ContentOffset[],\n scrollOptions: ScrollToOptions\n) {\n if (scrollSteps.length === 0) {\n return;\n }\n\n await wait(config);\n dispatchEvent(\n element,\n 'momentumScrollBegin',\n EventBuilder.ScrollView.scroll(scrollSteps[0], scrollOptions)\n );\n\n // Note: experimentally, in case of momentum scroll the last scroll step\n // will trigger `scroll` event.\n // See: https://github.com/callstack/react-native-testing-library/wiki/ScrollView-Events\n for (let i = 1; i < scrollSteps.length; i += 1) {\n await wait(config);\n dispatchEvent(\n element,\n 'scroll',\n EventBuilder.ScrollView.scroll(scrollSteps[i], scrollOptions)\n );\n }\n\n await wait(config);\n const lastStep = scrollSteps.at(-1);\n dispatchEvent(\n element,\n 'momentumScrollEnd',\n EventBuilder.ScrollView.scroll(lastStep, scrollOptions)\n );\n}\n\nfunction ensureScrollViewDirection(\n element: ReactTestInstance,\n options: ScrollToOptions\n) {\n const isVerticalScrollView = element.props.horizontal !== true;\n\n const hasHorizontalScrollOptions =\n options.x !== undefined || options.momentumX !== undefined;\n if (isVerticalScrollView && hasHorizontalScrollOptions) {\n throw new ErrorWithStack(\n `scrollTo() expected only vertical scroll options: \"y\" and \"momentumY\" for vertical \"ScrollView\" element but received ${stringify(\n pick(options, ['x', 'momentumX'])\n )}`,\n scrollTo\n );\n }\n\n const hasVerticalScrollOptions =\n options.y !== undefined || options.momentumY !== undefined;\n if (!isVerticalScrollView && hasVerticalScrollOptions) {\n throw new ErrorWithStack(\n `scrollTo() expected only horizontal scroll options: \"x\" and \"momentumX\" for horizontal \"ScrollView\" element but received ${stringify(\n pick(options, ['y', 'momentumY'])\n )}`,\n scrollTo\n );\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,mBAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,OAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA;AAmCO,eAAeQ,QAAQA,CAE5BC,OAA0B,EAC1BC,OAAwB,EACT;EACf,IAAI,CAAC,IAAAC,oCAAgB,EAACF,OAAO,CAAC,EAAE;IAC9B,MAAM,IAAIG,sBAAc,CACrB,mFAAkFH,OAAO,CAACI,IAAK,IAAG,EACnGL,QACF,CAAC;EACH;EAEAM,yBAAyB,CAACL,OAAO,EAAEC,OAAO,CAAC;EAE3C,IAAAK,oBAAa,EACXN,OAAO,EACP,mBAAmB,EACnBC,OAAO,CAACM,WAAW,EAAEC,KAAK,IAAI,CAAC,EAC/BP,OAAO,CAACM,WAAW,EAAEE,MAAM,IAAI,CACjC,CAAC;EAED,MAAMC,eAAe,GAAG,IAAAC,6BAAsB,EAACX,OAAO,CAAC;EACvD,MAAMY,SAAS,GAAG,IAAAC,yBAAiB,EACjC;IAAEC,CAAC,EAAEb,OAAO,CAACa,CAAC;IA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ACE,QAAQ,EAAEP,aAAa,CACxD,CAAC;AACH;AAEA,SAASxB,yBAAyBA,CAChCL,OAA0B,EAC1BC,OAAwB,EACxB;EACA,MAAMoC,oBAAoB,GAAGrC,OAAO,CAACsC,KAAK,CAACC,UAAU,KAAK,IAAI;EAE9D,MAAMC,0BAA0B,GAC9BvC,OAAO,CAACc,CAAC,KAAK0B,SAAS,IAAIxC,OAAO,CAACsB,SAAS,KAAKkB,SAAS;EAC5D,IAAIJ,oBAAoB,IAAIG,0BAA0B,EAAE;IACtD,MAAM,IAAIrC,sBAAc,CACrB,wHAAuH,IAAAuC,2BAAS,EAC/H,IAAAC,YAAI,EAAC1C,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,CAClC,CAAE,EAAC,EACHF,QACF,CAAC;EACH;EAEA,MAAM6C,wBAAwB,GAC5B3C,OAAO,CAACa,CAAC,KAAK2B,SAAS,IAAIxC,OAAO,CAACqB,SAAS,KAAKmB,SAAS;EAC5D,IAAI,CAACJ,oBAAoB,IAAIO,wBAAwB,EAAE;IACrD,MAAM,IAAIzC,sBAAc,CACrB,4HAA2H,IAAAuC,2BAAS,EACnI,IAAAC,YAAI,EAAC1C,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC,CAClC,CAAE,EAAC,EACHF,QACF,CAAC;EACH;AACF"}
|
|
@@ -4,6 +4,6 @@ import { ReactTestInstance } from 'react-test-renderer';
|
|
|
4
4
|
*
|
|
5
5
|
* @param element element trigger event on
|
|
6
6
|
* @param eventName name of the event
|
|
7
|
-
* @param event event payload
|
|
7
|
+
* @param event event payload(s)
|
|
8
8
|
*/
|
|
9
|
-
export declare function dispatchEvent(element: ReactTestInstance, eventName: string, event: unknown): void;
|
|
9
|
+
export declare function dispatchEvent(element: ReactTestInstance, eventName: string, ...event: unknown[]): void;
|
|
@@ -11,9 +11,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
11
11
|
*
|
|
12
12
|
* @param element element trigger event on
|
|
13
13
|
* @param eventName name of the event
|
|
14
|
-
* @param event event payload
|
|
14
|
+
* @param event event payload(s)
|
|
15
15
|
*/
|
|
16
|
-
function dispatchEvent(element, eventName, event) {
|
|
16
|
+
function dispatchEvent(element, eventName, ...event) {
|
|
17
17
|
const handler = getEventHandler(element, eventName);
|
|
18
18
|
if (!handler) {
|
|
19
19
|
return;
|
|
@@ -21,7 +21,7 @@ function dispatchEvent(element, eventName, event) {
|
|
|
21
21
|
|
|
22
22
|
// This will be called synchronously.
|
|
23
23
|
void (0, _act.default)(() => {
|
|
24
|
-
handler(event);
|
|
24
|
+
handler(...event);
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
function getEventHandler(element, eventName) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch-event.js","names":["_act","_interopRequireDefault","require","obj","__esModule","default","dispatchEvent","element","eventName","event","handler","getEventHandler","act","handleName","getEventHandlerName","handle","props","undefined","charAt","toUpperCase","slice"],"sources":["../../../src/user-event/utils/dispatch-event.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport act from '../../act';\n\n/**\n * Basic dispatch event function used by User Event module.\n *\n * @param element element trigger event on\n * @param eventName name of the event\n * @param event event payload\n */\nexport function dispatchEvent(\n element: ReactTestInstance,\n eventName: string,\n event: unknown\n) {\n const handler = getEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n // This will be called synchronously.\n void act(() => {\n handler(event);\n });\n}\n\nfunction getEventHandler(element: ReactTestInstance, eventName: string) {\n const handleName = getEventHandlerName(eventName);\n const handle = element.props[handleName] as unknown;\n if (typeof handle !== 'function') {\n return undefined;\n }\n\n return handle;\n}\n\nfunction getEventHandlerName(eventName: string) {\n return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n}\n"],"mappings":";;;;;;AACA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA4B,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,aAAaA,CAC3BC,OAA0B,EAC1BC,SAAiB,
|
|
1
|
+
{"version":3,"file":"dispatch-event.js","names":["_act","_interopRequireDefault","require","obj","__esModule","default","dispatchEvent","element","eventName","event","handler","getEventHandler","act","handleName","getEventHandlerName","handle","props","undefined","charAt","toUpperCase","slice"],"sources":["../../../src/user-event/utils/dispatch-event.ts"],"sourcesContent":["import { ReactTestInstance } from 'react-test-renderer';\nimport act from '../../act';\n\n/**\n * Basic dispatch event function used by User Event module.\n *\n * @param element element trigger event on\n * @param eventName name of the event\n * @param event event payload(s)\n */\nexport function dispatchEvent(\n element: ReactTestInstance,\n eventName: string,\n ...event: unknown[]\n) {\n const handler = getEventHandler(element, eventName);\n if (!handler) {\n return;\n }\n\n // This will be called synchronously.\n void act(() => {\n handler(...event);\n });\n}\n\nfunction getEventHandler(element: ReactTestInstance, eventName: string) {\n const handleName = getEventHandlerName(eventName);\n const handle = element.props[handleName] as unknown;\n if (typeof handle !== 'function') {\n return undefined;\n }\n\n return handle;\n}\n\nfunction getEventHandlerName(eventName: string) {\n return `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`;\n}\n"],"mappings":";;;;;;AACA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA4B,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,aAAaA,CAC3BC,OAA0B,EAC1BC,SAAiB,EACjB,GAAGC,KAAgB,EACnB;EACA,MAAMC,OAAO,GAAGC,eAAe,CAACJ,OAAO,EAAEC,SAAS,CAAC;EACnD,IAAI,CAACE,OAAO,EAAE;IACZ;EACF;;EAEA;EACA,KAAK,IAAAE,YAAG,EAAC,MAAM;IACbF,OAAO,CAAC,GAAGD,KAAK,CAAC;EACnB,CAAC,CAAC;AACJ;AAEA,SAASE,eAAeA,CAACJ,OAA0B,EAAEC,SAAiB,EAAE;EACtE,MAAMK,UAAU,GAAGC,mBAAmB,CAACN,SAAS,CAAC;EACjD,MAAMO,MAAM,GAAGR,OAAO,CAACS,KAAK,CAACH,UAAU,CAAY;EACnD,IAAI,OAAOE,MAAM,KAAK,UAAU,EAAE;IAChC,OAAOE,SAAS;EAClB;EAEA,OAAOF,MAAM;AACf;AAEA,SAASD,mBAAmBA,CAACN,SAAiB,EAAE;EAC9C,OAAQ,KAAIA,SAAS,CAACU,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAE,GAAEX,SAAS,CAACY,KAAK,CAAC,CAAC,CAAE,EAAC;AACtE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testing-library/react-native",
|
|
3
|
-
"version": "12.4.
|
|
3
|
+
"version": "12.4.2",
|
|
4
4
|
"description": "Simple and complete React Native testing utilities that encourage good testing practices.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -23,6 +23,25 @@
|
|
|
23
23
|
"test",
|
|
24
24
|
"integration"
|
|
25
25
|
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"clean": "del build",
|
|
28
|
+
"test": "jest",
|
|
29
|
+
"test:ci": "jest --maxWorkers=2 --collectCoverage=true --coverage-provider=v8",
|
|
30
|
+
"test:react-17": "scripts/test_react_17",
|
|
31
|
+
"typecheck": "tsc",
|
|
32
|
+
"flow": "flow",
|
|
33
|
+
"copy-flowtypes": "cp typings/index.flow.js build",
|
|
34
|
+
"lint": "eslint src --cache",
|
|
35
|
+
"validate": "yarn lint && yarn typecheck && yarn test",
|
|
36
|
+
"build:js": "babel src --out-dir build --extensions \".js,.ts,.jsx,.tsx\" --source-maps --ignore \"**/__tests__/**\"",
|
|
37
|
+
"build:js:watch": "yarn build:js --watch",
|
|
38
|
+
"build:ts": "tsc --build tsconfig.release.json",
|
|
39
|
+
"build:ts:watch": "yarn build:ts --watch --preserveWatchOutput",
|
|
40
|
+
"build": "yarn clean && yarn build:js && yarn build:ts && yarn copy-flowtypes",
|
|
41
|
+
"prepare": "yarn build",
|
|
42
|
+
"prepublish": "yarn build",
|
|
43
|
+
"publish": "release-it"
|
|
44
|
+
},
|
|
26
45
|
"files": [
|
|
27
46
|
"build/",
|
|
28
47
|
"jest-preset/",
|
|
@@ -33,6 +52,22 @@
|
|
|
33
52
|
"dont-cleanup-after-each.js",
|
|
34
53
|
"typings/index.flow.js"
|
|
35
54
|
],
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"jest-matcher-utils": "^29.7.0",
|
|
57
|
+
"pretty-format": "^29.7.0",
|
|
58
|
+
"redent": "^3.0.0"
|
|
59
|
+
},
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"jest": ">=28.0.0",
|
|
62
|
+
"react": ">=16.8.0",
|
|
63
|
+
"react-native": ">=0.59",
|
|
64
|
+
"react-test-renderer": ">=16.8.0"
|
|
65
|
+
},
|
|
66
|
+
"peerDependenciesMeta": {
|
|
67
|
+
"jest": {
|
|
68
|
+
"optional": true
|
|
69
|
+
}
|
|
70
|
+
},
|
|
36
71
|
"devDependencies": {
|
|
37
72
|
"@babel/cli": "^7.23.4",
|
|
38
73
|
"@babel/core": "^7.23.3",
|
|
@@ -42,6 +77,7 @@
|
|
|
42
77
|
"@babel/preset-react": "^7.23.3",
|
|
43
78
|
"@babel/preset-typescript": "^7.23.3",
|
|
44
79
|
"@callstack/eslint-config": "^14.1.0",
|
|
80
|
+
"@release-it/conventional-changelog": "^8.0.1",
|
|
45
81
|
"@relmify/jest-serializer-strip-ansi": "^1.0.2",
|
|
46
82
|
"@types/jest": "^29.5.10",
|
|
47
83
|
"@types/react": "^18.2.38",
|
|
@@ -57,42 +93,12 @@
|
|
|
57
93
|
"react": "18.2.0",
|
|
58
94
|
"react-native": "0.72.7",
|
|
59
95
|
"react-test-renderer": "18.2.0",
|
|
96
|
+
"release-it": "^17.0.1",
|
|
60
97
|
"strip-ansi": "^6.0.1",
|
|
61
98
|
"typescript": "^5.3.2"
|
|
62
99
|
},
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"pretty-format": "^29.7.0",
|
|
66
|
-
"redent": "^3.0.0"
|
|
67
|
-
},
|
|
68
|
-
"peerDependencies": {
|
|
69
|
-
"jest": ">=28.0.0",
|
|
70
|
-
"react": ">=16.8.0",
|
|
71
|
-
"react-native": ">=0.59",
|
|
72
|
-
"react-test-renderer": ">=16.8.0"
|
|
73
|
-
},
|
|
74
|
-
"peerDependenciesMeta": {
|
|
75
|
-
"jest": {
|
|
76
|
-
"optional": true
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
"scripts": {
|
|
80
|
-
"clean": "del build",
|
|
81
|
-
"test": "jest",
|
|
82
|
-
"test:ci": "jest --maxWorkers=2 --collectCoverage=true --coverage-provider=v8",
|
|
83
|
-
"test:react-17": "scripts/test_react_17",
|
|
84
|
-
"typecheck": "tsc",
|
|
85
|
-
"flow": "flow",
|
|
86
|
-
"copy-flowtypes": "cp typings/index.flow.js build",
|
|
87
|
-
"lint": "eslint src --cache",
|
|
88
|
-
"validate": "yarn lint && yarn typecheck && yarn test",
|
|
89
|
-
"prepublish": "yarn build",
|
|
90
|
-
"build:js": "babel src --out-dir build --extensions \".js,.ts,.jsx,.tsx\" --source-maps --ignore \"**/__tests__/**\"",
|
|
91
|
-
"build:js:watch": "yarn build:js --watch",
|
|
92
|
-
"build:ts": "tsc --build tsconfig.release.json",
|
|
93
|
-
"build:ts:watch": "yarn build:ts --watch --preserveWatchOutput",
|
|
94
|
-
"build": "yarn clean && yarn build:js && yarn build:ts && yarn copy-flowtypes",
|
|
95
|
-
"prepare": "yarn build"
|
|
100
|
+
"publishConfig": {
|
|
101
|
+
"registry": "https://registry.npmjs.org"
|
|
96
102
|
},
|
|
97
103
|
"packageManager": "yarn@4.0.1"
|
|
98
|
-
}
|
|
104
|
+
}
|