-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Jest for running unit tests (#242)
This PR ports us over to Jest! Closes #241
- Loading branch information
Showing
24 changed files
with
636 additions
and
668 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,8 @@ | |
/*.rbxm* | ||
|
||
# Luau | ||
sourcemap.json | ||
sourcemap*.json | ||
|
||
# Selene | ||
/roblox.toml | ||
|
||
# Wally | ||
/DevPackages | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
{ | ||
"name": "flipbook", | ||
"tree": { | ||
"Packages": { | ||
"$path": "Packages" | ||
}, | ||
"Example": { | ||
"$path": "example" | ||
}, | ||
"$path": "src" | ||
"$path": "default.project.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
std = "roblox+testez" | ||
std = "roblox" | ||
|
||
[lints] | ||
global_usage = "allow" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
return function() | ||
local mapRanges = require(script.Parent.mapRanges) | ||
|
||
it("should return 1.5 if we remap 0.5 from a 0 -> 1 range to a 1 -> 2 range", function() | ||
expect(mapRanges(0.5, 0, 1, 1, 2)).to.equal(1.5) | ||
end) | ||
|
||
it("should error if max0 is the same as min0", function() | ||
expect(function() | ||
mapRanges(0.5, 1, 1, 2, 2) | ||
end).to.throw() | ||
end) | ||
end | ||
local flipbook = script:FindFirstAncestor("flipbook") | ||
|
||
local JestGlobals = require(flipbook.Packages.JestGlobals) | ||
local mapRanges = require(script.Parent.mapRanges) | ||
|
||
local expect = JestGlobals.expect | ||
local test = JestGlobals.test | ||
|
||
test("return 1.5 if we remap 0.5 from a 0 -> 1 range to a 1 -> 2 range", function() | ||
expect(mapRanges(0.5, 0, 1, 1, 2)).toBe(1.5) | ||
end) | ||
|
||
test("error if max0 is the same as min0", function() | ||
expect(function() | ||
mapRanges(0.5, 1, 1, 2, 2) | ||
end).toThrow() | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,110 @@ | ||
local flipbook = script:FindFirstAncestor("flipbook") | ||
|
||
return function() | ||
local React = require(flipbook.Packages.React) | ||
local ReactRoblox = require(flipbook.Packages.ReactRoblox) | ||
local newFolder = require(flipbook.Testing.newFolder) | ||
local useDescendants = require(script.Parent.useDescendants) | ||
|
||
local container = Instance.new("ScreenGui") | ||
local root = ReactRoblox.createRoot(container) | ||
|
||
afterEach(function() | ||
ReactRoblox.act(function() | ||
root:unmount() | ||
end) | ||
local JestGlobals = require(flipbook.Packages.JestGlobals) | ||
local React = require(flipbook.Packages.React) | ||
local ReactRoblox = require(flipbook.Packages.ReactRoblox) | ||
local newFolder = require(flipbook.Testing.newFolder) | ||
local useDescendants = require(script.Parent.useDescendants) | ||
|
||
local afterEach = JestGlobals.afterEach | ||
local expect = JestGlobals.expect | ||
local test = JestGlobals.test | ||
|
||
local container = Instance.new("ScreenGui") | ||
local root = ReactRoblox.createRoot(container) | ||
|
||
afterEach(function() | ||
ReactRoblox.act(function() | ||
root:unmount() | ||
end) | ||
|
||
it("should return an initial list of descendants that match the predicate", function() | ||
local tree = newFolder({ | ||
Match = Instance.new("Part"), | ||
Foo = Instance.new("Part"), | ||
}) | ||
|
||
local descendants | ||
local function HookTester() | ||
descendants = useDescendants(tree, function(descendant) | ||
return descendant.Name == "Match" | ||
end) | ||
|
||
return nil | ||
end | ||
|
||
ReactRoblox.act(function() | ||
root:render(React.createElement(HookTester)) | ||
end) | ||
|
||
test("return an initial list of descendants that match the predicate", function() | ||
local tree = newFolder({ | ||
Match = Instance.new("Part"), | ||
Foo = Instance.new("Part"), | ||
}) | ||
|
||
local descendants | ||
local function HookTester() | ||
descendants = useDescendants(tree, function(descendant) | ||
return descendant.Name == "Match" | ||
end) | ||
|
||
expect(descendants).to.be.ok() | ||
expect(#descendants).to.equal(1) | ||
expect(descendants[1]).to.equal(tree:FindFirstChild("Match")) | ||
end) | ||
|
||
it("should respond to changes in descendants that match the predicate", function() | ||
local tree = newFolder({ | ||
Match = Instance.new("Part"), | ||
Foo = Instance.new("Part"), | ||
}) | ||
return nil | ||
end | ||
|
||
local descendants | ||
local function HookTester() | ||
descendants = useDescendants(tree, function(descendant) | ||
return descendant.Name == "Match" | ||
end) | ||
|
||
return nil | ||
end | ||
ReactRoblox.act(function() | ||
root:render(React.createElement(HookTester)) | ||
end) | ||
|
||
ReactRoblox.act(function() | ||
root:render(React.createElement(HookTester)) | ||
expect(descendants).toBeDefined() | ||
expect(#descendants).toBe(1) | ||
expect(descendants[1]).toBe(tree:FindFirstChild("Match")) | ||
end) | ||
|
||
test("respond to changes in descendants that match the predicate", function() | ||
local tree = newFolder({ | ||
Match = Instance.new("Part"), | ||
Foo = Instance.new("Part"), | ||
}) | ||
|
||
local descendants | ||
local function HookTester() | ||
descendants = useDescendants(tree, function(descendant) | ||
return descendant.Name == "Match" | ||
end) | ||
|
||
expect(descendants).to.be.ok() | ||
expect(#descendants).to.equal(1) | ||
return nil | ||
end | ||
|
||
local folder = newFolder({ | ||
Match = Instance.new("Part"), | ||
}) | ||
ReactRoblox.act(function() | ||
root:render(React.createElement(HookTester)) | ||
end) | ||
|
||
ReactRoblox.act(function() | ||
folder.Parent = tree | ||
end) | ||
expect(descendants).toBeDefined() | ||
expect(#descendants).toBe(1) | ||
|
||
expect(#descendants).to.equal(2) | ||
end) | ||
local folder = newFolder({ | ||
Match = Instance.new("Part"), | ||
}) | ||
|
||
it("should force an update when a matching descendant's name changes", function() | ||
local descendants | ||
ReactRoblox.act(function() | ||
folder.Parent = tree | ||
end) | ||
|
||
local tree = newFolder({ | ||
Match = Instance.new("Part"), | ||
}) | ||
expect(#descendants).toBe(2) | ||
end) | ||
|
||
local function HookTester() | ||
descendants = useDescendants(tree, function(descendant) | ||
return descendant:IsA("Part") | ||
end) | ||
test("force an update when a matching descendant's name changes", function() | ||
local descendants | ||
|
||
return nil | ||
end | ||
local tree = newFolder({ | ||
Match = Instance.new("Part"), | ||
}) | ||
|
||
ReactRoblox.act(function() | ||
root:render(React.createElement(HookTester)) | ||
local function HookTester() | ||
descendants = useDescendants(tree, function(descendant) | ||
return descendant:IsA("Part") | ||
end) | ||
|
||
expect(descendants).to.be.ok() | ||
expect(#descendants).to.equal(1) | ||
return nil | ||
end | ||
|
||
local prev = descendants | ||
local match = tree:FindFirstChild("Match") | ||
ReactRoblox.act(function() | ||
root:render(React.createElement(HookTester)) | ||
end) | ||
|
||
ReactRoblox.act(function() | ||
match.Name = "Changed" | ||
end) | ||
expect(descendants).toBeDefined() | ||
expect(#descendants).toBe(1) | ||
|
||
expect(descendants).never.to.equal(prev) | ||
expect(descendants[1]).to.equal(match) | ||
local prev = descendants | ||
local match = tree:FindFirstChild("Match") | ||
|
||
ReactRoblox.act(function() | ||
match.Name = "Changed" | ||
end) | ||
end | ||
|
||
expect(descendants).never.toBe(prev) | ||
expect(descendants[1]).toBe(match) | ||
end) |
Oops, something went wrong.