Skip to content

Commit

Permalink
RIDE-5275 React devtools inspector integration (#185)
Browse files Browse the repository at this point in the history
This branch includes further fixes to devtools for integration with the inspector and will form the basis for the devtools release candidate

It relies on the release of a new version of DeveloperTools, which is also in review: Roblox/developer-tools#8

Note that DeveloperTools is only a dev_dependency to enable the inspector for the Roact examples project.
  • Loading branch information
RoFlection Bot committed Sep 30, 2021
1 parent 904839c commit a945a61
Show file tree
Hide file tree
Showing 26 changed files with 920 additions and 587 deletions.
7 changes: 1 addition & 6 deletions bin/runTests.lua → bin/run-devtools-integration-test.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
-- When opening examples.rbxp in RobloxStudio, the tests for React can be run in Studio using the following command:
-- debug.loadmodule(game.ReplicatedStorage.RunTests)()


local Packages = game.ReplicatedStorage.Packages

local RotrieverWorkspace = Packages._Workspace

-- ROBLOX FIXME: What's the more reasonable way of accessing this? Are all dev
Expand All @@ -21,7 +16,7 @@ end)

-- Run all tests, collect results, and report to stdout.
local result = JestRoblox.TestBootstrap:run(
{ RotrieverWorkspace },
{ game.StarterPlayer },
JestRoblox.Reporters.TextReporterQuiet,
{ extraEnvironment = RobloxJest.testEnv }
)
Expand Down
145 changes: 144 additions & 1 deletion docs/bench/data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lastUpdate": 1633037737571,
"lastUpdate": 1633039269132,
"repoUrl": "https://github.com/Roblox/roact-alignment",
"entries": {
"Concurrent Benchmark": [
Expand Down Expand Up @@ -1072,6 +1072,47 @@
"extra": "200 samples\nroblox-cli version: 0.498.0.4980396"
}
]
},
{
"commit": {
"author": {
"name": "Roblox",
"username": "Roblox"
},
"committer": {
"name": "Roblox",
"username": "Roblox"
},
"id": "b1224be94e4b5d679e8c950e597953f813bc3adb",
"message": "RIDE-5275 React devtools inspector integration",
"timestamp": "2021-09-30T21:49:35Z",
"url": "https://github.com/Roblox/roact-alignment/pull/185/commits/b1224be94e4b5d679e8c950e597953f813bc3adb"
},
"date": 1633039266712,
"tool": "roblox",
"benches": [
{
"name": "FrameRate#FPS",
"value": 57.1644,
"range": "±29.61%",
"unit": "ops/sec",
"extra": "601 samples\nroblox-cli version: 0.498.0.4980396"
},
{
"name": "FrameRate#Δt",
"value": 23.466,
"range": "±220.69%",
"unit": "ms/op",
"extra": "601 samples\nroblox-cli version: 0.498.0.4980396"
},
{
"name": "FirstRender#Δt",
"value": 95.8256,
"range": "±27.13%",
"unit": "ms/op",
"extra": "200 samples\nroblox-cli version: 0.498.0.4980396"
}
]
}
],
"Mount Deep Tree": [
Expand Down Expand Up @@ -1917,6 +1958,40 @@
"extra": "100 samples\nroblox-cli version: 0.498.0.4980396"
}
]
},
{
"commit": {
"author": {
"name": "Roblox",
"username": "Roblox"
},
"committer": {
"name": "Roblox",
"username": "Roblox"
},
"id": "b1224be94e4b5d679e8c950e597953f813bc3adb",
"message": "RIDE-5275 React devtools inspector integration",
"timestamp": "2021-09-30T21:49:35Z",
"url": "https://github.com/Roblox/roact-alignment/pull/185/commits/b1224be94e4b5d679e8c950e597953f813bc3adb"
},
"date": 1633039267496,
"tool": "roblox",
"benches": [
{
"name": "FrameRate#FPS",
"value": 16.5457,
"range": "±13.06%",
"unit": "ops/sec",
"extra": "100 samples\nroblox-cli version: 0.498.0.4980396"
},
{
"name": "FrameRate#Δt",
"value": 62.0302,
"range": "±20.47%",
"unit": "ms/op",
"extra": "100 samples\nroblox-cli version: 0.498.0.4980396"
}
]
}
],
"Mount Wide Tree": [
Expand Down Expand Up @@ -2762,6 +2837,40 @@
"extra": "50 samples\nroblox-cli version: 0.498.0.4980396"
}
]
},
{
"commit": {
"author": {
"name": "Roblox",
"username": "Roblox"
},
"committer": {
"name": "Roblox",
"username": "Roblox"
},
"id": "b1224be94e4b5d679e8c950e597953f813bc3adb",
"message": "RIDE-5275 React devtools inspector integration",
"timestamp": "2021-09-30T21:49:35Z",
"url": "https://github.com/Roblox/roact-alignment/pull/185/commits/b1224be94e4b5d679e8c950e597953f813bc3adb"
},
"date": 1633039268299,
"tool": "roblox",
"benches": [
{
"name": "FrameRate#FPS",
"value": 12.6705,
"range": "±13.69%",
"unit": "ops/sec",
"extra": "50 samples\nroblox-cli version: 0.498.0.4980396"
},
{
"name": "FrameRate#Δt",
"value": 80.7179,
"range": "±16.68%",
"unit": "ms/op",
"extra": "50 samples\nroblox-cli version: 0.498.0.4980396"
}
]
}
],
"Sierpinski Triangle Benchmark": [
Expand Down Expand Up @@ -3607,6 +3716,40 @@
"extra": "50 samples\nroblox-cli version: 0.498.0.4980396"
}
]
},
{
"commit": {
"author": {
"name": "Roblox",
"username": "Roblox"
},
"committer": {
"name": "Roblox",
"username": "Roblox"
},
"id": "b1224be94e4b5d679e8c950e597953f813bc3adb",
"message": "RIDE-5275 React devtools inspector integration",
"timestamp": "2021-09-30T21:49:35Z",
"url": "https://github.com/Roblox/roact-alignment/pull/185/commits/b1224be94e4b5d679e8c950e597953f813bc3adb"
},
"date": 1633039269128,
"tool": "roblox",
"benches": [
{
"name": "FrameRate#FPS",
"value": 82.7136,
"range": "±12.09%",
"unit": "ops/sec",
"extra": "50 samples\nroblox-cli version: 0.498.0.4980396"
},
{
"name": "FrameRate#Δt",
"value": 12.2622,
"range": "±11.75%",
"unit": "ms/op",
"extra": "50 samples\nroblox-cli version: 0.498.0.4980396"
}
]
}
]
}
Expand Down
5 changes: 4 additions & 1 deletion examples.project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"$className": "ReplicatedStorage",
"Packages": {
"$path": "Packages"
},
"DeveloperTools": {
"$className": "BindableEvent"
}
},

