system-testing 1.0.22 → 1.0.23
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/package.json
CHANGED
|
@@ -179,6 +179,8 @@ export default class SystemTestBrowserHelper {
|
|
|
179
179
|
return {result: "initialized"}
|
|
180
180
|
} else if (data.type == "visit") {
|
|
181
181
|
this.events.emit("navigate", {path: data.path})
|
|
182
|
+
} else if (data.type == "dismissTo") {
|
|
183
|
+
this.events.emit("dismissTo", {path: data.path})
|
|
182
184
|
} else {
|
|
183
185
|
throw new Error(`Unknown command type for SystemTestBrowserHelper: ${data.type}`)
|
|
184
186
|
}
|
package/src/system-test.js
CHANGED
|
@@ -15,6 +15,8 @@ import {WebSocketServer} from "ws"
|
|
|
15
15
|
class ElementNotFoundError extends Error { }
|
|
16
16
|
|
|
17
17
|
export default class SystemTest {
|
|
18
|
+
static rootPath = "/blank?systemTest=true"
|
|
19
|
+
|
|
18
20
|
/**
|
|
19
21
|
* Gets the current system test instance
|
|
20
22
|
*
|
|
@@ -38,7 +40,7 @@ export default class SystemTest {
|
|
|
38
40
|
const systemTest = this.current()
|
|
39
41
|
|
|
40
42
|
await systemTest.communicator.sendCommand({type: "initialize"})
|
|
41
|
-
await systemTest.
|
|
43
|
+
await systemTest.dismissTo(SystemTest.rootPath)
|
|
42
44
|
|
|
43
45
|
try {
|
|
44
46
|
await systemTest.findByTestID("blankText", {useBaseSelector: false})
|
|
@@ -402,7 +404,7 @@ export default class SystemTest {
|
|
|
402
404
|
await this.startWebSocketServer()
|
|
403
405
|
|
|
404
406
|
// Visit the root page and wait for Expo to be loaded and the app to appear
|
|
405
|
-
await this.driverVisit(
|
|
407
|
+
await this.driverVisit(SystemTest.rootPath)
|
|
406
408
|
|
|
407
409
|
try {
|
|
408
410
|
await this.find("body > #root", {useBaseSelector: false})
|
|
@@ -614,4 +616,13 @@ export default class SystemTest {
|
|
|
614
616
|
async visit(path) {
|
|
615
617
|
await this.communicator.sendCommand({type: "visit", path})
|
|
616
618
|
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Dismisses to a path in the browser
|
|
622
|
+
*
|
|
623
|
+
* @param {string} path
|
|
624
|
+
*/
|
|
625
|
+
async dismissTo(path) {
|
|
626
|
+
await this.communicator.sendCommand({type: "dismissTo", path})
|
|
627
|
+
}
|
|
617
628
|
}
|
package/src/use-system-test.js
CHANGED
|
@@ -49,12 +49,31 @@ export default function useSystemTest({onInitialize, ...restArgs} = {}) {
|
|
|
49
49
|
const enabled = useMemo(() => isSystemTestEnabled(), [])
|
|
50
50
|
const systemTestBrowserHelper = enabled ? getSystemTestBrowserHelper() : null
|
|
51
51
|
const result = useMemo(() => ({enabled, systemTestBrowserHelper}), [enabled, systemTestBrowserHelper])
|
|
52
|
+
const instanceShared = useMemo(() => ({}), [])
|
|
52
53
|
|
|
54
|
+
instanceShared.enabled = enabled
|
|
55
|
+
instanceShared.router = router
|
|
56
|
+
|
|
57
|
+
// Resets navigation when instructed by the system test browser helper
|
|
58
|
+
const onSystemTestBrowserHelperDismissTo = useCallback(({path}) => {
|
|
59
|
+
if (instanceShared.enabled) {
|
|
60
|
+
try {
|
|
61
|
+
instanceShared.router.dismissTo(path)
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error(`Failed to dismiss to path "${path}": ${error.message}`)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}, [])
|
|
67
|
+
|
|
68
|
+
useEventEmitter(shared.systemTestBrowserHelper?.getEvents(), "dismissTo", onSystemTestBrowserHelperDismissTo)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
// Navigates when instructed by the system test browser helper and keeping history of screens
|
|
53
72
|
const onSystemTestBrowserHelperNavigate = useCallback(({path}) => {
|
|
54
|
-
if (enabled) {
|
|
55
|
-
router.navigate(path)
|
|
73
|
+
if (instanceShared.enabled) {
|
|
74
|
+
instanceShared.router.navigate(path)
|
|
56
75
|
}
|
|
57
|
-
}, [
|
|
76
|
+
}, [])
|
|
58
77
|
|
|
59
78
|
useEventEmitter(shared.systemTestBrowserHelper?.getEvents(), "navigate", onSystemTestBrowserHelperNavigate)
|
|
60
79
|
|