local U=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=U.beforeEach local Z=U.describe local q=U.it local i=U.jest Z("\084\114\097\099\105\110\103",function()local U=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 Z=U.expect local r S(function()i.resetModules()r=(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")).tracing end)q("\115\104\111\117\108\100 \114\101\116\117\114\110 \116\104\101 \118\097\108\117\101 \111\102 \097 \116\114\097\099\101\100 \102\117\110\099\116\105\111\110",function()(Z(r.unstable_trace("\097\114\098\105\116\114\097\114\121",0,function()return 123 end))).toBe(123)end)q("\115\104\111\117\108\100 \114\101\116\117\114\110 \116\104\101 \118\097\108\117\101 \111\102 \097 \119\114\097\112\112\101\100 \102\117\110\099\116\105\111\110",function()local U r.unstable_trace("\097\114\098\105\116\114\097\114\121",0,function()U=r.unstable_wrap(function()return 123 end)end);(Z(U())).toBe(123)end)q("\115\104\111\117\108\100 \101\120\101\099\117\116\101 \116\114\097\099\101\100 \099\097\108\108\098\097\099\107\115",function()local U=false r.unstable_trace("\115\111\109\101 \101\118\101\110\116",0,function()U=true end);(Z(U)).toBe(true)end)q("\115\104\111\117\108\100 \114\101\116\117\114\110 \116\104\101 \118\097\108\117\101 \111\102 \097 \099\108\101\097\114 \102\117\110\099\116\105\111\110",function()(Z(r.unstable_clear(function()return 123 end))).toBe(123)end)q("\115\104\111\117\108\100 \101\120\101\099\117\116\101 \119\114\097\112\112\101\100 \099\097\108\108\098\097\099\107\115",function()local U=false local S=r.unstable_wrap(function()U=true end)S();(Z(U)).toBe(true)end)end)
-- ROBLOX upstream: https://github.com/facebook/react/blob/9abc2785cb070148d64fae81e523246b90b92016/packages/scheduler/src/__tests__/Tracing-test.js
-- /**
--  * Copyright (c) Facebook, Inc. and its affiliates.
--  *
--  * This source code is licensed under the MIT license found in the
--  * LICENSE file in the root directory of this source tree.
--  *
--  * @jest-environment node
--  */

local JestGlobals = require("@pkg/@jsdotlua/jest-globals")
local beforeEach = JestGlobals.beforeEach
local describe = JestGlobals.describe
local it = JestGlobals.it
local jest = JestGlobals.jest

describe("Tracing", function()
	local JestGlobals = require("@pkg/@jsdotlua/jest-globals")
	local jestExpect = JestGlobals.expect

	local SchedulerTracing

	beforeEach(function()
		jest.resetModules()

		SchedulerTracing = require("@pkg/@jsdotlua/scheduler").tracing
	end)

	it("should return the value of a traced function", function()
		jestExpect(SchedulerTracing.unstable_trace("arbitrary", 0, function()
			return 123
		end)).toBe(123)
	end)

	it("should return the value of a wrapped function", function()
		local wrapped
		SchedulerTracing.unstable_trace("arbitrary", 0, function()
			wrapped = SchedulerTracing.unstable_wrap(function()
				return 123
			end)
		end)
		jestExpect(wrapped()).toBe(123)
	end)

	it("should execute traced callbacks", function()
		local done = false

		SchedulerTracing.unstable_trace("some event", 0, function()
			done = true
		end)

		jestExpect(done).toBe(true)
	end)

	it("should return the value of a clear function", function()
		jestExpect(SchedulerTracing.unstable_clear(function()
			return 123
		end)).toBe(123)
	end)

	it("should execute wrapped callbacks", function()
		local done = false
		local wrappedCallback = SchedulerTracing.unstable_wrap(function()
			done = true
		end)

		wrappedCallback()
		jestExpect(done).toBe(true)
	end)
end)
