-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract logic from TestRunner (#6390)
## Summary This PR extracts from TestRunner logic that isn't directly related to running tests. ## Test plan
- Loading branch information
Showing
5 changed files
with
114 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
apps/common-app/src/examples/RuntimeTests/ReJest/TestRunner/CallTrackerRegistry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { makeMutable } from 'react-native-reanimated'; | ||
import type { TrackerCallCount } from '../types'; | ||
|
||
let callCallTrackerRegistryJS: Record<string, number> = {}; | ||
const callCallTrackerRegistryUI = makeMutable<Record<string, number>>({}); | ||
function callTrackerJS(name: string) { | ||
if (!callCallTrackerRegistryJS[name]) { | ||
callCallTrackerRegistryJS[name] = 0; | ||
} | ||
callCallTrackerRegistryJS[name]++; | ||
} | ||
|
||
export class CallTrackerRegistry { | ||
public callTracker(name: string) { | ||
'worklet'; | ||
if (_WORKLET) { | ||
if (!callCallTrackerRegistryUI.value[name]) { | ||
callCallTrackerRegistryUI.value[name] = 0; | ||
} | ||
callCallTrackerRegistryUI.value[name]++; | ||
callCallTrackerRegistryUI.value = { ...callCallTrackerRegistryUI.value }; | ||
} else { | ||
callTrackerJS(name); | ||
} | ||
} | ||
|
||
public getTrackerCallCount(name: string): TrackerCallCount { | ||
return { | ||
name, | ||
onJS: callCallTrackerRegistryJS[name] ?? 0, | ||
onUI: callCallTrackerRegistryUI.value[name] ?? 0, | ||
}; | ||
} | ||
|
||
public resetRegistry() { | ||
callCallTrackerRegistryUI.value = {}; | ||
callCallTrackerRegistryJS = {}; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
apps/common-app/src/examples/RuntimeTests/ReJest/TestRunner/NotificationRegistry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { runOnJS } from 'react-native-reanimated'; | ||
|
||
const notificationRegistry: Record<string, boolean> = {}; | ||
function notifyJS(name: string) { | ||
notificationRegistry[name] = true; | ||
} | ||
|
||
export class NotificationRegistry { | ||
public notify(name: string) { | ||
'worklet'; | ||
if (_WORKLET) { | ||
runOnJS(notifyJS)(name); | ||
} else { | ||
notifyJS(name); | ||
} | ||
} | ||
|
||
public async waitForNotify(name: string) { | ||
return new Promise(resolve => { | ||
const interval = setInterval(() => { | ||
if (notificationRegistry[name]) { | ||
clearInterval(interval); | ||
resolve(true); | ||
} | ||
}, 10); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters