Skip to content

Commit c4283e2

Browse files
author
RoFlection Bot
committed
remove wrapping fn in test-helpers (#67)
1 parent 1a3976b commit c4283e2

10 files changed

+63
-64
lines changed

bin/spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local Root = game:GetService("ReplicatedStorage")
22
local Packages = Root.Packages
33

4-
local runCLI = require(Packages.Jest).runCLI
4+
local runCLI = require(Packages.Dev.Jest).runCLI
55

66
local status, result = runCLI(Root, {
77
verbose = _G.verbose == "true",

rotriever.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ LuauPolyfill = "github.com/roblox/luau-polyfill@0.3.4"
1111
LuauRegExp = "github.com/Roblox/luau-regexp@0.2.0"
1212
Chalk = "github.com/roblox/chalk-lua@0.1.3"
1313
Promise = "github.com/evaera/roblox-lua-promise@4.0.0"
14-
Jest = { git = "https://github.com/roblox/jest-roblox.git", version="3.0.0-alpha", package="Jest" }
1514
JestGetType = { git = "https://github.com/roblox/jest-roblox.git", rev="master", package="JestGetType"}
1615
PrettyFormat = { git = "https://github.com/roblox/jest-roblox.git", rev="master", package="PrettyFormat"}
1716
RobloxShared = { git = "https://github.com/roblox/jest-roblox.git", rev="master", package="RobloxShared"}
1817
JestGlobals = "github.com/roblox/jest-roblox@3.0.0-alpha"
18+
19+
[dev_dependencies]
20+
Jest = { git = "https://github.com/roblox/jest-roblox.git", version="3.0.0-alpha", package="Jest" }

src/__tests__/element-queries.spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ local configure = require(script.Parent.Parent.config).configure
1717
local getConfig = require(script.Parent.Parent.config).getConfig
1818
-- ROBLOX deviation START
1919

20-
local test_utilsModule = require(script.Parent.helpers["test-utils"])(afterEach)
20+
local test_utilsModule = require(script.Parent.helpers["test-utils"])
2121
local render = test_utilsModule.render
2222
local renderIntoDocument = test_utilsModule.renderIntoDocument
2323
test("query can return null", function()

src/__tests__/get-node-text.spec.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ local Packages = script.Parent.Parent.Parent
44
local JestGlobals = require(Packages.JestGlobals)
55
local expect = JestGlobals.expect
66
local test = JestGlobals.test
7-
local afterEach = JestGlobals.afterEach
87

98
local getNodeText = require(script.Parent.Parent["get-node-text"]).getNodeText
10-
local render = require(script.Parent.helpers["test-utils"])(afterEach).render
9+
local render = require(script.Parent.helpers["test-utils"]).render
1110

1211
--[[
1312
ROBLOX deviation START:

src/__tests__/helpers/test-utils.lua

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,59 @@
11
-- ROBLOX upstream: https://github.com/testing-library/dom-testing-library/blob/v8.14.0/src/__tests__/helpers/test-utils.js
2-
-- ROBLOX deviation: wrapping in function to pass afterEach as an argument.
3-
return function(afterEach)
4-
local Packages = script.Parent.Parent.Parent.Parent
5-
local LuauPolyfill = require(Packages.LuauPolyfill)
6-
local Object = LuauPolyfill.Object
7-
type Array<T> = LuauPolyfill.Array<T>
8-
type Object = LuauPolyfill.Object
9-
10-
local document = require(script.Parent.Parent.Parent.jsHelpers.document)
11-
12-
local exports = {}
13-
14-
local getQueriesForElement = require(script.Parent.Parent.Parent["get-queries-for-element"]).getQueriesForElement
15-
16-
local function render(html: Array<Instance>, ref_: Object?)
17-
local ref = (if ref_ == nil then {} else ref_) :: Object
18-
-- ROBLOX deviation START: use ROBLOX instances
19-
-- local container = if ref.container == nil then document:createElement("div") else ref.container
20-
local container
21-
if ref.container == nil then
22-
local div = Instance.new("Frame")
23-
container = div
24-
container.Parent = document
25-
else
26-
container = ref.container
27-
end
28-
container:ClearAllChildren()
29-
for i = 1, #html do
30-
html[i].Parent = container
31-
end
32-
-- ROBLOX deviation END
33-
local containerQueries = getQueriesForElement(container)
34-
local function rerender(newHtml: Array<Instance>)
35-
return render(newHtml, { container = container })
36-
end
37-
return Object.assign({}, { container = container, rerender = rerender }, containerQueries)
2+
local Packages = script.Parent.Parent.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+
local afterEach = require(Packages.JestGlobals).afterEach
9+
10+
local document = require(script.Parent.Parent.Parent.jsHelpers.document)
11+
12+
local exports = {}
13+
14+
local getQueriesForElement = require(script.Parent.Parent.Parent["get-queries-for-element"]).getQueriesForElement
15+
16+
local function render(html: Array<Instance>, ref_: Object?)
17+
local ref = (if ref_ == nil then {} else ref_) :: Object
18+
-- ROBLOX deviation START: use ROBLOX instances
19+
-- local container = if ref.container == nil then document:createElement("div") else ref.container
20+
local container
21+
if ref.container == nil then
22+
local div = Instance.new("Frame")
23+
container = div
24+
container.Parent = document
25+
else
26+
container = ref.container
3827
end
39-
40-
local function renderIntoDocument(html: Array<Instance>)
41-
-- ROBLOX START deviation: no document.body
42-
return render(html, { container = document })
43-
-- ROBLOX deviation END
28+
container:ClearAllChildren()
29+
for i = 1, #html do
30+
html[i].Parent = container
4431
end
45-
46-
local function cleanup()
47-
-- ROBLOX deviation START:
48-
-- document.body.innerHTML = ""
49-
document:ClearAllChildren()
50-
-- ROBLOX deviation END
32+
-- ROBLOX deviation END
33+
local containerQueries = getQueriesForElement(container)
34+
local function rerender(newHtml: Array<Instance>)
35+
return render(newHtml, { container = container })
5136
end
37+
return Object.assign({}, { container = container, rerender = rerender }, containerQueries)
38+
end
5239

53-
afterEach(cleanup)
54-
55-
exports.render = render
56-
exports.renderIntoDocument = renderIntoDocument
57-
exports.cleanup = cleanup
40+
local function renderIntoDocument(html: Array<Instance>)
41+
-- ROBLOX START deviation: no document.body
42+
return render(html, { container = document })
43+
-- ROBLOX deviation END
44+
end
5845

59-
return exports
46+
local function cleanup()
47+
-- ROBLOX deviation START:
48+
-- document.body.innerHTML = ""
49+
document:ClearAllChildren()
50+
-- ROBLOX deviation END
6051
end
52+
53+
afterEach(cleanup)
54+
55+
exports.render = render
56+
exports.renderIntoDocument = renderIntoDocument
57+
exports.cleanup = cleanup
58+
59+
return exports

src/__tests__/pretty-dom.spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ local pretty_domModule = require(script.Parent.Parent["pretty-dom"])
1818
local prettyDOM = pretty_domModule.prettyDOM
1919
local logDOM = pretty_domModule.logDOM
2020
local getUCDModule = require(script.Parent.Parent["get-user-code-frame"])
21-
local test_utilsModule = require(script.Parent.helpers["test-utils"])(afterEach)
21+
local test_utilsModule = require(script.Parent.helpers["test-utils"])
2222
local render = test_utilsModule.render
2323
local renderIntoDocument = test_utilsModule.renderIntoDocument
2424

src/__tests__/screen.spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ local RegExp = require(Packages.LuauRegExp)
1717
local getUCDModule = require(script.Parent.Parent["get-user-code-frame"])
1818

1919
local screen = require(script.Parent.Parent.screen).screen
20-
local test_utilsModule = require(script.Parent.helpers["test-utils"])(afterEach)
20+
local test_utilsModule = require(script.Parent.helpers["test-utils"])
2121
local _render = test_utilsModule.render
2222
local renderIntoDocument = test_utilsModule.renderIntoDocument
2323

src/__tests__/suggestions.spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ local CollectionService = game:GetService("CollectionService")
2525
local configure = require(script.Parent.Parent.config).configure
2626
local screen = require(script.Parent.Parent.screen).screen
2727
local getSuggestedQuery = require(script.Parent.Parent.suggestions).getSuggestedQuery
28-
local test_utilsModule = require(script.Parent.helpers["test-utils"])(afterEach)
28+
local test_utilsModule = require(script.Parent.helpers["test-utils"])
2929
local renderIntoDocument = test_utilsModule.renderIntoDocument
3030
local render = test_utilsModule.render
3131

src/__tests__/wait-for-element-to-be-removed.spec.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ local Promise = require(Packages.Promise)
1111
local JestGlobals = require(Packages.JestGlobals)
1212
local expect = JestGlobals.expect
1313
local test = JestGlobals.test
14-
local afterEach = JestGlobals.afterEach
1514

1615
local CollectionService = game:GetService("CollectionService")
1716

1817
local waitForElementToBeRemoved =
1918
require(script.Parent.Parent["wait-for-element-to-be-removed"]).waitForElementToBeRemoved
20-
local renderIntoDocument = require(script.Parent.helpers["test-utils"])(afterEach).renderIntoDocument
19+
local renderIntoDocument = require(script.Parent.helpers["test-utils"]).renderIntoDocument
2120

2221
local document = require(script.Parent.Parent.jsHelpers.document)
2322
test("resolves on mutation only when the element is removed", function()

src/__tests__/wait-for.spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ local waitFor = require(script.Parent.Parent["wait-for"]).waitFor
2323
local configModule = require(script.Parent.Parent.config)
2424
local configure = configModule.configure
2525
local getConfig = configModule.getConfig
26-
local renderIntoDocument = require(script.Parent.helpers["test-utils"])(afterEach).renderIntoDocument
26+
local renderIntoDocument = require(script.Parent.helpers["test-utils"]).renderIntoDocument
2727

2828
local function deferred()
2929
local resolve, reject

0 commit comments

Comments
 (0)