Expand All @@ -29,4 +32,4 @@
}
}
}
}
}
6 changes: 6 additions & 0 deletions examples/ProjectWorkspace/DeveloperTools.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- FIXME: This is a bit hacky; should rotriever provide a smoother way to access
-- dev dependencies?
-- return require(ReplicatedStorage.Packages._Index["roblox_developer-tools"]["developer-tools"])
return require(ReplicatedStorage.Packages._Index["roblox_developer-tools"]["DeveloperTools"])
2 changes: 1 addition & 1 deletion examples/ProjectWorkspace/React.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ local Workspace = ReplicatedStorage.Packages._Workspace

-- FIXME: This is a bit hacky; should rotriever provide a smoother way to access
-- local workspace members, even if they don't see use?
return require(Workspace.React.React)
return require(Workspace.React.React)
91 changes: 91 additions & 0 deletions examples/devtools-integration.spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
--[[
This test is currently run manually to verify the DeveloperTools library integrates into roact-alignment
roblox-cli run --load.place examples.project.json --run bin/run-devtools-integration-test.lua --lua.globals __NO_LOADMODULE__=false __EXPERIMENTAL__=true __PROFILE__=true
]]

return function()
describe("Devtools Integration", function()
local Packages = game.ReplicatedStorage.Packages
local Workspace = Packages._Workspace
local ProjectWorkspace = game.StarterPlayer.StarterPlayerScripts.RoactExamples.ProjectWorkspace
local inspector
local jestModule = require(Packages._Index["roblox_jest-roblox"]["jest-roblox"])
local RobloxJest = require(Workspace.RobloxJest.RobloxJest)
local expect = jestModule.Globals.expect
local jest = jestModule.Globals.jest
local devtools

local insert = table.insert

beforeEach(function()
local DeveloperTools = require(ProjectWorkspace.DeveloperTools)

inspector = DeveloperTools.forLibrary("UniversalApp", {})
devtools = inspector:initRoact(Workspace)
end)

it("can connect to a Roact tree and inspect its children and child branch nodes", function()
local ReactDevtoolsShared = Workspace.ReactDevtoolsShared.ReactDevtoolsShared
local utils = require(ReactDevtoolsShared.__tests__.utils)
local act = utils.act

local React = require(ProjectWorkspace.React)
local ReactRoblox = require(ProjectWorkspace.ReactRoblox)

-- Create a Roact root
act(function()
local root = ReactRoblox.createRoot(Instance.new("Frame"))
return root:render(React.createElement("TextLabel", { Text = "Test" }))
end)

-- Deliver new root to the store
local devtools = inspector.workers.reactTargetWatcher.devtools
devtools.bridge:_flush()

-- Check that the target has been added
local _, target = next(inspector.targets)

expect(target.name).toBe("#1")

-- Attach to the tree
target.listener.onEvent("TEST")

local worker = inspector.workers[target.id]

-- Stub the message handler
local spy = jest:fn()
worker.send = spy
worker:showChildren({})

expect(spy).toBeCalledWith(worker, {
eventName = "RoactInspector.ShowChildren",
path = {},
children = {
["1.2"] = {
Children = {},
Icon = "Branch",
Name = "TextLabel",
Path = {"1.2"},
}
}
})

worker:showBranch({"1.2"})

expect(spy.mock.calls[2][2].eventName).toBe("RoactInspector.ShowBranch")
expect(spy.mock.calls[2][2].branch).toEqual({
{
Icon = "Branch",
Name = "Root",
Link = "",
Source = "",
},
{
Name = "TextLabel",
Link = "",
Source = "",
}
})
end)
end)
end
3 changes: 2 additions & 1 deletion examples/hello-roact/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
return function()
local PlayerGui = game:GetService("Players").LocalPlayer.PlayerGui

local PlayerGui = game:GetService("Players").LocalPlayer.PlayerGui

local React = require(script.Parent.ProjectWorkspace.React)
local ReactRoblox = require(script.Parent.ProjectWorkspace.ReactRoblox)

Expand Down
5 changes: 5 additions & 0 deletions examples/init.client.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
local PlayerGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")

local DeveloperTools = require(script.ProjectWorkspace.DeveloperTools)

local inspector = DeveloperTools.forLibrary("ReactExamples")
inspector:initRoact(game:GetService("ReplicatedStorage").Packages._Workspace)

local exampleData = {
{
name = "hello-roact",
Expand Down
Loading

0 comments on commit a945a61

Please sign in to comment.