Skip to content

Commit

Permalink
Merge pull request #147 from Roblox/bbrimeyer/feature/additional-tests
Browse files Browse the repository at this point in the history
Add missing end2end test cases
  • Loading branch information
benbrimeyer committed Oct 12, 2020
2 parents 6c169cd + 64dc2fe commit 4bee8e3
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 3 deletions.
17 changes: 14 additions & 3 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,19 @@ stds.roblox = {
-- -- Extra functions
"typeof",
"tick", "warn",
}
table = {
fields = {
find = {},
create = {},
pack = {},
},
},
},
}

stds.testez = {
read_globals = {
"it", "describe", "beforeAll", "beforeEach", "afterAll", "afterEach",
"it", "describe", "beforeAll", "beforeEach", "afterAll", "afterEach", "fail", "expect"
},
}

Expand All @@ -26,4 +33,8 @@ ignore = {

files["tests/lifecycleHooks.lua"] = {
std = "+testez",
}
}

files["tests/e2e"] = {
std = "+testez"
}
20 changes: 20 additions & 0 deletions tests/e2e/expect-extend/tests/foo/foo-a.spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
return function()
describe("lower", function()
beforeAll(function()
expect.extend({
bar = function()
return {
message = "custom failure message (not)",
pass = true,
}
end
})
end)

it("SHOULD run", function()
print("foo-a")
expect(0).foo(0)
expect(0).bar(0)
end)
end)
end
13 changes: 13 additions & 0 deletions tests/e2e/expect-extend/tests/foo/init.spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
return function()
beforeAll(function()
print("init.spec")
expect.extend({
foo = function()
return {
message = "custom failure message (not)",
pass = true,
}
end
})
end)
end
36 changes: 36 additions & 0 deletions tests/e2e/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
local TestEZ = require(script.Parent.Parent.TestEZ)

local noOptReporter = {
report = function()
end,
}

return {
["run expect-extend e2e"] = function()
TestEZ.run(script:FindFirstChild("expect-extend"), function(results)
assert(#results.errors == 0,
"Expected no errors, got " .. tostring(results.errors[1]) ..
" plus " .. tostring(#results.errors - 1) .. " more.")
end)
end,

["run lifecycle e2e w/ filter for describe block"] = function()
TestEZ.TestBootstrap:run({
script:FindFirstChild("lifecycle"):FindFirstChild("testNameFilterDescribeBlock"),
},
noOptReporter,
{
testNamePattern = "super specific describe block",
})
end,

["run lifecycle e2e w/ filter for file name"] = function()
TestEZ.TestBootstrap:run({
script:FindFirstChild("lifecycle"):FindFirstChild("testNameFilterFileName"),
},
noOptReporter,
{
testNamePattern = "specificFileName",
})
end,
}
54 changes: 54 additions & 0 deletions tests/e2e/lifecycle/completeLifecycleOrderTests.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- Shared test cases asserting lifecycle hooks are firing in the correct order

return function()
describe("full example", function()
beforeAll(function(context)
context.globalState = {}

table.insert(context.globalState, "beforeAll")
expect(table.find(context.globalState, "beforeAll")).to.equal(1)
end)

beforeEach(function(context)
table.insert(context.globalState, "beforeEach")
expect(table.find(context.globalState, "beforeEach")).to.equal(2)
end)

it("it block", function(context)
table.insert(context.globalState, "test")
expect(table.find(context.globalState, "test")).to.equal(3)
end)

afterEach(function(context)
table.insert(context.globalState, "afterEach")
expect(table.find(context.globalState, "afterEach")).to.equal(4)
end)

afterAll(function(context)
table.insert(context.globalState, "afterAll")
expect(table.find(context.globalState, "afterAll")).to.equal(5)
end)
end)

describe("no it block - should not call beforeEach or afterEach", function()
beforeAll(function(context)
context.globalState = {}

table.insert(context.globalState, "beforeAll")
expect(table.find(context.globalState, "beforeAll")).to.equal(1)
end)

beforeEach(function()
fail("should not be called")
end)

afterEach(function()
fail("should not be called")
end)

afterAll(function(context)
table.insert(context.globalState, "afterAll")
expect(table.find(context.globalState, "afterAll")).to.equal(2)
end)
end)
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local completeLifecycleOrderTests = require(script:FindFirstAncestor("lifecycle").completeLifecycleOrderTests)

return function()
describe("never run", function()
it("SHOULD FAIL", function()
fail("This should have never ran. Check testNamePattern")
end)
end)

describe("super specific describe block", completeLifecycleOrderTests)
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
return function()
it("SHOULD NEVER RUN", function()
fail("This should never have run in this file. Check testNamePattern.")
end)
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
local completeLifecycleOrderTests = require(script:FindFirstAncestor("lifecycle").completeLifecycleOrderTests)

return function()
describe("file name", completeLifecycleOrderTests)
end

0 comments on commit 4bee8e3

Please sign in to comment.