Skip to content

Commit

Permalink
Trove test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleitnick committed Dec 10, 2024
1 parent 619cafe commit 3b9e7fa
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 197 deletions.
21 changes: 20 additions & 1 deletion ci/Test.luau
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ export type TestContext = {
Test: (self: TestContext, name: string, fn: () -> ()) -> (),
Describe: (self: TestContext, name: string, fn: () -> ()) -> (),
Expect: (self: TestContext, value: any) -> TestExpect,
BeforeEach: (self: TestContext, fn: () -> ()) -> (),
AfterEach: (self: TestContext, fn: () -> ()) -> (),
}

local TestContext = {}
Expand All @@ -230,6 +232,8 @@ function TestContext.new(root: string): TestContext
Name = root,
Items = {},
AnyFail = false,
BeforeEachFns = {},
AfterEachFns = {},
},
}, TestContext) :: any

Expand All @@ -239,6 +243,9 @@ function TestContext.new(root: string): TestContext
end

function TestContext:Test(name: string, fn: () -> ())
for _, fn in self.Current.BeforeEachFns do
fn()
end
local success, err = pcall(fn)
self.Current.Items[name] = {
Success = success,
Expand All @@ -249,6 +256,9 @@ function TestContext:Test(name: string, fn: () -> ())
self.TotalFails += 1
self.Current.AnyFail = true
end
for _, fn in self.Current.AfterEachFns do
fn()
end
end

function TestContext:Describe(name: string, fn: () -> ())
Expand All @@ -257,6 +267,8 @@ function TestContext:Describe(name: string, fn: () -> ())
Name = name,
Items = {},
AnyFail = false,
BeforeEachFns = {},
AfterEachFns = {},
}
self.Current = group
parentGroup.Items[name] = group
Expand All @@ -277,6 +289,14 @@ function TestContext:Expect(value: any): TestExpect
return setmetatable({ Value = resolvedValue, Success = success, Err = err, Flip = false }, TestExpect) :: any
end

function TestContext:BeforeEach(fn: () -> ())
table.insert(self.Current.BeforeEachFns, fn)
end

function TestContext:AfterEach(fn: () -> ())
table.insert(self.Current.AfterEachFns, fn)
end

------------------------------------------------------------------------------------------------------------

local Test = {}
Expand Down Expand Up @@ -351,7 +371,6 @@ function Test.run(ancestors: { Instance })
local outputTxt = table.concat(output, "\n")

return {
Results = results,
AllPass = allPass,
Output = outputTxt,
}
Expand Down
196 changes: 0 additions & 196 deletions modules/trove/init.spec.luau

This file was deleted.

Loading

0 comments on commit 3b9e7fa

Please sign in to comment.