Skip to content

Commit a671d3c

Browse files
author
RoFlection Bot
committed
Port/reexport types (#31)
1 parent b54f738 commit a671d3c

File tree

3 files changed

+321
-0
lines changed

3 files changed

+321
-0
lines changed

src/init.lua

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,116 @@
11
-- ROBLOX upstream: https://github.com/testing-library/react-testing-library/blob/v12.1.5/src/index.js
2+
-- ROBLOX deviation START: reexport types
3+
local typesModule = require(script.types)
4+
export type within = typesModule.within
5+
export type QueryByBoundAttribute<T = Instance> = typesModule.QueryByBoundAttribute<T>
6+
export type AllByBoundAttribute<T = Instance> = typesModule.AllByBoundAttribute<T>
7+
export type FindAllByBoundAttribute<T = Instance> = typesModule.FindAllByBoundAttribute<T>
8+
export type GetByBoundAttribute<T = Instance> = typesModule.GetByBoundAttribute<T>
9+
export type FindByBoundAttribute<T = Instance> = typesModule.FindByBoundAttribute<T>
10+
export type QueryByText<T = Instance> = typesModule.QueryByText<T>
11+
export type AllByText<T = Instance> = typesModule.AllByText<T>
12+
export type FindAllByText<T = Instance> = typesModule.FindAllByText<T>
13+
export type GetByText<T = Instance> = typesModule.GetByText<T>
14+
export type FindByText<T = Instance> = typesModule.FindByText<T>
15+
export type getByPlaceholderText<T = Instance> = typesModule.getByPlaceholderText<T>
16+
export type getAllByPlaceholderText<T = Instance> = typesModule.getAllByPlaceholderText<T>
17+
export type queryByPlaceholderText<T = Instance> = typesModule.queryByPlaceholderText<T>
18+
export type queryAllByPlaceholderText<T = Instance> = typesModule.queryAllByPlaceholderText<T>
19+
export type findByPlaceholderText<T = Instance> = typesModule.findByPlaceholderText<T>
20+
export type findAllByPlaceholderText<T = Instance> = typesModule.findAllByPlaceholderText<T>
21+
export type getByText<T = Instance> = typesModule.getByText<T>
22+
export type getAllByText<T = Instance> = typesModule.getAllByText<T>
23+
export type queryByText<T = Instance> = typesModule.queryByText<T>
24+
export type queryAllByText<T = Instance> = typesModule.queryAllByText<T>
25+
export type findByText<T = Instance> = typesModule.findByText<T>
26+
export type findAllByText<T = Instance> = typesModule.findAllByText<T>
27+
export type getByDisplayValue<T = Instance> = typesModule.getByDisplayValue<T>
28+
export type getAllByDisplayValue<T = Instance> = typesModule.getAllByDisplayValue<T>
29+
export type queryByDisplayValue<T = Instance> = typesModule.queryByDisplayValue<T>
30+
export type queryAllByDisplayValue<T = Instance> = typesModule.queryAllByDisplayValue<T>
31+
export type findByDisplayValue<T = Instance> = typesModule.findByDisplayValue<T>
32+
export type findAllByDisplayValue<T = Instance> = typesModule.findAllByDisplayValue<T>
33+
export type getByTestId<T = Instance> = typesModule.getByTestId<T>
34+
export type getAllByTestId<T = Instance> = typesModule.getAllByTestId<T>
35+
export type queryByTestId<T = Instance> = typesModule.queryByTestId<T>
36+
export type queryAllByTestId<T = Instance> = typesModule.queryAllByTestId<T>
37+
export type findByTestId<T = Instance> = typesModule.findByTestId<T>
38+
export type findAllByTestId<T = Instance> = typesModule.findAllByTestId<T>
39+
export type WithSuggest = typesModule.WithSuggest
40+
export type GetErrorFunction<Argument = any> = typesModule.GetErrorFunction<Argument>
41+
export type SelectorMatcherOptions = typesModule.SelectorMatcherOptions
42+
export type QueryByAttribute = typesModule.QueryByAttribute
43+
export type AllByAttribute = typesModule.AllByAttribute
44+
export type queryByAttribute = typesModule.queryByAttribute
45+
export type queryAllByAttribute = typesModule.queryAllByAttribute
46+
export type getElementError = typesModule.getElementError
47+
export type QueryMethod<Argument, Return> = typesModule.QueryMethod<Argument, Return>
48+
export type QueryBy<Argument> = typesModule.QueryBy<Argument>
49+
export type GetAllBy<Argument> = typesModule.GetAllBy<Argument>
50+
export type FindAllBy<Argument> = typesModule.FindAllBy<Argument>
51+
export type GetBy<Argument> = typesModule.GetBy<Argument>
52+
export type FindBy<Argument> = typesModule.FindBy<Argument>
53+
export type BuiltQueryMethods<Argument> = typesModule.BuiltQueryMethods<Argument>
54+
export type buildQueries<Argument> = typesModule.buildQueries<Argument>
55+
export type Screen<Q> = typesModule.Screen<Q>
56+
export type screen = typesModule.screen
57+
export type waitForOptions = typesModule.waitForOptions
58+
export type waitFor = typesModule.waitFor
59+
export type waitForElementToBeRemoved<T> = typesModule.waitForElementToBeRemoved<T>
60+
export type MatcherFunction = typesModule.MatcherFunction
61+
export type Matcher = typesModule.Matcher
62+
export type ByRoleMatcher = typesModule.ByRoleMatcher
63+
export type NormalizerFn = typesModule.NormalizerFn
64+
export type NormalizerOptions = typesModule.NormalizerOptions
65+
export type MatcherOptions = typesModule.MatcherOptions
66+
export type Match = typesModule.Match
67+
export type DefaultNormalizerOptio = typesModule.DefaultNormalizerOptions
68+
export type getDefaultNormalizer = typesModule.getDefaultNormalizer
69+
export type getNodeText = typesModule.getNodeText
70+
export type EventType = typesModule.EventType
71+
export type FireFunction = typesModule.FireFunction
72+
export type FireObject = typesModule.FireObject
73+
export type CreateFunction = typesModule.CreateFunction
74+
export type CreateObject = typesModule.CreateObject
75+
export type createEvent = typesModule.createEvent
76+
export type fireEvent = typesModule.fireEvent
77+
export type BoundFunction<T> = typesModule.BoundFunction<T>
78+
export type BoundFunctions<Q> = typesModule.BoundFunctions<Q>
79+
export type Query = typesModule.Query
80+
export type Queries = typesModule.Queries
81+
export type getQueriesForElement = typesModule.getQueriesForElement
82+
export type PrettyDOMOptions = typesModule.PrettyDOMOptions
83+
export type prettyDOM = typesModule.prettyDOM
84+
export type logDOM = typesModule.logDOM
85+
export type prettyFormat_Colors = typesModule.prettyFormat_Colors
86+
export type prettyFormat_CompareKeys = typesModule.prettyFormat_CompareKeys
87+
export type prettyFormat_Options = typesModule.prettyFormat_Options
88+
export type prettyFormat_OptionsReceived = typesModule.prettyFormat_OptionsReceived
89+
export type prettyFormat_OldPlugin = typesModule.prettyFormat_OldPlugin
90+
export type prettyFormat_NewPlugin = typesModule.prettyFormat_NewPlugin
91+
export type prettyFormat_Plugin = typesModule.prettyFormat_Plugin
92+
export type prettyFormat_Plugins = typesModule.prettyFormat_Plugins
93+
export type prettyFormat_PrettyFormatOptions = typesModule.prettyFormat_PrettyFormatOptions
94+
export type prettyFormat_Printer = typesModule.prettyFormat_Printer
95+
export type prettyFormat_Refs = typesModule.prettyFormat_Refs
96+
export type prettyFormat_Theme = typesModule.prettyFormat_Theme
97+
export type Config = typesModule.Config
98+
export type ConfigFn = typesModule.ConfigFn
99+
export type configure = typesModule.configure
100+
export type getConfig = typesModule.getConfig
101+
export type QueryOptions = typesModule.QueryOptions
102+
export type QueryArgs = typesModule.QueryArgs
103+
export type Suggestion = typesModule.Suggestion
104+
export type Variant = typesModule.Variant
105+
export type Method = typesModule.Method
106+
export type getSuggestedQuery = typesModule.getSuggestedQuery
107+
export type RenderResult<Q> = typesModule.RenderResult<Q>
108+
export type RenderOptions<Q, Container, BaseElement> = typesModule.RenderOptions<Q, Container, BaseElement>
109+
export type render<Q, Container = Instance, BaseElement = Container> = typesModule.render<Q, Container, BaseElement>
110+
export type cleanup = typesModule.cleanup
111+
export type act = typesModule.act
112+
-- ROBLOX deviation END
113+
2114
-- ROBLOX comment: wrap in function to pass afterEach function
3115
return function(afterEach)
4116
local Packages = script.Parent
File renamed without changes.

src/types/init.lua

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
-- ROBLOX upstream: https://github.com/testing-library/react-testing-library/blob/v12.1.5/types/index.d.ts
2+
local Packages = script.Parent.Parent
3+
local LuauPolyfill = require(Packages.LuauPolyfill)
4+
local Object = LuauPolyfill.Object
5+
type Array<T> = LuauPolyfill.Array<T>
6+
type Object = LuauPolyfill.Object
7+
8+
type React_ReactElement = any
9+
type DocumentFragment = any
10+
type React_JSXElementConstructor<T> = any
11+
12+
local exports = {}
13+
14+
-- TypeScript Version: 3.8
15+
local domModule = require(Packages.DomTestingLibrary)
16+
local queries = domModule.queries
17+
type typeofQueries = typeof(queries)
18+
19+
-- ROBLOX deviation START: ReactDOM not available
20+
type Renderer = any
21+
-- ROBLOX deviation END
22+
local reactAct = require(script.Parent.jsHelpers["react-dom"]["test-utils"]).act
23+
Object.assign(exports, require(Packages.DomTestingLibrary))
24+
25+
export type within = domModule.within
26+
export type QueryByBoundAttribute<T = Instance> = domModule.QueryByBoundAttribute<T>
27+
export type AllByBoundAttribute<T = Instance> = domModule.AllByBoundAttribute<T>
28+
export type FindAllByBoundAttribute<T = Instance> = domModule.FindAllByBoundAttribute<T>
29+
export type GetByBoundAttribute<T = Instance> = domModule.GetByBoundAttribute<T>
30+
export type FindByBoundAttribute<T = Instance> = domModule.FindByBoundAttribute<T>
31+
export type QueryByText<T = Instance> = domModule.QueryByText<T>
32+
export type AllByText<T = Instance> = domModule.AllByText<T>
33+
export type FindAllByText<T = Instance> = domModule.FindAllByText<T>
34+
export type GetByText<T = Instance> = domModule.GetByText<T>
35+
export type FindByText<T = Instance> = domModule.FindByText<T>
36+
export type getByPlaceholderText<T = Instance> = domModule.getByPlaceholderText<T>
37+
export type getAllByPlaceholderText<T = Instance> = domModule.getAllByPlaceholderText<T>
38+
export type queryByPlaceholderText<T = Instance> = domModule.queryByPlaceholderText<T>
39+
export type queryAllByPlaceholderText<T = Instance> = domModule.queryAllByPlaceholderText<T>
40+
export type findByPlaceholderText<T = Instance> = domModule.findByPlaceholderText<T>
41+
export type findAllByPlaceholderText<T = Instance> = domModule.findAllByPlaceholderText<T>
42+
export type getByText<T = Instance> = domModule.getByText<T>
43+
export type getAllByText<T = Instance> = domModule.getAllByText<T>
44+
export type queryByText<T = Instance> = domModule.queryByText<T>
45+
export type queryAllByText<T = Instance> = domModule.queryAllByText<T>
46+
export type findByText<T = Instance> = domModule.findByText<T>
47+
export type findAllByText<T = Instance> = domModule.findAllByText<T>
48+
export type getByDisplayValue<T = Instance> = domModule.getByDisplayValue<T>
49+
export type getAllByDisplayValue<T = Instance> = domModule.getAllByDisplayValue<T>
50+
export type queryByDisplayValue<T = Instance> = domModule.queryByDisplayValue<T>
51+
export type queryAllByDisplayValue<T = Instance> = domModule.queryAllByDisplayValue<T>
52+
export type findByDisplayValue<T = Instance> = domModule.findByDisplayValue<T>
53+
export type findAllByDisplayValue<T = Instance> = domModule.findAllByDisplayValue<T>
54+
export type getByTestId<T = Instance> = domModule.getByTestId<T>
55+
export type getAllByTestId<T = Instance> = domModule.getAllByTestId<T>
56+
export type queryByTestId<T = Instance> = domModule.queryByTestId<T>
57+
export type queryAllByTestId<T = Instance> = domModule.queryAllByTestId<T>
58+
export type findByTestId<T = Instance> = domModule.findByTestId<T>
59+
export type findAllByTestId<T = Instance> = domModule.findAllByTestId<T>
60+
export type WithSuggest = domModule.WithSuggest
61+
export type GetErrorFunction<Argument = any> = domModule.GetErrorFunction<Argument>
62+
export type SelectorMatcherOptions = domModule.SelectorMatcherOptions
63+
export type QueryByAttribute = domModule.QueryByAttribute
64+
export type AllByAttribute = domModule.AllByAttribute
65+
export type queryByAttribute = domModule.queryByAttribute
66+
export type queryAllByAttribute = domModule.queryAllByAttribute
67+
export type getElementError = domModule.getElementError
68+
export type QueryMethod<Argument, Return> = domModule.QueryMethod<Argument, Return>
69+
export type QueryBy<Argument> = domModule.QueryBy<Argument>
70+
export type GetAllBy<Argument> = domModule.GetAllBy<Argument>
71+
export type FindAllBy<Argument> = domModule.FindAllBy<Argument>
72+
export type GetBy<Argument> = domModule.GetBy<Argument>
73+
export type FindBy<Argument> = domModule.FindBy<Argument>
74+
export type BuiltQueryMethods<Argument> = domModule.BuiltQueryMethods<Argument>
75+
export type buildQueries<Argument> = domModule.buildQueries<Argument>
76+
export type Screen<Q> = domModule.Screen<Q>
77+
export type screen = domModule.screen
78+
export type waitForOptions = domModule.waitForOptions
79+
export type waitFor = domModule.waitFor
80+
export type waitForElementToBeRemoved<T> = domModule.waitForElementToBeRemoved<T>
81+
export type MatcherFunction = domModule.MatcherFunction
82+
export type Matcher = domModule.Matcher
83+
export type ByRoleMatcher = domModule.ByRoleMatcher
84+
export type NormalizerFn = domModule.NormalizerFn
85+
export type NormalizerOptions = domModule.NormalizerOptions
86+
export type MatcherOptions = domModule.MatcherOptions
87+
export type Match = domModule.Match
88+
export type DefaultNormalizerOptions = domModule.DefaultNormalizerOptions
89+
export type getDefaultNormalizer = domModule.getDefaultNormalizer
90+
export type getNodeText = domModule.getNodeText
91+
export type EventType = domModule.EventType
92+
export type FireFunction = domModule.FireFunction
93+
export type FireObject = domModule.FireObject
94+
export type CreateFunction = domModule.CreateFunction
95+
export type CreateObject = domModule.CreateObject
96+
export type createEvent = domModule.createEvent
97+
export type fireEvent = domModule.fireEvent
98+
export type BoundFunction<T> = domModule.BoundFunction<T>
99+
export type BoundFunctions<Q> = domModule.BoundFunctions<Q>
100+
export type Query = domModule.Query
101+
export type Queries = domModule.Queries
102+
export type getQueriesForElement = domModule.getQueriesForElement
103+
export type PrettyDOMOptions = domModule.PrettyDOMOptions
104+
export type prettyDOM = domModule.prettyDOM
105+
export type logDOM = domModule.logDOM
106+
export type prettyFormat_Colors = domModule.prettyFormat_Colors
107+
export type prettyFormat_CompareKeys = domModule.prettyFormat_CompareKeys
108+
export type prettyFormat_Options = domModule.prettyFormat_Options
109+
export type prettyFormat_OptionsReceived = domModule.prettyFormat_OptionsReceived
110+
export type prettyFormat_OldPlugin = domModule.prettyFormat_OldPlugin
111+
export type prettyFormat_NewPlugin = domModule.prettyFormat_NewPlugin
112+
export type prettyFormat_Plugin = domModule.prettyFormat_Plugin
113+
export type prettyFormat_Plugins = domModule.prettyFormat_Plugins
114+
export type prettyFormat_PrettyFormatOptions = domModule.prettyFormat_PrettyFormatOptions
115+
export type prettyFormat_Printer = domModule.prettyFormat_Printer
116+
export type prettyFormat_Refs = domModule.prettyFormat_Refs
117+
export type prettyFormat_Theme = domModule.prettyFormat_Theme
118+
export type Config = domModule.Config
119+
export type ConfigFn = domModule.ConfigFn
120+
export type configure = domModule.configure
121+
export type getConfig = domModule.getConfig
122+
export type QueryOptions = domModule.QueryOptions
123+
export type QueryArgs = domModule.QueryArgs
124+
export type Suggestion = domModule.Suggestion
125+
export type Variant = domModule.Variant
126+
export type Method = domModule.Method
127+
export type getSuggestedQuery = domModule.getSuggestedQuery
128+
129+
export type RenderResult<Q = typeofQueries, Container = Instance, BaseElement = Container> = {
130+
container: Container,
131+
baseElement: BaseElement,
132+
debug_: (
133+
baseElement: (Instance | Array<Instance>)?,
134+
maxLength: number?,
135+
options: prettyFormat_OptionsReceived?
136+
) -> (),
137+
rerender: (ui: React_ReactElement) -> (),
138+
unmount: () -> (),
139+
asFragment: () -> DocumentFragment,
140+
} & Object --[[ ROBLOX TODO: Unhandled node for type: TSMappedType ]] --[[ { [P in keyof Q]: BoundFunction<Q[P]> } ]]
141+
142+
export type RenderOptions<Q = typeofQueries, Container = Instance, BaseElement = Container> = {
143+
--[[ *
144+
* By default, React Testing Library will create a div and append that div to the document.body. Your React component will be rendered in the created div. If you provide your own HTMLElement container via this option,
145+
* it will not be appended to the document.body automatically.
146+
*
147+
* For example: If you are unit testing a `<tbody>` element, it cannot be a child of a div. In this case, you can
148+
* specify a table as the render container.
149+
*
150+
* @see https://testing-library.com/docs/react-testing-library/api/#container
151+
]]
152+
container: Container?,
153+
--[[ *
154+
* Defaults to the container if the container is specified. Otherwise `document.body` is used for the default. This is used as
155+
* the base element for the queries as well as what is printed when you use `debug()`.
156+
*
157+
* @see https://testing-library.com/docs/react-testing-library/api/#baseelement
158+
]]
159+
baseElement: BaseElement?,
160+
--[[ *
161+
* If `hydrate` is set to `true`, then it will render with `ReactDOM.hydrate`. This may be useful if you are using server-side
162+
* rendering and use ReactDOM.hydrate to mount your components.
163+
*
164+
* @see https://testing-library.com/docs/react-testing-library/api/#hydrate)
165+
]]
166+
hydrate: boolean?,
167+
--[[ *
168+
* Queries to bind. Overrides the default set from DOM Testing Library unless merged.
169+
*
170+
* @see https://testing-library.com/docs/react-testing-library/api/#queries
171+
]]
172+
queries: Q?,
173+
--[[ *
174+
* Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating
175+
* reusable custom render functions for common data providers. See setup for examples.
176+
*
177+
* @see https://testing-library.com/docs/react-testing-library/api/#wrapper
178+
]]
179+
wrapper: React_JSXElementConstructor<{ children: React_ReactElement }>?,
180+
}
181+
-- ROBLOX deviation START: can't express equivalent, we just return same type
182+
-- type Omit<T, K> = Pick<T, Exclude<any --[[ ROBLOX TODO: Unhandled node for type: TSTypeOperator ]] --[[ keyof T ]], K>>
183+
type Omit<T, K> = T
184+
-- ROBLOX deviation END
185+
186+
--[[ *
187+
* Render into a container which is appended to document.body. It should be used with cleanup.
188+
]]
189+
export type render<Q = typeofQueries, Container = Instance, BaseElement = Container> =
190+
((
191+
ui: React_ReactElement,
192+
options: RenderOptions<Q, Container, BaseElement>
193+
) -> RenderResult<Q, Container, BaseElement>)
194+
| ((ui: React_ReactElement, options: Omit<RenderOptions, "queries">?) -> RenderResult)
195+
196+
--[[*
197+
* Unmounts React trees that were mounted with render.
198+
]]
199+
export type cleanup = () -> ()
200+
201+
--[[ *
202+
* Simply calls ReactDOMTestUtils.act(cb)
203+
* If that's not available (older version of react) then it
204+
* simply calls the given callback immediately
205+
]]
206+
-- ROBLOX deviation START: dropped support for oder versions
207+
export type act = typeof(reactAct)
208+
-- ROBLOX deviation END
209+
return exports

0 commit comments

Comments
 (0)