Skip to content

Commit 9ad3447

Browse files
author
RoFlection Bot
committed
enable ci (#35)
1 parent 6f06252 commit 9ad3447

File tree

6 files changed

+106
-66
lines changed

6 files changed

+106
-66
lines changed

foreman.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[tools]
2+
rojo = { source = "rojo-rbx/rojo", version = "7.2.1" }
23
rotrieve = { source = "roblox/rotriever", version = "0.5.4" }
34
selene = { source = "Kampfkarren/selene", version = "0.20.0" }
4-
stylua = { source = "JohnnyMorganz/StyLua", version = "=0.14.2" }
5+
stylua = { source = "JohnnyMorganz/StyLua", version = "0.14.2" }

src/__tests__/events.spec.lua

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ local eventTypes = {
3737
}
3838
-- ROBLOX deviation END
3939

40+
-- ROBLOX deviation START: subset with implemented methods in RTL, but not implemented in DTL
41+
local unhandledEventTypes = {
42+
{
43+
type = "Mouse",
44+
events = {
45+
{ fireEventName = "mouseEnter" },
46+
{ fireEventName = "mouseLeave" },
47+
},
48+
elementType = "TextButton",
49+
},
50+
{
51+
type = "Pointer",
52+
events = {
53+
{ fireEventName = "pointerEnter" },
54+
{ fireEventName = "pointerLeave" },
55+
},
56+
elementType = "TextButton",
57+
},
58+
}
59+
-- ROBLOX deviation END
60+
4061
Array.forEach(eventTypes, function(ref)
4162
local type_, events, elementType, init = ref.type, ref.events, ref.elementType, ref.init
4263
describe(("%s Events"):format(type_), function()
@@ -137,4 +158,23 @@ end)
137158
-- expect(handleBubbledFocus).toHaveBeenCalledTimes(1)
138159
-- end)
139160
-- ROBLOX deviation END
161+
162+
-- ROBLOX deviation START: No upstream equivalent
163+
164+
Array.forEach(unhandledEventTypes, function(ref)
165+
local type_, events, elementType, init = ref.type, ref.events, ref.elementType, ref.init
166+
describe(("Unhandled %s Events"):format(type_), function()
167+
Array.forEach(events, function(event: { fireEventName: string })
168+
local propName = ("on%s%s"):format(event.fireEventName:sub(1, 1):upper(), event.fireEventName:sub(2))
169+
test(("triggers %s"):format(propName), function()
170+
local ref = React.createRef()
171+
render(React.createElement(elementType, { ref = ref }))
172+
expect(function()
173+
fireEvent[event.fireEventName](ref.current, init)
174+
end).toThrowError("Event not found")
175+
end)
176+
end)
177+
end)
178+
end)
179+
-- ROBLOX deviation END
140180
return {}

src/__tests__/new-act.spec.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type Promise<T> = LuauPolyfill.Promise<T>
1515

1616
local Promise = require(Packages.Promise)
1717

18-
local asyncAct
18+
local asyncAct, _consoleErrorMock
1919

2020
-- ROBLOX deviation: Mock is not supported
2121
-- local _testUtils = require(script.Parent.Parent.jsHelpers["react-dom"]["test-utils"])
@@ -37,8 +37,7 @@ beforeEach(function()
3737
end)
3838

3939
afterEach(function()
40-
-- ROBLOX deviation: mockRestore is unavailable, resetting manually
41-
-- consoleErrorMock.mockRestore()
40+
(console.error :: any):mockRestore()
4241
console.error = originalConsoleError
4342
end)
4443

src/fire-event.lua

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,24 @@ fireEvent.pointerLeave = function(...: any)
5151
return fireEvent.pointerOut(...)
5252
end
5353

54-
local select_ = fireEvent.select
55-
fireEvent.select = function(node, init)
56-
select_(node, init)
57-
-- React tracks this event only on focused inputs
58-
node.focus()
54+
-- ROBLOX deviation START: no select event available
55+
-- local select_ = fireEvent.select
56+
-- fireEvent.select = function(node, init)
57+
-- select_(node, init)
58+
-- -- React tracks this event only on focused inputs
59+
-- node.focus()
5960

60-
-- React creates this event when one of the following native events happens
61-
-- - contextMenu
62-
-- - mouseUp
63-
-- - dragEnd
64-
-- - keyUp
65-
-- - keyDown
66-
-- so we can use any here
67-
-- @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/SelectEventPlugin.js#L203-L224
68-
fireEvent.keyUp(node, init)
69-
end
61+
-- -- React creates this event when one of the following native events happens
62+
-- -- - contextMenu
63+
-- -- - mouseUp
64+
-- -- - dragEnd
65+
-- -- - keyUp
66+
-- -- - keyDown
67+
-- -- so we can use any here
68+
-- -- @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/SelectEventPlugin.js#L203-L224
69+
-- fireEvent.keyUp(node, init)
70+
-- end
71+
-- ROBLOX deviation END
7072

7173
-- React event system tracks native focusout/focusin events for
7274
-- running blur/focus handlers

src/init.lua

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,48 @@
11
-- ROBLOX upstream: https://github.com/testing-library/react-testing-library/blob/v12.1.5/src/index.js
2+
local Packages = script.Parent
3+
4+
local JestGlobals = require(Packages.JestGlobals)
5+
local afterEach = JestGlobals.afterEach
6+
7+
local LuauPolyfill = require(Packages.LuauPolyfill)
8+
local Object = LuauPolyfill.Object
9+
10+
local jsHelpers = script.jsHelpers
11+
local isCallable = require(jsHelpers.isCallable)
12+
13+
local exports = {} :: { [string]: any }
14+
15+
local cleanup = require(script.pure).cleanup
16+
-- if we're running in a test runner that supports afterEach
17+
-- or teardown then we'll automatically run cleanup afterEach test
18+
-- this ensures that tests run in isolation from each other
19+
-- if you don't like this then either import the `pure` module
20+
-- or set the RTL_SKIP_AUTO_CLEANUP env variable to 'true'.
21+
if
22+
-- ROBLOX deviation START: adapt conditions
23+
not _G.RTL_SKIP_AUTO_CLEANUP
24+
-- ROBLOX deviation END
25+
then
26+
-- ignore teardown() in code coverage because Jest does not support it
27+
--[[ istanbul ignore else ]]
28+
if isCallable(afterEach) then
29+
afterEach(function()
30+
cleanup()
31+
end)
32+
-- -- ROBLOX deviation START: does not apply
33+
-- -- elseif typeof(teardown) == "function" then
34+
-- -- -- Block is guarded by `typeof` check.
35+
-- -- -- eslint does not support `typeof` guards.
36+
-- -- -- eslint-disable-next-line no-undef
37+
-- -- teardown(function()
38+
-- -- cleanup()
39+
-- -- end)
40+
-- -- ROBLOX deviation END
41+
end
42+
end
43+
44+
Object.assign(exports, require(script.pure))
45+
246
-- ROBLOX deviation START: reexport types
347
local typesModule = require(script.types)
448
export type within = typesModule.within
@@ -111,50 +155,4 @@ export type cleanup = typesModule.cleanup
111155
export type act = typesModule.act
112156
-- ROBLOX deviation END
113157

114-
-- ROBLOX comment: wrap in function to pass afterEach function
115-
116-
local Packages = script.Parent
117-
118-
local JestGlobals = require(Packages.JestGlobals)
119-
local afterEach = JestGlobals.afterEach
120-
121-
local LuauPolyfill = require(Packages.LuauPolyfill)
122-
local Object = LuauPolyfill.Object
123-
124-
local jsHelpers = script.jsHelpers
125-
local isCallable = require(jsHelpers.isCallable)
126-
127-
local exports = {} :: { [string]: any }
128-
129-
local cleanup = require(script.pure).cleanup
130-
-- if we're running in a test runner that supports afterEach
131-
-- or teardown then we'll automatically run cleanup afterEach test
132-
-- this ensures that tests run in isolation from each other
133-
-- if you don't like this then either import the `pure` module
134-
-- or set the RTL_SKIP_AUTO_CLEANUP env variable to 'true'.
135-
if
136-
-- ROBLOX deviation START: adapt conditions
137-
not _G.RTL_SKIP_AUTO_CLEANUP
138-
-- ROBLOX deviation END
139-
then
140-
-- ignore teardown() in code coverage because Jest does not support it
141-
--[[ istanbul ignore else ]]
142-
if isCallable(afterEach) then
143-
afterEach(function()
144-
cleanup()
145-
end)
146-
-- -- ROBLOX deviation START: does not apply
147-
-- -- elseif typeof(teardown) == "function" then
148-
-- -- -- Block is guarded by `typeof` check.
149-
-- -- -- eslint does not support `typeof` guards.
150-
-- -- -- eslint-disable-next-line no-undef
151-
-- -- teardown(function()
152-
-- -- cleanup()
153-
-- -- end)
154-
-- -- ROBLOX deviation END
155-
end
156-
end
157-
158-
Object.assign(exports, require(script.pure))
159-
160158
return exports

src/jsHelpers/matchers.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local Array = LuauPolyfill.Array
55

66
local exports = {}
77

8-
local function toMatchInlineSnapshot(self, received, expected)
8+
local function toMatchInlineSnapshot(self, received, expected: string)
99
local function serialize(received)
1010
if typeof(received) == "string" then
1111
return received

0 commit comments

Comments
 (0)