Skip to content
This repository was archived by the owner on Sep 14, 2024. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6c36a86
Collapse TestPlan/TestPlanner/TestPlanBuilder/TestEnvironment
MagiMaster May 7, 2020
a61e327
Merge remote-tracking branch 'origin/master' into masterPlan
MagiMaster May 9, 2020
b7e1877
Fix test name. Now it works as expected the first time
MagiMaster May 9, 2020
ab4a9ac
Add a more explicit check of duplicate nodes
MagiMaster May 9, 2020
7084dad
Merge branch 'fixTest' into masterPlan
MagiMaster May 9, 2020
ff58302
Update tests of duplicate it blocks to match new code
MagiMaster May 9, 2020
79c68b7
Add expectation to environment
MagiMaster May 13, 2020
ed47b2c
Add luacheck globals for new test
MagiMaster May 13, 2020
04afd68
Refactor TestNode to keep a pointer back to plan tree
MagiMaster May 14, 2020
a33e158
Update comments
MagiMaster May 14, 2020
90d935a
Typo
MagiMaster May 14, 2020
5ed50de
Remove odd plan-as-parent pointer since the plan is stored explicitly
MagiMaster May 14, 2020
0a37fb8
Remove reference to TestPlanBuilder
MagiMaster May 14, 2020
e3249cb
Tests for init.spec ordering
MagiMaster May 19, 2020
062408a
Use a finalize function to be sure order is correct
MagiMaster May 19, 2020
5ae438d
Another test to make sure init.spec and afterAll work together
MagiMaster May 19, 2020
e90c1df
Remove debug print
MagiMaster May 19, 2020
4b5a677
Expand test of lifecycle hooks
MagiMaster May 19, 2020
5265c39
Expand test of lifecycle hooks
MagiMaster May 19, 2020
815f0ee
Fix #101, change beforeAll and afterAll hook implementation
MagiMaster May 19, 2020
8bf7e43
Merge remote-tracking branch 'origin/master' into lifecycle
MagiMaster May 19, 2020
b2fc3b8
Merge remote-tracking branch 'origin/master' into expandOrder
MagiMaster May 19, 2020
ae1b2a5
Merge branch 'lifecycle' into expandOrder
MagiMaster May 19, 2020
9060717
Mention change in changelog
MagiMaster May 19, 2020
5b0d20e
Add it blocks for expand test
MagiMaster May 20, 2020
7410e38
Merge remote-tracking branch 'origin/master' into expandOrder
MagiMaster May 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Remove the `step` alias for `it` since that's meant for use with `try`.
* Remove the `include` global function.
* Remove `HACK_NO_XPCALL`. With recent changes to the definition of xpcall, this is no longer necessary. Since people are still using it, it will now print out a warning asking them to delete that call instead.
* Guarantee that `init.spec.lua` will run before any `it` or `describe` blocks in the folder under it.
* Major changes to the internals of test planning.
* The major visible change is that `describe` and `it` blocks with duplicate descriptions will now not overwrite the earlier copies of those nodes.
* Duplicate `it` nodes within one `describe` will raise an error.
Expand Down
23 changes: 17 additions & 6 deletions src/TestPlan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ local function newEnvironment(currentNode, extraEnvironment)
local function addChild(phrase, callback, nodeType, nodeModifier)
local node = currentNode:addChild(phrase, nodeType, nodeModifier)
node.callback = callback
if nodeType == TestEnum.NodeType.Describe then
node:expand()
end
return node
end

Expand Down Expand Up @@ -177,10 +174,14 @@ function TestNode:getFullName()
end

--[[
Expand a node by setting its callback environment and then calling it. Any
further it and describe calls within the callback will be added to the tree.
Expand a node by setting its callback environment and then calling it. Only
expands this one node.
]]
function TestNode:expand()
if not self.callback then
return
end

local originalEnv = getfenv(self.callback)
local callbackEnv = setmetatable({}, { __index = originalEnv })
for key, value in pairs(self.environment) do
Expand Down Expand Up @@ -245,7 +246,17 @@ function TestPlan:addRoot(path, method)
end

curNode.callback = method
curNode:expand()
end

--[[
Expands all describe nodes, leaving the plan in a runnable state.
]]
function TestPlan:finalize()
self:visitAllNodes(function(node)
if node.type == TestEnum.NodeType.Describe then
node:expand()
end
end)
end

--[[
Expand Down
1 change: 1 addition & 0 deletions src/TestPlanner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function TestPlanner.createPlan(specFunctions, testNamePattern, extraEnvironment
plan:addRoot(module.path, module.method)
end

plan:finalize()
return plan
end

Expand Down
89 changes: 89 additions & 0 deletions tests/expandOrder.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
local TestEZ = require(script.Parent.Parent.TestEZ)

return {
["init.spec.lua is run before children are expanded"] = function()
local initialized = false

local plan = TestEZ.TestPlanner.createPlan({
{
method = function()
assert(initialized, "init.spec was not called before bar.spec")
end,
path = {'bar.spec', 'foo'}
},
{
method = function()
initialized = true
end,
path = {'foo'}
},
})

local results = TestEZ.TestRunner.runPlan(plan)
assert(#results.errors == 0, "init test failed: " .. tostring(results.errors[1]))
end,
["init.spec.lua afterAll can correctly undo changes"] = function()
local initialized = false

-- luacheck: globals it
local plan = TestEZ.TestPlanner.createPlan({
{
method = function()
print("Ad")
it("A", function()
print("Ai")
assert(not initialized, "initialized was true in foo/a.spec")
end)
end,
path = {'a.spec', 'foo'}
},
{
method = function()
print("Bd")
it("B", function()
print("Bi")
assert(initialized, "initialized was false in foo/bar/b.spec")
end)
end,
path = {'b.spec', 'bar', 'foo'}
},
{
method = function()
print("Init")
initialized = true

-- luacheck: globals afterAll
afterAll(function()
print("After")
initialized = false
end)
end,
path = {'bar', 'foo'}
},
{
method = function()
print("Cd")
it("C", function()
print("Ci")
assert(initialized, "initialized was false in foo/bar/c.spec")
end)
end,
path = {'c.spec', 'bar', 'foo'}
},
{
method = function()
print("Dd")
it("D", function()
print("Di")
assert(not initialized, "initialized was true in foo/d.spec")
end)
end,
path = {'d.spec', 'foo'}
},
})

local results = TestEZ.TestRunner.runPlan(plan)
assert(#results.errors == 0, "init test failed:\n" ..
table.concat(results.errors, "\n"))
end,
}
4 changes: 4 additions & 0 deletions tests/planning/init.spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- This should be added to the "planning" node of the tree instead of creating
-- a new node.
return function()
end