local x=require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\106\101\115\116-\103\108\111\098\097\108\115")local s=x.beforeEach local F=x.expect local z=x.describe local W=x.it local M=x.jest local S local p local r local Q s(function()M.resetModules()r=require("\046\046")p=require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\114\101\097\099\116-\114\111\098\108\111\120")Q=require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\115\099\104\101\100\117\108\101\114")S=require("\064\112\107\103\047\064\106\115\100\111\116\108\117\097\047\114\101\097\099\116")end)z("\112\099\097\108\108 \100\101\112\116\104",function()W("\115\104\111\117\108\100 \114\101\110\100\101\114 \101\118\101\110 \119\104\101\110 \112\099\097\108\108 \100\101\112\116\104 \108\105\109\105\116 \105\115 \104\105\116",function()local function x(x)S.useLayoutEffect(function()Q.unstable_yieldValue("\076\097\121\111\117\116 \069\102\102\101\099\116")end)return r.createElement("\084\101\120\116\076\097\098\101\108",{Text="\076\097\121\111\117\116"})end local function s(s)local F={[1]=function()return r.createElement(x)end}for x=2,500,1 do F[x]=function()return r.createElement(F[x-1])end end return F[s]end local z=r.createElement("\070\114\097\109\101",nil,r.createElement(s(500)))local W=Instance.new("\070\111\108\100\101\114")local M=p.createRoot(W);(F(function()M:render(z)Q.unstable_flushAllWithoutAsserting()end)).toWarnDev({})local J=W:GetChildren();(F(#J)).toBe(1)end)end)
--!strict
--[[
	* Copyright (c) Roblox Corporation. All rights reserved.
	* Licensed under the MIT License (the "License");
	* you may not use this file except in compliance with the License.
	* You may obtain a copy of the License at
	*
	*     https://opensource.org/licenses/MIT
	*
	* Unless required by applicable law or agreed to in writing, software
	* distributed under the License is distributed on an "AS IS" BASIS,
	* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	* See the License for the specific language governing permissions and
	* limitations under the License.
]]

local JestGlobals = require("@pkg/@jsdotlua/jest-globals")
local beforeEach = JestGlobals.beforeEach
local jestExpect = JestGlobals.expect
local describe = JestGlobals.describe
local it = JestGlobals.it
local jest = JestGlobals.jest
local React
local ReactRoblox
local RoactCompat
local Scheduler

beforeEach(function()
	jest.resetModules()
	RoactCompat = require("..")
	ReactRoblox = require("@pkg/@jsdotlua/react-roblox")
	Scheduler = require("@pkg/@jsdotlua/scheduler")
	React = require("@pkg/@jsdotlua/react")
end)

describe("pcall depth", function()
	-- ROBLOX: we no longer warn, but this test is a good way to programmaitcally create a complex tree
	it("should render even when pcall depth limit is hit", function()
		local function LayoutEffect(props)
			React.useLayoutEffect(function()
				Scheduler.unstable_yieldValue("Layout Effect")
			end)
			return RoactCompat.createElement("TextLabel", { Text = "Layout" })
		end

		local function constructDeepTree(n)
			local constructTreeTable = {
				[1] = function()
					return RoactCompat.createElement(LayoutEffect)
				end,
			}
			for i = 2, 500 do
				constructTreeTable[i] = function()
					return RoactCompat.createElement(constructTreeTable[i - 1])
				end
			end
			return constructTreeTable[n]
		end

		local DeepTree = RoactCompat.createElement(
			"Frame",
			nil,
			RoactCompat.createElement(constructDeepTree(500))
		)

		local instance = Instance.new("Folder")
		local root = ReactRoblox.createRoot(instance)
		jestExpect(function()
			root:render(DeepTree)
			Scheduler.unstable_flushAllWithoutAsserting()
		end).toWarnDev({})
		local children = instance:GetChildren()

		jestExpect(#children).toBe(1)
	end)
end)
