xref: /expo/apps/bare-expo/e2e/setup/setupSockets.js (revision 4e9295b9)
1import * as detox from 'detox';
2import { startAsync, send } from '../../relapse/server';
3
4let stopAsync;
5beforeAll(async () => {
6  // const customConsole = Object.assign(Object.create(console), {
7  //   // We only want warnings and errors from the client to show up in the jest logs
8  //   log() {},
9  //   // RN saves a reference to the original implementation of `console.error` and calls it via
10  //   // `console._errorOriginal` and the invocation is sent to Detox
11  //   _errorOriginal(...args) {
12  //     console.error(...args);
13  //   },
14  // });
15
16  // The testing modules we want to share with the client
17  const API = {
18    device: detox.device,
19    detox,
20    // Using this will cause a stack overflow
21    // console: customConsole,
22  };
23
24  stopAsync = await startAsync({
25    onConnect: () => {
26      send({ globals: Object.keys(API) });
27    },
28    onEvent: (invocation, props) => {
29      const [module, method] = invocation.split('.');
30      API[module][method](...props);
31    },
32  });
33});
34
35afterAll(async () => {
36  if (stopAsync) {
37    await stopAsync();
38  }
39});
40