|
1 | 1 | -- 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 | + |
2 | 46 | -- ROBLOX deviation START: reexport types |
3 | 47 | local typesModule = require(script.types) |
4 | 48 | export type within = typesModule.within |
@@ -111,50 +155,4 @@ export type cleanup = typesModule.cleanup |
111 | 155 | export type act = typesModule.act |
112 | 156 | -- ROBLOX deviation END |
113 | 157 |
|
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 | | - |
160 | 158 | return exports |
0 commit comments