MCPcopy Create free account
hub / github.com/Effect-TS/effect / start

Function start

packages/ui/native/test/NativeRouter.test.ts:151–222  ·  view source on GitHub ↗
(launched: string | null = null, nested = false)

Source from the content-addressed store, hash-verified

149const NestedApp = makeApp(true)
150
151const start = async (launched: string | null = null, nested = false) => {
152 let router: Router.Router | undefined
153 const back = FakeDevice.module()
154 const linking = FakeDevice.module({
155 getInitialURL: () => Promise.resolve(launched),
156 openURL: () => Promise.resolve()
157 })
158 const a11y = FakeDevice.module()
159 const fake = FakeDevice.make("android", {
160 DeviceEventManager: back.module,
161 IntentAndroid: linking.module,
162 AccessibilityInfo: a11y.module
163 })
164 const mounted = await FakeFabric.mount((container) =>
165 Effect.gen(function*() {
166 const context = yield* Layer.build(
167 NativeRouter.layer({
168 routes: AppRoute,
169 prefixes: ["myapp://"]
170 })
171 )
172 router = Context.get(context, Router.Router)
173 return yield* Effect.flatMap(
174 RouterStack.props(AppRoute),
175 (props) => Renderer.mount(nested ? NestedApp : App, props, container)
176 ).pipe(Effect.provide(context))
177 }).pipe(Effect.provideService(Native.Device, fake.device))
178 )
179 const { fabric, settle } = mounted
180 const shown = (text: string) => FakeFabric.find(fabric.committed(), FakeFabric.byText(text)) !== undefined
181 const press = async (text: string) => {
182 FakeFabric.touch(fabric, mounted.find(FakeFabric.byText(text)))
183 await settle()
184 }
185 const back_ = async () => {
186 fake.emit("hardwareBackPress")
187 await settle()
188 }
189 const screens = () => {
190 const out: Array<FakeFabric.ShadowNode> = []
191 const walk = (nodes: ReadonlyArray<FakeFabric.ShadowNode>) => {
192 for (const n of nodes) {
193 if (n.props.position === "absolute") out.push(n)
194 walk(n.children)
195 }
196 }
197 walk(fabric.committed())
198 return out
199 }
200 const calls = (module: ReturnType<typeof FakeDevice.module>, name: string) =>
201 module.calls.filter(([method]) => method === name).map(([, ...args]) => args)
202 return {
203 ...mounted,
204 fake,
205 run: async (effect: Effect.Effect<unknown>) => {
206 Effect.runSync(effect)
207 await settle()
208 },

Callers 2

Calls 13

resolveMethod · 0.80
settleFunction · 0.70
callsFunction · 0.70
makeMethod · 0.65
mountMethod · 0.65
pipeMethod · 0.65
buildMethod · 0.65
getMethod · 0.65
propsMethod · 0.65
layerMethod · 0.45
provideMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected