Skip to content

Commit deeab86

Browse files
author
RoFlection Bot
committed
Add kcd-scripts test configurations (#38)
1 parent ef3b083 commit deeab86

File tree

11 files changed

+70
-35
lines changed

11 files changed

+70
-35
lines changed

analyze.project.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"$path": "Packages",
77
"ReactTestingLibrary": {
88
"$path": "src"
9+
},
10+
"TestsSetup": {
11+
"$path": "tests"
912
}
1013
}
1114
}

default.project.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"$path": "Packages",
77
"ReactTestingLibrary": {
88
"$path": "src"
9+
},
10+
"TestsSetup": {
11+
"$path": "tests"
912
}
1013
}
1114
}

src/__tests__/auto-cleanup.spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test("first", function()
1717
render(React.createElement("TextLabel", { Text = "hi" }))
1818
end)
1919

20-
test.only("second", function()
20+
test("second", function()
2121
expect(document).toBeEmptyDOMElement()
2222
end)
2323

src/__tests__/cleanup.spec.lua

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ test("cleanup runs effect cleanup functions", function()
6868
end)
6969

7070
describe("fake timers and missing act warnings", function()
71-
local originalConsoleError = console.error
7271
beforeEach(function()
7372
jest.resetAllMocks()
7473
-- ROBLOX deviation START: replace spyOn
@@ -80,9 +79,6 @@ describe("fake timers and missing act warnings", function()
8079
end)
8180

8281
afterEach(function()
83-
-- ROBLOX deviation START: replace spyOn
84-
console.error = originalConsoleError
85-
-- ROBLOX deviation END
8682
jest.useRealTimers()
8783
end)
8884

@@ -147,7 +143,7 @@ describe("fake timers and missing act warnings", function()
147143
return nil
148144
end
149145
render(React.createElement(Test, nil))
150-
task.wait(2)
146+
task.wait()
151147

152148
jest.runAllTimers()
153149
cleanup()

src/__tests__/new-act.spec.lua

Lines changed: 6 additions & 7 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, _consoleErrorMock
18+
local asyncAct, consoleErrorMock
1919

2020
-- ROBLOX deviation: Mock is not supported
2121
-- local _testUtils = require(script.Parent.Parent.jsHelpers["react-dom"]["test-utils"])
@@ -27,18 +27,17 @@ local asyncAct, _consoleErrorMock
2727
-- }
2828
-- end)
2929

30-
local originalConsoleError = console.error
31-
3230
beforeEach(function()
33-
console.error = jest.fn()
34-
3531
jest.resetModules()
3632
asyncAct = require(script.Parent.Parent["act-compat"]).asyncAct
33+
-- ROBLOX deviation START: replace spyOn
34+
consoleErrorMock = jest.fn()
35+
console.error = consoleErrorMock
36+
-- ROBLOX deviation END
3737
end)
3838

3939
afterEach(function()
40-
(console.error :: any):mockRestore()
41-
console.error = originalConsoleError
40+
consoleErrorMock:mockRestore()
4241
end)
4342

4443
test("async act works when it does not exist (older versions of react)", function()

src/__tests__/render.spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ local ParentModule = require(script.Parent.Parent)
1515
local render = ParentModule.render
1616
local screen = ParentModule.screen
1717

18-
test.only("renders div into document", function()
18+
test("renders div into document", function()
1919
local ref = React.createRef()
2020
local container = render(React.createElement("Frame", { ref = ref })).container
2121
-- ROBLOX deviation START: replace firstChild with Instance equivalent

src/__tests__/setup/init.lua

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/__tests__/stopwatch.spec.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ end
7373
test("unmounts a component", function()
7474
return Promise.resolve():andThen(function()
7575
-- ROBLOX deviation START: replace spyOn with jest.fn
76-
local originalConsoleError = console.error
7776
console.error = jest.fn(function() end)
7877
-- ROBLOX deviation END
7978
local ref = render(React.createElement(StopWatch, nil))
@@ -95,9 +94,6 @@ test("unmounts a component", function()
9594
0
9695
-- ROBLOX deviation END
9796
)
98-
-- ROBLOX deviation START: restore console.error
99-
console.error = originalConsoleError
100-
-- ROBLOX deviation END
10197
end)
10298
end)
10399
return {}

src/jest.config.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
local Packages = script.Parent.Parent
12
return {
23
displayName = "Jest",
3-
setupFiles = { script.Parent.__tests__.setup },
4-
testMatch = { "**/*.spec" },
4+
setupFilesAfterEnv = { Packages.TestsSetup["setup-env"] },
5+
testMatch = { "**/__tests__/**/*.spec" },
56
}

tests.project.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"$path": "Packages",
1616
"ReactTestingLibrary": {
1717
"$path": "src"
18+
},
19+
"TestsSetup": {
20+
"$path": "tests"
1821
}
1922
}
2023
}

0 commit comments

Comments
 (0)